diff --git a/plantcv/geospatial/images.py b/plantcv/geospatial/images.py index e50f0e38..58b41012 100644 --- a/plantcv/geospatial/images.py +++ b/plantcv/geospatial/images.py @@ -46,6 +46,7 @@ def __init__(self, input_array: np.ndarray, filename: str, wavelengths: list, default_wavelengths: list, crs: str, transform: affine.Affine, nodata: float): super().__init__() self.thumb = self._create_thumb() + self.nodata = 0 def __array_finalize__(self, obj): super().__array_finalize__(obj) @@ -107,6 +108,7 @@ def __init__(self, input_array: np.ndarray, filename: str, crs: str, super().__init__() self.data_array = self._gray_cutoff() self.thumb = self._create_thumb() + #self.nodata = 0 def __array_finalize__(self, obj): super().__array_finalize__(obj) @@ -127,7 +129,7 @@ def _gray_cutoff(self): img_copy = np.squeeze(self) if self.cutoff is not None : quantile = np.quantile(img_copy, self.cutoff) - img_copy[img_copy >= quantile] = np.nan + img_copy[img_copy >= quantile] = 0 return img_copy def _create_thumb(self): @@ -138,7 +140,7 @@ def _create_thumb(self): numpy.ndarray Stretched thumbnail """ - img_copy = self.data_array + img_copy = self.data_array.astype(np.float64) # Change nodata values to Nan img_copy[img_copy == self.nodata] = np.nan # Stretch values to min/max for visualization diff --git a/plantcv/geospatial/read/geotif.py b/plantcv/geospatial/read/geotif.py index 2d0b7909..eebe419c 100644 --- a/plantcv/geospatial/read/geotif.py +++ b/plantcv/geospatial/read/geotif.py @@ -66,6 +66,8 @@ def _read_geotif_and_shapefile(filename, cropto): ------- img_data : numpy.ndarray Image data array with shape ``(bands, height, width)``. + nodata_indicies : numpy.ndarray + Coordinates of missing data that has been replaced with 0s. metadata : dict Rasterio metadata dictionary including CRS, transform, and driver information. @@ -152,7 +154,16 @@ def geotif(filename, bands="R,G,B", cropto=None, cutoff=None): # Check if img is uint16 if img_data.dtype == "uint16": + img_data = np.where(img_data == metadata["nodata"], 0, img_data) img_data = ((img_data/65535.0) * 255.0).astype(np.uint8) + + # Check if img is float32 + if img_data.dtype == "float32": + # Replace nodata with 0 + img_data = np.where(img_data == metadata["nodata"], 0, img_data) + img_data = img_data ** (1 / 2.2) + img_data = (img_data * 255).astype("uint8") + if depth > 1: # Make a GEO instance before calculating a pseudo-rgb obj = GEO(input_array=img_data,