コード例 #1
0
ファイル: capture.py プロジェクト: gdslab/p4m
    def save_thermal_over_rgb(self,
                              outfilename,
                              figsize=(30, 23),
                              lw_index=None,
                              hist_min_percent=0.2,
                              hist_max_percent=99.8):
        if self.__aligned_capture is None:
            raise RuntimeError(
                "call Capture.create_aligned_capture prior to saving as RGB")

        # by default we don't mask the thermal, since it's native resolution is much lower than the MS
        if lw_index is None:
            lw_index = self.lw_indices()[0]
        masked_thermal = self.__aligned_capture[:, :, lw_index]

        im_display = np.zeros((self.__aligned_capture.shape[0],
                               self.__aligned_capture.shape[1], 3),
                              dtype=np.float32)
        rgb_band_indices = [
            self.band_names_lower().index('red'),
            self.band_names_lower().index('green'),
            self.band_names_lower().index('blue')
        ]

        # for rgb true color, we usually want to use the same min and max scaling across the 3 bands to
        # maintain the "white balance" of the calibrated image
        im_min = np.percentile(
            self.__aligned_capture[:, :, rgb_band_indices].flatten(),
            hist_min_percent)  # modify these percentiles to adjust contrast
        im_max = np.percentile(
            self.__aligned_capture[:, :, rgb_band_indices].flatten(),
            hist_max_percent)  # for many images, 0.5 and 99.5 are good values
        for dst_band, src_band in enumerate(rgb_band_indices):
            im_display[:, :, dst_band] = imageutils.normalize(
                self.__aligned_capture[:, :, src_band], im_min, im_max)

        # Compute a histogram
        min_display_therm = np.percentile(masked_thermal, hist_min_percent)
        max_display_therm = np.percentile(masked_thermal, hist_max_percent)

        fig, _ = plotutils.plot_overlay_withcolorbar(
            im_display,
            masked_thermal,
            figsize=figsize,
            title='Temperature over True Color',
            vmin=min_display_therm,
            vmax=max_display_therm,
            overlay_alpha=0.25,
            overlay_colormap='jet',
            overlay_steps=16,
            display_contours=True,
            contour_steps=16,
            contour_alpha=.4,
            contour_fmt="%.0fC",
            show=False)
        fig.savefig(outfilename)
コード例 #2
0
# Compute and display a histogram
hist_min = np.min(ndvi[np.where(np.logical_and(ndvi > 0, ndvi < 1))])
hist_max = np.max(ndvi[np.where(np.logical_and(ndvi > 0, ndvi < 1))])
fig, axis = plt.subplots(1, 1, figsize=(10, 4))
axis.hist(ndvi.ravel(), bins=512, range=(hist_min, hist_max))
plt.title("NDVI Histogram")
plt.show()

min_display_ndvi = 0.5
max_display_ndvi = 0.92
masked_ndvi = np.ma.masked_where(ndvi < min_display_ndvi, ndvi)
plotutils.plot_overlay_withcolorbar(
    gamma_corr_rgb,
    masked_ndvi,
    figsize=(18, 18),
    title='NDVI filtered to only plants over RGB base layer',
    vmin=min_display_ndvi,
    vmax=max_display_ndvi)

# ## NDRE Computation
#
# In the same manner, we can compute, filter, and display another index useful for the RedEdge camera, the Normalized Difference Red Edge (NDRE) index.  We also filter out shadows and soil to ensure our display focuses only on the plant health.

# In[ ]:

# Compute Normalized Difference Red Edge Index from the NIR(3) and RedEdge(4) bands
ndre = (im_aligned[:, :, 3] - im_aligned[:, :, 4]) / (im_aligned[:, :, 3] +
                                                      im_aligned[:, :, 4])

# Mask areas with low NDRE and low NDVI