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
import Image, numpy, scipy | |
def image2array(im): | |
newArr = numpy.fromstring(im.tostring(),numpy.uint8) | |
newArr = numpy.reshape(newArr,im.size) | |
return newArr | |
def array2image(a): | |
#a=a/a.max()*255.0 #optional. | |
im=Image.Image() | |
im=Image.fromarray(numpy.uint8(a)) | |
return im | |
def example(): | |
Img=Image.open('some.tiff') | |
arr=image2array(Img) | |
# | |
# some operations on array | |
# | |
Img2=array2image(arr) | |
Img2.save('some2.png') |