How do I show on a figure the the result of histogram intersection of two images?
5 views (last 30 days)
Show older comments
Hello,
I have selected from a video two frames and I want to use the Histogram Intersection.
When I run the code I get the values [1;256] I'm guessing that the intersection is between those to values.
I would like to know if my code is correct because I'm a bit confuse about the result.
Also I would like to know is there is a way to show the intersection of those to images in a histogram.
Please find below my code
function [output]=calculate_histIntersect(filename,threshold)
filename='C:\Users\User\Videos\videos\TestSet\01_DevilsAdvocate_01.mp4';
vObj= VideoReader(filename);
%From our video read frame 40
% convert the image to grayscale
vFrame1 = read(vObj, 40);
vFrame1grey = rgb2gray(vFrame1);
%From our video read frame 135
% convert the image to grayscale
vFrame2 = read(vObj, 135);
vFrame2grey = rgb2gray(vFrame2);
% Computing the threshold for both frames
% Define threshold value 40
%create a matrix of mrow and ncolum this is done for both brames
%create a matrix for the threshold images
threshold=40;
[mrow, ncol]=size(vFrame1grey);
[urow, vncol]=size(vFrame2grey);
ThvFrame1grey=zeros(mrow, ncol);
ThvFrame2grey=zeros(urow, vncol);
% arrange the value of the first frame according to the threshold
% If the values of the original image are bigger than threshold in the new
% image asign value 1 if not asign value0
for i=1:mrow
for j=1:ncol
if vFrame1grey(i,j)> threshold
ThvFrame1grey (i,j)=1;
else ThvFrame1grey (i,j)=0;
end
end
end
% arrange the value of the second frame according to the threshold
% If the values of the original image are bigger than threshold in the new
% image asign value 1 if not asign value0
for i=1:urow
for j=1:vncol
if vFrame2grey(i,j)> threshold
ThvFrame2grey (i,j)=1;
else ThvFrame2grey (i,j)=0;
end
end
end
% Compute the histogram for the thresholds images
hist01=imhist(ThvFrame1grey);
hist02=imhist(ThvFrame2grey);
% Create absolute value dor both histograms
hist01abs=abs(hist01);
hist02abs=abs(hist02);
% Compute histogram intersection
histIntersect= min(hist01,hist02)/min(hist01abs,hist02abs);
Intersect = find(histIntersect);
output = sort(Intersect);
figure
subplot(2,2,1),imshow(vFrame1grey)
subplot(2,2,2),imhist(vFrame1grey)
subplot(2,2,3),imshow(vFrame2grey)
subplot(2,2,4),imhist(vFrame2grey)
figure
subplot(2,2,1),imshow(ThvFrame1grey)
subplot(2,2,2),imhist(hist01)
subplot(2,2,3),imshow(ThvFrame1grey)
subplot(2,2,4),imhist(hist02)
end
6 Comments
Prajith Chilummula
on 10 Jan 2019
According to the document shared, the code seems fine. Your updated code should work.
hist01=hist01/sum(hist01);
hist02=hist02/sum(hist02);
% Compute histogram intersection
histIntersect= min(hist01,hist02);
Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!