-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FitsImagePlugin does not support RICE_1 compression #7771
Comments
I was trying to fix the bug in the source code, and I found a new bug. My fits file is a compressed fits image (XTENSION= 'BINTABLE', TTYPE1 = 'COMPRESSED_DATA', and has keys like ZIMAGE, ZCMPTYPE, ...), but pillow seems to ignore this situation. The shape of my origin image is 4096x4096, but pillow only read the compressed image with a shape of 4096x8. |
I would describe the situation here by saying that FitsImagePlugin doesn't currently support Binary Table extensions. Pillow is reading the primary array header, seeing that there are 0 data axes, and then raises an error, because, well, we can't do much with a zero-dimensional image. When you tried to read the second header, Pillow then found How about this suggestion? What if Pillow reads your image, initially says that it is 0px wide by 0px high, and then, the user calls |
In my opinion, the compressed image and the uncompressed image are the same image. The creator of the fits file only saved the compressed image and added those essential origin image parameters to the header. Besides, I think the 0x0 image and the following compressed image are on the same level instead of the father-child relationship. I think skipping the 0-dimensional image and returning the following image would be better. If a fits format file does have two parts of images(the first part is not 0-dimensional), the Here are the solutions from other Python Libraries. Astropy will return a list with two elements and Sunpy will return a single object. |
Looking at the spec, I found
So, it seems like what I was reading in the header was not a second image, but instead an option to load the image piece by piece. In essence, you're right, there's only one image. Two questions
|
I am trying to do a machine-learning image annotation work. Most of the annotation tools do not support the "fits" format and it is very difficult to load a custom image format. I tried to use the CVAT and it loads the image with Pillow. That's the reason why I want to use Pillow to load fits format files.
The origin image is not very clear to view so I often use the histogram equalization algorithm before viewing the image. def image_histogram_equalization(image, number_bins=256):
# get image histogram
image_histogram, bins = np.histogram(image.flatten(), number_bins, density=True)
cdf = image_histogram.cumsum() # cumulative distribution function
cdf = 255 * cdf / cdf[-1] # normalize
# use linear interpolation of cdf to find new pixel values
image_equalized = np.interp(image.flatten(), bins[:-1], cdf)
return image_equalized.reshape(image.shape).astype(np.uint8) |
Your image has RICE_1 compression. I've been having trouble figuring that out, so in the meantime, I've created #7894 to add support for something other than uncompressed data at least - GZIP_1 compression. |
What did you do?
Tried using pillow for opening/handling a .fits file.
The header in my fits file has two parts and the its structure is like this:
The fits file that I use comes from satellite observation data. Here's an example fits file that comes from the same satellite with the same header structure.
I'm not sure whether this kind of header agrees the fits format standard, so I checked the fit format document. In section 3.3.1, it says
It means that the fits file I use agrees with the fits file standard.
I have just checked PR #5405 , it seems that when reading the fits file from disk, the code
break
at the firstEND
.What did you expect to happen?
Not receiving a "ValueError: No image datar" while using Image.open. Expected to load the fits image data.
What actually happened?
The Image.open code returns: ValueError: No image data
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: