Compare two histograms with Correlation Coefficient

조회 수: 12 (최근 30일)
Sandra Marta
Sandra Marta 2016년 11월 16일
댓글: Sandra Marta 2016년 11월 16일
Im am trying to get a histogram of the hue of an image and then compare two different image histograms with correlation coefficient. "Corr2" is not working..
img = imread('hb1.jpeg'); hsvImage = rgb2hsv(img); hImage = hsvImage(:, :, 1); figure; subplot(2,2,1); hHist = histogram(hImage);
img = imread('hb2.jpeg'); hsvImage = rgb2hsv(img); hImage = hsvImage(:, :, 1); figure; subplot(2,2,1); hHist2 = histogram(hImage);
R=corr2(hHist, hHist2);

답변 (2개)

Steven Lord
Steven Lord 2016년 11월 16일
The corrcoef function cannot accept histogram object handles. You may have better luck using corrcoef on the vectors of bin counts from two calls to histcounts (using the same set of edges for each call) instead.
% Sample data
x1 = randn(1, 1e5);
x2 = 2*randn(1, 1e5);
% Obtain the vectors of bin counts. Use the set of edges returned from the first call
% as an input to the second call so the vector of bin counts are the same length and
% measure "apples to apples"
[n2, edges] = histcounts(x2);
n1 = histcounts(x1, edges);
% Compute the correlation coefficient between the vectors of bin counts
corrcoef(n1, n2)
You might also find this Stack Exchange discussion interesting and/or informative.

Changoleon
Changoleon 2016년 11월 16일
Why it does not work? What is the error?
How about you try this:
R=corrcoef(hHist, hHist2);
  댓글 수: 1
Sandra Marta
Sandra Marta 2016년 11월 16일
This is the error: Expected input number 1, A, to be one of these types:
logical, numeric
Instead its type was matlab.graphics.chart.primitive.Histogram.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by