Python: floating point images / matlab im2double alternative?

I am trying to convert some matlab code to python and the function im2doublegives me problems. It takes an image and returns a matrix with pixels, using double characters instead of int.

I am currently manipulating my images using PIL. It has a method convertthat can take 'F'as a parameter, but all it does is convert the integer value 255to 255.0. As far as I know, it's useless.

The problem is that I am doing image manipulations, and then I have to save them. I can normalize my values ​​so that they fall in the range 0-255, but I lose some accuracy. It is small enough that it usually does not matter, but here it does.

I tried using the "tiff" file format and it did not work. Although I can write / read, the results that I get are not correct, which I can only get at the time of converting pixels to 255, which leads to a loss of accuracy, as I said earlier. I also tried this file format 'SPIDER', which I found on Google earlier that supports PIL, although I could not open the image in the editor to check how it does it.

+3
source share
1 answer

A way to do this correctly in Python would be to use Numpy . You can read images through PIL in numpy arrays. At the moment, a wide range of Matlab matrix operations is available to you through numpy / scipy. Changing the precision of an array is just a matter of switching the data type of arrays through numpy. Recent PIL releases include a patch from Travis Oliphant so you can do this without additional hackers.

TIFF . GDAL / . , TIFF zlib.

+1

All Articles