Skip to content
Draft
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
5 changes: 5 additions & 0 deletions plantcv/plantcv/hyperspectral/read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ def read_data(filename, mode="ENVI"):
pseudo_rgb = _make_pseudo_rgb(spectral_array)
spectral_array.pseudo_rgb = pseudo_rgb

if spectral_array.d_type == np.uint8:
spectral_array.array_data = spectral_array.array_data.astype("float32") # required for further calculations
spectral_array.array_data = spectral_array.array_data / 255 # convert 0-255 (orig.) to 0-1 range
spectral_array.d_type = np.float32

_debug(visual=pseudo_rgb, filename=os.path.join(params.debug_outdir, str(params.device) + "_pseudo_rgb.png"))

return spectral_array
2 changes: 2 additions & 0 deletions tests/plantcv/hyperspectral/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self):
self.hsi_whiteref_file = os.path.join(self.datadir, "hsi_whiteref.pkl")
self.hsi_darkref_file = os.path.join(self.datadir, "hsi_darkref.pkl")
self.savi_file = os.path.join(self.datadir, "savi.pkl")
self.hsi_uint8 = os.path.join(self.datadir, "test-hyperpectral-uint8.raw")
self.hsi_uint8_hdr = os.path.join(self.datadir, "test-hyperpectral-uint8.hdr")

@staticmethod
def load_hsi(pkl_file):
Expand Down
5 changes: 5 additions & 0 deletions tests/plantcv/hyperspectral/test_read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ def test_read_data_parse_arcgis(hyperspectral_test_data):
"""Test for PlantCV."""
array_data = read_data(filename=hyperspectral_test_data.arcgis, mode="arcgis")
assert np.shape(array_data.array_data) == (1, 1600, 978)

def test_read_data_uint8(hyperspectral_test_data):
"""Test for PlantCV."""
array_data = read_data(filename=hyperspectral_test_data.hsi_uint8)
assert np.shape(array_data.array_data) == (1, 2, 978)
21 changes: 21 additions & 0 deletions tests/testdata/test-hyperspectral-uint8.hdr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ENVI
; this file was created using PlantCV version 3.6.dev124+gf033097d
; original file: ./RC5-9B3D54_000000_20240603_010000
interleave = bil
samples = 2
lines = 1
bands = 10
data type = 1
wavelength units = nm
wavelength = {
0.0,
475.0,
500.0,
526.0,
595.0,
630.0,
665.0,
740.0,
850.0,
940.0
}
Binary file added tests/testdata/test-hyperspectral-uint8.raw
Binary file not shown.