diff --git a/plantcv/plantcv/hyperspectral/read_data.py b/plantcv/plantcv/hyperspectral/read_data.py index 6995efbb2..41f533abb 100644 --- a/plantcv/plantcv/hyperspectral/read_data.py +++ b/plantcv/plantcv/hyperspectral/read_data.py @@ -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 diff --git a/tests/plantcv/hyperspectral/conftest.py b/tests/plantcv/hyperspectral/conftest.py index a2e3aba02..98ed0075e 100644 --- a/tests/plantcv/hyperspectral/conftest.py +++ b/tests/plantcv/hyperspectral/conftest.py @@ -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): diff --git a/tests/plantcv/hyperspectral/test_read_data.py b/tests/plantcv/hyperspectral/test_read_data.py index 7bc2dfbf5..fb9faa80c 100644 --- a/tests/plantcv/hyperspectral/test_read_data.py +++ b/tests/plantcv/hyperspectral/test_read_data.py @@ -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) diff --git a/tests/testdata/test-hyperspectral-uint8.hdr b/tests/testdata/test-hyperspectral-uint8.hdr new file mode 100644 index 000000000..51a567296 --- /dev/null +++ b/tests/testdata/test-hyperspectral-uint8.hdr @@ -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 +} \ No newline at end of file diff --git a/tests/testdata/test-hyperspectral-uint8.raw b/tests/testdata/test-hyperspectral-uint8.raw new file mode 100644 index 000000000..761812139 Binary files /dev/null and b/tests/testdata/test-hyperspectral-uint8.raw differ