I'm trying a simple disk filter applied to a fits file:
from skimage.morphology import disk
from skimage.filters.rank import median
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
# Open data files for image and mask
hdulist = fits.open('xbulge-w1.fits')
w1data = hdulist[0].data
hdulistmask = fits.open('xbulge-mask.fits')
maskdata = hdulistmask[0].data
mask = 1 - maskdata
w1_masked = np.ma.array(w1data, mask = mask)
selem = disk(5)
filt = median(w1_masked,
selem=disk(5),
out=None,
mask=mask)
plt.imshow(filt)
plt.show()
but this gives me a "ValueError: Images of type float must be between -1 and 1." What's going on?
This should help you solve your problem. I initially wrote this answer for this question that was about the same message error, also for a filtering operation.
In general, (and this is valid for other programming languages), an image can be typically represented in 2 ways:
[0, 255]
. In this case the values are of type uint8
- unsigned integer 8-bytes.[0, 1]
. In this case the values
are of type float.Depending on the language and library, the types and range of values allowed for the pixels' intensity can be more or less permissive.
The error here tells you that the pixels' values of your image are of type float
but that they are not in the range [-1, 1]
. If the values are in between [0, 255]
(or [-255, 255]
), you just need to divide them all by 255
. Converting the values to integers may also work.
This holds for images represented as regular arrays (or matrices, depending on the language). In your case the use of masked arrays involves masked values that are neither floats nor integers. Hence, I doubt you can use regular filtering functions if you keep on using masked arrays.
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