📄 histgram.m
字号:
%the fuction calculate the histgram of a given sample(which is a elliptic region defined by x,y,Hx and Hy)
function bin=histgram(x,y,Hx,Hy,I)
global v_count;
global matrix;
bin=zeros(1,v_count);
hx=double(Hx);
hy=double(Hy);
a=(hx.^2+hy.^2)^0.5; %a is adjust parament
pixel_distance=a;
d=0;
r=0;
count=0; %test how many pixels are included for the calculation of histgram
%I=getimage
for pixel_x=(x-hx):1:(x+hx)
for pixel_y=(y-hy):1:(y+hy)
% if(((x-pixel_x)^2/Hx+(y-pixel_y)^2/Hy)<=1)
R=double(I(pixel_y,pixel_x,1));
G=double(I(pixel_y,pixel_x,2));
B=double(I(pixel_y,pixel_x,3)) ; %get the r,g,b of the current pixel
a1=floor(R/32);
a2=floor(G/32);
a3=floor(B/32);
bin_id=matrix(a1*64+a2*8+a3+1);%all colorbin function, return the corresponding color bin for the pixel
%bin_id=colorbin(R,G,B);
pixel_distance=((double(x-pixel_x).^2)+(double(y-pixel_y).^2)).^0.5; %%%%%%%%%%%%%it has been modified here: .^ instead of ^
r=pixel_distance/a;
k=1-r^2; % k is the weight of the current pixel for its color bin--in other words, k is the data will be added to the color bin,
bin(bin_id)=bin(bin_id)+k; %bin[i] is the ith color bin,the data in all of bins together make the color histgram(a vector)
d=d+k; %d is an accumulative paramater, to adjust the vector,which you will see later how bin[] is made
%
end;
% end;
end;
f=1/d;
time=1:1:v_count;
bin(time)=f*bin(time);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -