histogram functions in plantcv #685
Replies: 6 comments 3 replies
-
Used wavelength -> web color code function to visualize histogram for RGB image. |
Beta Was this translation helpful? Give feedback.
-
Just got the testing result for hyperspectral image. It seems that if showing all bands, we should not show the legend... It seems not necessary and not suitable that we show histograms of all bands by default. |
Beta Was this translation helpful? Give feedback.
-
A pull request will be created for functions pcv.visualize.histogram and pcv.analyze_color, where pcv.analyze_color make histograms by calling pcv.visualize.histogram.
|
Beta Was this translation helpful? Give feedback.
-
Solution present in #698 |
Beta Was this translation helpful? Give feedback.
-
There are 5 histogram related functions: For function (1) there is a little different: the input is called hist_plot_type and the default value is None, other acceptable inputs are "rgb", "lab", "hsv" and "all". The hue stats would be saved no matter what value is set for hist_plot_type. For function (4) there is also a little bit different situation. Although the variable says "histplot", what actually plotted is the average spectra of the pixels from the masked area, not a "normal" histogram. Based on the information above, there are several proposals:
|
Beta Was this translation helpful? Give feedback.
-
Updates on 03/23/2021: |
Beta Was this translation helpful? Give feedback.
-
Two types of histogram functions are used in plantcv: cv2.calcHist is used in pcv.analyze_color and np.histogram is used in pcv.visualize.histogram.
cv2.calcHist(images, channels, mask, bins, ranges): this function is capable of taking a variable "mask" and calculate histogram only on the mask area.
np.histogram(a, bins, range): this function takes an array as an input and calculate histogram. So if we want to calculate histogram only based on masked area (that's probably most the cases we use the function), we will have to apply the mask first and calculate the histogram based on the masked image. (this is the case in the function pcv.visualize.histogram.
Only when set bins to be 255 and range to be [1,256] can these two method have the same result.
hist_data = [int(i[0]) for i in cv2.calcHist([img], [0], mask, [255], [1, 256])]
hist_data, hist_bins = np.histogram(masked, 255, (1, 256))
Which means we exclude value 0 when calculating histogram.
That is because when using the histogram method in np, currently we are calculating histogram on masked image, not the masked part of the image, i.e. a lot of 0s.
Though it might be fine for most cases, but to be more general I think it makes much sense to include 0, or at least capable of including 0.
Since cv2.calcHist is capable o f calculating histogram with or without mask, I propose to use cv2.calcHist in plantcv.
Beta Was this translation helpful? Give feedback.
All reactions