How can I rescale an histogram ?
Show older comments
Hello,
I am using a code which allows to plot an histogram of H (Hue parameter) values of each pixel from a picture. I would like to compare histograms from two different pictures. I know how to overlay them but one is smmaller than the other one so it's difficult to read the whole figure. I don't know how to normalize or rescale (I am not sure about the right word) them. I want to set the value of the higher bin to 1 for each histogram.
Please find below the code I am using :
% ** 00 ** ***Define path to folder and pick movie file***
[file,fold] = uigetfile('*.tif','Select the tif movie file');
% ** 1 ** ***Extract all tif data
info=imfinfo([fold,file]); %Yields error but give length of movie
name=file(1:length(file)-4);
s=struct;
for i=1:length(info)
im=imread([fold,file],i);
s(i).ima=im; %put images in an array structure
end
clear im
% ** 2 ** ***Pick several images and plot all points in colorspace***
list=[1];
sl=struct;
n=0;
for i=list
n=n+1;
sl(n).ima=s(i).ima;
end
for i=1:length(list)
im=sl(i).ima; %image in rgb
%Plot RGB
figure('Color',[1 1 1])
imagesc(im)
axis equal tight
set(gca,'XTick',[],'YTick',[])
title(['Frame ' num2str(list(i))],'Fontsize',16)
saveas(gcf,[fold,'Frame_' num2str(list(i),'%.3i') '.png'],'png')
%Convert RBG to HSV and keep only H
imH=rgb2hsv(im);
imH=imH(:,:,1);
%Convert RGB to XYZ
imX=rgb2xyz(im);
%Convert to xyz
x=imX(:,:,1)./(imX(:,:,1)+imX(:,:,2)+imX(:,:,3));
y=imX(:,:,2)./(imX(:,:,1)+imX(:,:,2)+imX(:,:,3));
%Reshape to vector
xx=reshape(x,[1 size(x,1)*size(x,2)]);
yy=reshape(y,[1 size(y,1)*size(y,2)]);
%Remove the background based on criterion on RBG sum
Sc=10000; %ENTER VALUE
S=im(:,:,1)+im(:,:,2)+im(:,:,3);
S(S<Sc)=0;
S=double(reshape(S,[1 size(x,1)*size(x,2)]));
H=reshape(imH,[1 size(x,1)*size(x,2)]);
xx(S==0)=[];
yy(S==0)=[];
H(S==0)=[];
figure('Color',[1 1 1],'units','normalized','outerposition',[0 0 1 1])
subplot(2,2,1)
imagesc(im)
axis equal tight
set(gca,'XTick',[],'YTick',[])
title(['Frame ' num2str(list(i))],'Fontsize',16)
subplot(2,2,[2,4])
plotChromaticity
hold all
hd=histogram2(xx,yy,300,'DisplayStyle','tile');
colormap gray
title('CIE plot','Fontsize',16)
subplot(2,2,3)
histogram(H,300)
title('Histo H layer','Fontsize',16)
saveas(gcf,[fold,'Frame_' num2str(list(i),'%.3i') '_CIE.png'],'png')
end
Accepted Answer
More Answers (0)
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!