Referring to the answer to this question , I tried to save my own JPG image files after some basic image processing. I applied only rotation and shift. This is my code:
import numpy as np import sys from skimage import data, io, filter, color, exposure import skimage.transform as tf from skimage.transform import rotate, setup, AffineTransform from PIL import Image mypath = PATH_TO_FILENAME readfile = FILENAME img = color.rgb2gray(io.imread(mypath + readfile)) myimg = rotate(img, angle=10, order=2) afine_tf = tf.AffineTransform(shear=0.1) editedimg = tf.warp(myimg, afine_tf)
I know that image processing was great because if I show it before saving it is just the original image with a little rotation and shift, as expected. But I am doing something wrong, keeping it. I tried without the astype(np.uint8)) part astype(np.uint8)) but got an error. Then I removed some of the code from the link mentioned above because I guessed that this was especially true for Fourier transforms, because when I included some of their code, I got an image that was gray, but with white lines in the shift direction I filed application. But now the image that is being saved is only 2 Kbytes, but only black.
And when I tried something simple:
result = Image.fromarray(editedimg) result.save(path+newfile)
then I got this error:
raise IOError("cannot write mode %s as JPEG" % im.mode) IOError: cannot write mode F as JPEG
I do not need to use PIL, if there is another way to just save my image, I am fine with that.
python numpy image-processing save image-formats
user961627 Jun 17 '14 at 2:08 a.m. 2014-06-17 14:08
source share