How can we plot pixel difference histogram accurately?

function PDH(img1,img2)
diffImage2 = imfilter(img2, [1, -1]);
diffImage1 = imfilter(img1, [1, -1]);
minValue1 = min(diffImage1(:));
maxValue1 = max(diffImage1(:));
minValue2 = min(diffImage2(:));
maxValue2 = max(diffImage2(:));
[counts2,edge2] = histcounts(diffImage2(:));
[counts1,edge1] = histcounts(diffImage1(:));
end
problem occures when trying plotting edge against counts cause size of edges always exceeds counts by one. However,
edges1 = linspace(minValue1, maxValue1, numel(counts1)) &
edges2 = linspace(minValue2, maxValue2, numel(counts2)) solve the problrm but the shape is not clear unless achieving decimation by certain number e.g 10.
plot(edges1, counts1, edges2, counts2); % Overlapped
plot(edges1(1:10:end), counts1(1:10:end), edges2(1:10:end), counts2(1:10:end));% looks better
Is there more accurate procedure to automatically fit the gragh with proper edges scaling.
Regards

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 3 月 8 日

0 投票

problem occures when trying plotting edge against counts cause size of edges always exceeds counts by one.
So plot(edge2(1:end-1), counts2) and the problem is solved.
Or use histc(), in which case the last bin will exist and will count only the values that exactly equal the upper bound of the edges.

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 3 月 8 日

回答済み:

2021 年 3 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by