Created
August 31, 2012 02:07
-
-
Save nobonobo/3547854 to your computer and use it in GitHub Desktop.
wxPythonでImageを2値化ストリームに変換する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import imap, islice, izip | |
def make_binstream(img): | |
def _bytestream(dt): | |
stream = izip(islice(dt,0,None,3), islice(dt,1,None,3), islice(dt,2,None,3)) | |
while 1: | |
# bits: 8コのboolアレイ | |
bits = [stream.next()==('\x00','\x00','\x00') for i in range(8)] | |
yield chr(reduce(lambda a,b: (a<<1) + b, bits)) # bitsを1バイトに変換 | |
dt = img.ConvertToMono(255,255,255).GetData() | |
return ''.join(_bytestream(dt)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment