Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions plantcv/geospatial/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions plantcv/geospatial/read/geotif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down