1

I have the following code for a .tif file:

img = Image.open("randompic.tif")

image = Jpeg()
image.encodeRGB("randompic.tif")
print(np.array_equal(image.total_bit_objects, np.asarray(Image.open('randompic.tif').convert('L'))))

I try to adapt it for a .CR2 file :

img = np.fromfile('IMG_4387.CR2', "uint16")

image = Jpeg()
image.encodeRGB("IMG_4387.CR2")
print(np.array_equal(image.total_bit_objects, np.asarray(Image.open('IMG_4387.CR2').convert('L'))))

However, Image.open('IMG_4387.CR2') does not work.

Do you have any idea to fix me ?

  • There's 2 images in there. You could parse [the header](https://stackoverflow.com/questions/3696642/reading-a-cr2-raw-canon-image-header-using-python), and try to extract them, or try https://github.com/photoshell/rawkit – Doyousketch2 Jun 29 '21 at 23:40

1 Answers1

1

Why not try the following code. It uses simple PIL I tried rawpy and rawkit and they had complications with Libraw. Rawpy worked but performed a postprocessing I could not seem to understand

from PIL import Image

im = Image.open("File.CR2")
rgb_im = im.convert('RGB')
rgb_im.save('File.JPG')