You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to open 12bit image files with PIL/Pillow. This currently seems to be unsupported.
For a sample image, the debug mode spits out the following:
format key: ('II', 1, 1, 1, (12,), ())
Now I thought I'd cheat and just insert a key into the OPEN_key dict in TiffImagePlugin.py
(II, 1, 1, 1, (12,), ()): ("I;16", "I;16")
This now obviously messes up the image, and my tiff file ends seemingly prematurely.
Am I missing something? If it is possible to read 12bit tiffs easily, please let me know. If it is as of yet unsupported, I am happy to help, although I am afraid I will need some pointers :)
Ok. Imagemagick helpfully converted that into 1000 separate tiff files, each ~400k, 1024x304, 12bit gray with no compression. (Apparently it can convert all of them, but not one of them. Yay.)
Imagemagick is a good swiss army knife for pulling apart images to see what's going on. On the other hand, it doesn't always give you what you want. I'm currently trying to get a good 12 bit test image with known values (e.g. a ramp from 0x000 to 0x0ff, or at least known integer values for some pixels) so that I can ensure that I'm not getting bits badly twiddled. But changing the depth of an 8 bit image normalizes the values so that they go full range, and I haven't figured out how to turn that off, at least in a way that I know what the values are supposed to be.
So, current progress is that I've got I12 files unpacking to I16, but I'm stuck on the verification. Do you happen to have a way to dump one frame to raw 16bit values (with known endianess)?
This is the exact same image, saved from the camera in 12bit (actual chip bit depth), 16bit padded left and 16bit padded right. The camera offers the option of selecting "high" or "low" bits when saving at 16bit, I read this as padding left/right, but that might be wrong.
Imagemagick is reporting that the max value in the 16 bit ones is 255,255,255, which would correspond to an 8 bit image padded left. It's also reporting that it's an MSB oriented image, which is... not in agreement with the II* prefix.
Like other swiss army knives, sometimes it's not really the right tool for the job.
Ok, I managed to get imagemagick to give me two equivalent files, one was cropped from one frame of your original, one was converted to be the same data in a 16bit form, and I was able to get the images to match.
Try out cc5e8f0 on your machine and see if that does it for you. I still need test on a bigendian machine, but I should have access to one of them around here somewhere.
Activity
wiredfool commentedon Nov 19, 2013
Even if you can't pull out a single page, let me take a look at it and see what I can do.
wiredfool commentedon Nov 19, 2013
ok. downloading. wasn't expecting a cd sized image...
kadrach commentedon Nov 19, 2013
And that's a small one. Didn't want to upload the full sized ones ;)
wiredfool commentedon Nov 19, 2013
Ok. Imagemagick helpfully converted that into 1000 separate tiff files, each ~400k, 1024x304, 12bit gray with no compression. (Apparently it can convert all of them, but not one of them. Yay.)
I see the 12bit packing there.
kadrach commentedon Nov 20, 2013
I hadn't thought of using imagemagick. I have amended the original post to include both samples.
wiredfool commentedon Nov 20, 2013
Imagemagick is a good swiss army knife for pulling apart images to see what's going on. On the other hand, it doesn't always give you what you want. I'm currently trying to get a good 12 bit test image with known values (e.g. a ramp from 0x000 to 0x0ff, or at least known integer values for some pixels) so that I can ensure that I'm not getting bits badly twiddled. But changing the depth of an 8 bit image normalizes the values so that they go full range, and I haven't figured out how to turn that off, at least in a way that I know what the values are supposed to be.
So, current progress is that I've got I12 files unpacking to I16, but I'm stuck on the verification. Do you happen to have a way to dump one frame to raw 16bit values (with known endianess)?
kadrach commentedon Nov 20, 2013
This is the exact same image, saved from the camera in 12bit (actual chip bit depth), 16bit padded left and 16bit padded right. The camera offers the option of selecting "high" or "low" bits when saving at 16bit, I read this as padding left/right, but that might be wrong.
wiredfool commentedon Nov 20, 2013
I'm getting the padded left and padded right ones being exactly the same:
Imagemagick is reporting that the max value in the 16 bit ones is 255,255,255, which would correspond to an 8 bit image padded left. It's also reporting that it's an MSB oriented image, which is... not in agreement with the II* prefix.
Like other swiss army knives, sometimes it's not really the right tool for the job.
Comments
wiredfool commentedon Nov 21, 2013
Ok, I managed to get imagemagick to give me two equivalent files, one was cropped from one frame of your original, one was converted to be the same data in a 16bit form, and I was able to get the images to match.
Try out cc5e8f0 on your machine and see if that does it for you. I still need test on a bigendian machine, but I should have access to one of them around here somewhere.
kadrach commentedon Nov 21, 2013
Yes that works, thank you very much!