# Joint Histogram 2 D

76 views (last 30 days)
Brave A on 4 Sep 2019
Commented: Brave A on 29 Oct 2019
I am doing this
Write a MATLAB function which computes the 2D joint histogram, GXY ,
of a pair of images, X and Y, of equal size. Test it on the red and green
components of the Queen Butterfly image.
Display the joint histogram, GXY , as a grey level image.
here is my attempt:
function h=histogramtest
h=zeros(size(A,1),size(A,2));
red=A(:,:,1);
green=A(:,:,2);
row=double(red(:)+1);
col=double(green(:)+1);
%h = zeros(256,256);
for i=1:256
for j=1:256
for k = 1:size(row)
% count number of occurences where i == row(k) and j == col(k)
end
% set h(i,j) = count value you get from previous loop
end
end
imshow(h)
end
it's not working at all . Thanks in advance for help in edit the code.

KSSV on 4 Sep 2019
Why you want to run a loop and count? YOu have functions to do that..read about hist.
Brave A on 4 Sep 2019
it might a mistakes.
I tried to implement what questions asked, any help?
Brave A on 4 Sep 2019
I don't want his function becaue I have colored pictured and I want to show in gray. the first part of my code is correct but the second part , is where I am struggling .

Bruno Luong on 4 Sep 2019
Edited: Bruno Luong on 4 Sep 2019
% Test data
red=A(:,:,1);
green=A(:,:,2);
% h = histcounts2(green,red,256); % compute
% or plot
histogram2(green(:),red(:),256);

Show 1 older comment
Brave A on 4 Sep 2019
you can say I need to implement the function instead of using functions does that for me :)
Bruno Luong on 4 Sep 2019
Yeah because the loops obviously are wrong. It come down to understand what is an histogram. If it's homework, then I can't help you more.
Brave A on 29 Oct 2019

Bruno Luong on 4 Sep 2019
Edited: Bruno Luong on 4 Sep 2019
% Test data