Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 2 deletions docs/read_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Reads image into numpy ndarray and splits the path and image filename (*see note

- **Parameters:**
- filename - image file to be read (possibly including a path)
- mode - return mode of image ("native," "rgb", "rgba", "csv", "envi", "arcgis", "gray", or "nd2"), defaults to "native"
- mode - return mode of image ("native," "rgb", "rgba", "csv", "envi", "arcgis", "gray", "nd2", or "thermal"), defaults to "native"

- **Context:**
- Reads in file to be processed
Expand All @@ -18,7 +18,8 @@ Reads image into numpy ndarray and splits the path and image filename (*see note
default settings (`mode="native"`). However, if the alpha channel is needed users must specify `mode="rgba"`.
- Comma separated data can be read in with `mode="csv"` so that, for example, thermal data can
be used in downstream analysis, such as [`pcv.analyze.thermal`](analyze_thermal.md).
- Nikon microscope images can be read in using `mode="nd2"`.
- Nikon microscope images can be read in using `mode="nd2"`.
- FLIR thermal images can be read in using `mode="thermal"`.
- Hyperspectral data can be read in with `mode="envi"` where the filename parameter is the raw data file. There is also support for
ArcGis style hyperspectral images (`mode="arcgis"`). These modes of
reading in data expects a `filename`.hdr file which gets used for shaping the hyperspectral datacube and labeling bands of data
Expand Down
5 changes: 4 additions & 1 deletion plantcv/plantcv/readimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd
import nd2
import flyr
from plantcv.plantcv import fatal_error
from plantcv.plantcv import params
from plantcv.plantcv.hyperspectral import read_data
Expand All @@ -16,7 +17,7 @@ def readimage(filename, mode="native"):

Inputs:
filename = name of image file
mode = mode of imread ("native", "rgb", "rgba", "gray", "csv", "envi", "arcgis", "nd2")
mode = mode of imread ("native", "rgb", "rgba", "gray", "csv", "envi", "arcgis", "nd2", "thermal")

Returns:
img = image object as numpy array
Expand All @@ -43,6 +44,8 @@ def readimage(filename, mode="native"):
return array_data
elif mode.upper() == "ND2":
img = nd2.imread(filename)
elif mode.upper() == "THERMAL":
img = flyr.unpack(filename).celsius
else:
img = cv2.imread(filename, -1)

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ dependencies = [
"statsmodels",
"altair",
"vl-convert-python",
"nd2"
"nd2",
"flyr"
]
requires-python = ">=3.8"
authors = [
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def __init__(self):
self.kmeans_classifier_gray_dir = os.path.join(self.datadir, "kmeans_classifier_gray_dir")
# nd2 file
self.nd2_img = os.path.join(self.datadir, "test_nd2_img.nd2")
# flir thermal img
self.flir_img = os.path.join(self.datadir, "FLIR_test.jpg")

@staticmethod
def load_hsi(pkl_file):
Expand Down
6 changes: 6 additions & 0 deletions tests/plantcv/test_readimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def test_readimage_nd2(test_data):
assert len(img.shape) == 3


def test_readimage_thermal(test_data):
"""Test for PlantCV."""
img, _, _ = readimage(filename=test_data.flir_img, mode="thermal")
assert len(img.shape) == 2


def test_readimage_bad_file():
"""Test for PlantCV."""
with pytest.raises(RuntimeError):
Expand Down
Binary file added tests/testdata/FLIR_test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.