plantcv
plantcv copied to clipboard
Analyze Thermal Values can not work
Describe the bug hi there, When I input a PNG type image (Gray, alpha channel=no, choose 'gray')in Analyze Thermal Values notebook, in Analysis step, the error happens:
SystemError Traceback (most recent call last)
label="default"
)filled_img = pcv.morphology.fill_segments(mask=cropped_mask, objects=edge_objects)
10
---> 11 analysis_img = pcv.analyze_thermal_values(thermal_array=thermal_data, mask=kept_mask, histplot=True)
/usr/local/lib/python3.8/site-packages/plantcv/plantcv/analyze_thermal_values.py in analyze_thermal_values(thermal_array, mask, histplot) 31 max_value = np.amax(thermal_array) 32 # Calculate histogram ---> 33 hist_thermal = [float(i[0]) for i in cv2.calcHist([np.float32(thermal_array)], [0], mask, [256], [0, max_value])] 34 bin_width = max_value / 256. 35 b = 0
SystemError: <built-in function calcHist> returned NULL without setting an error
the sample image I used is:
looking forward your reply!
Hi @Ove7comer,
The pcv.analyze_thermal_values
function expects the input image to be a 64-bit floating-point number rather than the typical 8-bit or 16-bit unsigned integer value of images. This is because the thermal data we work with are calibrated and reported as temperature values. Because your input image is a PNG file you likely have 8-bit unsigned integer values. To work around this you can run the analyze function like this:
import numpy as np
therm_hist = pcv.analyze_thermal_values(thermal_array=thermal_data.astype(np.float64), mask=kept_mask, histplot=True)
That is great, Thanks.
However, the histplot I got is a little bit weird:
Hope you can help me!
Looks like the issue is that there are fewer unique temperature values observed than there are histogram bins (I think the default is 30?). It looks like we did not add an input to control the number of bins as we have in other functions. This is something we would need to add in order to be able to generate a smoother looking histogram