PIL cannot write mode F to jpeg

前端 未结 3 406
清酒与你
清酒与你 2021-01-03 17:28

I am taking a jpg image and using numpy\'s fft2 to create/save a new image. However it throws this error

\"IOError: cannot write mode F as JPEG\" 
         


        
3条回答
  •  春和景丽
    2021-01-03 18:06

    I think it may be that your fft_p array is in float type and the image should have every pixel in the format 0-255 (which is uint8), so maybe you can try doing this before creating the image from array:

    fft_p = fft_p.astype(np.uint8)
    new_p = Image.fromarray(fft_p)
    

    But be aware that every element in the fft_p array should be in the 0-255 range, so maybe you would need to do some processing to that before to get the desired results, for example if you every element is a float between 0 and 1 you can multiply them by 255.

提交回复
热议问题