Tobias Wood [...] > These have thrown up an interesting issue - to what maximum value > should n-bit images be scaled when n is between 8 and 16? The png spec > and test images suggest it should be (2^n - 1). This means that higher > bit depths give higher precision over the same intensity range and the > same maximum value. However for my particular camera and software this > would be wrong, as the CCD has a fixed 12-bit dynamic range and the > lower png bit depths are only used to save file space. Hence at the > moment I have set my software to scale to (2^16 - 1) for 8 < n < 16, > but it follows the png spec for n < 8, so there are two contradictory > behaviours and I am unsure which is the best approach. Personally I > would prefer matplotlib to return raw integer values, not floats > scaled between 0 and 1 and then I can apply the scaling myself, but I > am aware that this is not particularly user friendly for anyone else. > imshow() seems to handle integer values fine and correctly scales for > display, provided that no alpha channel is present. In the past I worked on a similar problem, saving and loading images from a 14bit monochrome CCD camera to a PNG file. The PNG specification gives precise recommondations how to handle such a case: for saving an n-bit image which is not directly supported by the PNG specs the image needs to be scaled up to one of the supported bit depths, i.e. 1,2,4,8 or 16. The original bit depth should be stored in the sBIT chunk to recover the original data. Explicitely, a 12 bit image needs to be scaled by a factor (2^16 - 1)/(2^12-1). The approach I have chosen is: I have png_save_image(filename, img, significant_bits) that behaves as specified in the specs, i.e., 14bit images are scaled up to 16bit. For loading an image I use img, metadata = png_load_image(filename) that returns the downscaled image as an integer array and a dict containing some metadata (which includes the original bit depth). I also noticed that neither pnglib, PIL nor matlab perform this downscaling. With this approach the loaded image data is identical to the original raw image. For further processing I typically normalize the image to the range 0 to 1.0, using the bit depth information. A float array is sufficiently precise, also for 16bit images. For your enhancements to imread, introducing a new keyword 'normalized' would allow to switch between both these possibilies.As I understand I have essentially chosen the same approach like you, at least for bitdepths > 8. I didn't get the point what is different for bitdepth s<=8.
Another remark to your first posting: I didn't experience a problem with PIL to load 16bit PNG grayscale images. I also noticed you used C++ constructs in your code. I think this is not recommended. Gregor ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users