フィルターのクリア

Histogram based thresholding for reduction in computation

2 ビュー (過去 30 日間)
D_coder
D_coder 2018 年 9 月 4 日
コメント済み: the cyclist 2018 年 9 月 5 日
i am planning to use histcounts () function for histogram based threshold We know that histogram is a plot of pixel intensity vs frequency. My plan is to use the histcounts function to identify the pixel intensity for a particular drop in frequency for the first time in the histogram and use it as a threshold. eg: say if I execute function [N edges] = histcounts(I) on image I and I get frequency values N = 5000 2000 1000 150 20 5 3 0 1 5 3 0 0 2 and edges = 0 2.5 2.7 3.0 3.5 3.8 4.2 4.6 4.9 5.4 5.7 6.1 7.3 7.7 8.1 then how do I choose a threshold by observing the minimum frequency for the first time and selecting the corresponding edge as the threshold. (In the above case 0 is the minimum frequency. I want the pixel intensity when this zero frequency occurs for the first time)

採用された回答

the cyclist
the cyclist 2018 年 9 月 5 日
[min_N,min_idx] = min(N);
minEdge = edges(min_idx);
  4 件のコメント
Image Analyst
Image Analyst 2018 年 9 月 5 日
Derrel, be aware that your example of N happens to show that the first min is also the first global min. If that's not the case, like you have a min that comes before but is not also a global min, his and my answers will be different. Because your first min is also a global min I'm not sure which you wanted when you said you wanted "a particular drop in frequency for the first time" or "the minimum frequency for the first time". What if the first min is not a global min? What would you want in that case? In that case, the Cyclist's code and mine differ:
See the difference when the first local min is at index 9, and not at index 12, with this array:
N = [5000 2000 1000 150 20 5 3 2 1 5 3 0 0 2 0]
edges = [0 2.5 2.7 3.0 3.5 3.8 4.2 4.6 4.9 5.4 5.7 6.1 7.3 7.7 8.1]
% Find all local mins (dips) in the histogram shape:
minIndexes = imregionalmin(N)
% minIndexes is 1 at every index that is a valley/min/dip.
% Find the first min
indexOfFirstMin = find(minIndexes, 1, 'first')
% Get the bin edge there and make that the threshold.
thresholdValue = edges(indexOfFirstMin)
[min_N,min_idx] = min(N)
minEdge = edges(min_idx)
It shows a difference where my code finds the first min/dip/valley in the histogram while the Cyclists code shows the first time the overall global min occurs whether or not it's the first local min.
indexOfFirstMin =
9
thresholdValue =
4.9
min_N =
0
min_idx =
12
minEdge =
6.1
Which would you want in this case? The first local min, or the first global min?
the cyclist
the cyclist 2018 年 9 月 5 日
This is an excellent point.
Also, I'll point out that using the histogram counts to determine where your minimum lies might not be the most robust method. There is a certain amount of arbitrariness to where the bins are located. Maybe that's OK for your application, but you might want to think about that part, too.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 9 月 5 日
You can pass "N" into imregionalmin() to get local mins (dips) in the histogram. Then use find() to find the first dip, if that's what you want. Something like (untested)
% Find all local mins (dips) in the histogram shape:
minIndexes = imregionalmin(N);
% minIndexes is 1 at every index that is a valley/min/dip.
% Find the first min
indexOfFirstMin = find(minIndexes, 1, 'first');
% Get the bin edge there and make that the threshold.
thresholdValue = edges(indexOfFirstMin);

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by