python - ValueError: Images of type float must be between -1 and 1 -
i'm trying simple disk filter applied fits file:
from skimage.morphology import disk skimage.filters.rank import median import numpy np import matplotlib.pyplot plt astropy.io import fits # open data files image , 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 gives me "valueerror: images of type float must between -1 , 1." what's going on?
this should solve problem. wrote answer question same message error, filtering operation.
in general, (and valid other programming languages), image can typically represented in 2 ways:
- with intensity values in range
[0, 255]
. in case values of typeuint8
- unsigned integer 8-bytes. - with intensity values in range
[0, 1]
. in case values of type float.
depending on language , library, types , range of values allowed pixels' intensity can more or less permissive.
the error here tells pixels' values of image of type float
not in range [-1, 1]
. if values in between [0, 255]
(or [-255, 255]
), need divide them 255
. converting values integers may work.
this holds images represented regular arrays (or matrices, depending on language). in case use of masked arrays involves masked values neither floats nor integers. hence, doubt can use regular filtering functions if keep on using masked arrays.
Comments
Post a Comment