bin2Gray.py
#!/usr/bin/python
import os
import re
import numpy
import scipy.misc
import os, array
from scipy import ndimage, misc
# aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
images = []
for root, dirnames, filenames in os.walk("."):
for filename in filenames:
if re.search("\.(vir)$", filename):
filepath = os.path.join(root, filename)
f = open(filename,'rb');
ln = os.path.getsize(filename); # length of file in bytes
width = numpy.int(numpy.ceil(numpy.sqrt(ln)));
rem = ln % width;
a = array.array("B"); # uint8 array
a.fromfile(f, ln-rem);
f.close();
g = numpy.reshape(a,(numpy.int(len(a)/width),width));
g = numpy.uint8(g);
scipy.misc.imsave(filename+".png",g); # save the image
#image = ndimage.imread(filepath, mode="L")
#image_resized = misc.imresize(image, (256, 256))
#misc.imsave(filepath, image_resized)
댓글
댓글 쓰기