How can we plot pixel difference histogram accurately?
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 8 Mar 2021
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.
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!