I want to read 32-bit float image files with python to do some image analysis.
I have tried
import matplotlib.pyplot as plt
im = plt.imread('path_to_file.tif')
But, this only reads the data as 8-bit integer values. Is there a way to provide imread() with the right data type?
-- Well, it formerly worked out of the box with 16-bit TIFF files, but doesn't with 32-bit floats.
I experienced a similar problem trying to read single-channel 32-bit integer images. The solution I came up with was:
from skimage import io
im = io.imread('path_to_file.tif')
If you have OpenCV installed on your computer you could also try:
import cv2
im = cv2.imread('path_to_file.tif', -1)
Hope this helps
I found a way via PIL, which is:
from matplotlib import pyplot as plt
from matplotlib import cm
from PIL import Image
from numpy import array
im = Image.open('path_to_file.tif')
ncols, nrows = im.size
ima = array(im.getdata()).reshape((nrows, ncols))
plt.imshow(ima, cmap=cm.Greys_r)
May be that helps someone.
S
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With