def plotMeanError(msi, axes=None): """ create a plot for the Msi with x axes being the wavelengths and y-axes being the corresponding mean image values (e.g. reflectances, absorptions). Plots also standard deviation bands Takes image masks into account: doesn't plot a spectrum containing masked elements """ if axes is None: axes = plt.gca() # sort the wavelengths sortedIndices = sorted(range(len(msi.get_wavelengths())), key=lambda k: msi.get_wavelengths()[k]) sortedWavelenghts = msi.get_wavelengths()[sortedIndices] # copy the msi, since it will be altered (mean will be built) msi_copy = copy.deepcopy(msi) image = msi_copy.get_image() image = imgmani.collapse_image(image) std_curve = np.ma.std(image, axis=0) msimani.calculate_mean_spectrum(msi_copy) # calculate std logging.info("percentual std: " + str(std_curve / msi_copy.get_image() * 100.)) # plot as errorbar axes.errorbar(sortedWavelenghts, msi_copy.get_image()[sortedIndices], yerr=std_curve, fmt='-o')
def normalize(self, msi): # todo: guard if iqBand is outside of image dimension original_shape = msi.get_image().shape collapsed_image = collapse_image(msi.get_image()) iqDimension = collapsed_image[:, self.iqBand] normalized_image = collapsed_image / iqDimension[:, None] msi.set_image(np.reshape(normalized_image, original_shape))
def normalize(self, msi): # todo: guard if iqBand is outside of image dimension original_shape = msi.get_image().shape collapsed_image = collapse_image(msi.get_image()) iqDimension = collapsed_image[ :, self.iqBand] normalized_image = collapsed_image / iqDimension[:, None] msi.set_image(np.reshape(normalized_image, original_shape))
def plot(msi, axes=None, color=None): """ create a plot for the Msi with x axes being the wavelengths and y-axes being the corresponding image values (e.g. reflectances, absorptions) Takes image masks into account: doesn't plot a spectrum containing masked elements """ if axes is None: axes = plt.gca() sortedIndices = sorted(range(len(msi.get_wavelengths())), key=lambda k: msi.get_wavelengths()[k]) sortedWavelenghts = msi.get_wavelengths()[sortedIndices] # reshape to collapse all but last dimension (which contains reflectances) collapsedImage = imgmani.collapse_image(msi.get_image()) # todo: simply use np.ma.compress_rows # print "filtered ", filteredImage.shape i = 0 for i in range(collapsedImage.shape[0]): if (collapsedImage[i, 0] is not np.ma.masked): axes.plot(sortedWavelenghts, collapsedImage[i, :][sortedIndices], "-o", color=color)
def calculate_mean_spectrum(msi): """ reduce this image to only its mean spectrum. If the msi.get_image() is a masked array these values will be ignored when calculating the mean spectrum """ # reshape to collapse all but last dimension (which contains reflectances) collapsedImage = collapse_image(msi.get_image()) msi.set_image(np.mean(collapsedImage, axis=0)) # returns the same msi. return msi
def calculate_mean_spectrum(msi): """ reduce this image to only its mean spectrum. If the msi.get_image() is a masked array these values will be ignored when calculating the mean spectrum """ # reshape to collapse all but last dimension (which contains reflectances) collapsedImage = collapse_image(msi.get_image()) msi.set_image(np.mean(collapsedImage.astype(float), axis=0)) # returns the same msi. return msi
def normalize(self, msi, norm="l1"): original_shape = msi.get_image().shape collapsed_image = collapse_image(msi.get_image()) # temporarily save mask, since scipy normalizer removes mask is_masked_array = isinstance(msi.get_image(), np.ma.MaskedArray) if is_masked_array: mask = msi.get_image().mask normalizer = Normalizer(norm=norm) normalized_image = normalizer.transform(collapsed_image) if is_masked_array: normalized_image = np.ma.MaskedArray(normalized_image, mask=mask) msi.set_image(np.reshape(normalized_image, original_shape))
def normalize_integration_times(msi): """ divides by integration times """ if ('integration times' not in msi.get_properties()): logging.warn("warning: trying to normalize integration times for " "image without the integration time property") return msi original_shape = msi.get_image().shape collapsed_image = collapse_image(msi.get_image()) collapsed_image = collapsed_image / msi.get_properties()['integration times'] msi.set_image(collapsed_image.reshape(original_shape)) msi.add_property({'integration times': np.ones_like(msi.get_properties()['integration times'])}) return msi
def normalize_integration_times(msi): """ divides by integration times """ if ('integration times' not in msi.get_properties()): logging.warn("warning: trying to normalize integration times for " "image without the integration time property") return msi original_shape = msi.get_image().shape collapsed_image = collapse_image(msi.get_image()) collapsed_image = collapsed_image / msi.get_properties( )['integration times'] msi.set_image(collapsed_image.reshape(original_shape)) msi.add_property({ 'integration times': np.ones_like(msi.get_properties()['integration times']) }) return msi