I'm trying to use Canny edge detection algorithm in python(newbie) for daily fields of temperature data on cartesian coordinates.
For example Temperature= size(X,Y,time), 365 days of temperature data at 1-m intervals.
For this purpose, I want to use OpenCv Canny edge detection (cv2-Canny), because it is a built-in function, but a bit confused about how to apply the thresholds.
I want to detect edges, but with precise temperature gradient values.
To obtain the correct thresholds, my approach would be to calculate the temperature gradients, and get their range of probability density function (PDF) for 365-days. For example, if most of the gradients are less than 0.25 Celsius/meter, than this would be my upper threshold. Following that Canny recommended an upper:lower ratio between 2:1 and 3:1, I would set my lower gradient to ~0.08 Celsius/meter. Or the lower could also be defined using the PDF distribution.
This is the point where I am confused. Do I need to convert/scale the temperature gradients (tempgrad) into "uint8" in the range of 0-255 as:
tempgrad_final= ((tempgrad - np.nanmin(tempgrad)) * (1/(np.nanmax(tempgrad) - np.nanmin(tempgrad)) *255)).astype('uint8')
or as suggested here
and then apply the algorithm on temperature itself, as:
canny = cv2.Canny(temp, thresh_min, thresh_max, apertureSize=apertureSize, L2gradient=False)
where temp will be the temperature data, but thres_min and thres_max will be the temperature gradients scaled to 0-255?
Is this the correct approach? If not could someone please suggest how to set precise thresholds in cv2.Canny? Thanks
I tried Canny algorithm with OpenCV, but the thresholds were very confusing and results changed dramatically depending on the thresholds.