[英]Not sure how the hist function in MATLAB works
I am not very sure how the hist function in MATLAB works. 我不太确定MATLAB中的hist函数如何工作。 I seem to have few problems with it.
我似乎没有什么问题。
Bascially, in the code below, i am trying to run the rotation invariant Uniform Local Binary Pattern(LBP) code. 基本上,在下面的代码中,我正在尝试运行旋转不变的统一局部二进制模式(LBP)代码。 I have no problem with the LBP code but the problem is with hist function(indicated in the code below).
LBP代码没有问题,但问题出在hist函数(在下面的代码中表示)。
The problem is that the range i should get is from 0:9 but when i apply the histogram function i get values greater than 9 such as 35, 27 and even values such as 178114.Not very sure how to correct it. 问题是我应该得到的范围是从0:9开始,但是当我应用直方图函数时,我得到的值大于9(例如35、27)甚至是值(例如178114)。不太确定如何纠正它。
I2 = imread('test.png');
RIUniformHist=[];
m=size(I2,1);
n=size(I2,2);
for i=1:10:m
for j=1:10:n
for k=i+1:i+8
for l=j+1:j+8
J0=I2(k,l);
I3(k-1,l-1)=I2(k-1,l-1)>J0;
I3(k-1,l)=I2(k-1,l)>J0;
I3(k-1,l+1)=I2(k-1,l+1)>J0;
I3(k,l+1)=I2(k,l+1)>J0;
I3(k+1,l+1)=I2(k+1,l+1)>J0;
I3(k+1,l)=I2(k+1,l)>J0;
I3(k+1,l-1)=I2(k+1,l-1)>J0;
I3(k,l-1)=I2(k,l-1)>J0;
LBP=I3(k-1,l-1)*2^7+I3(k-1,l)*2^6+I3(k-1,l+1)*2^5+I3(k,l+1)*2^4+I3(k+1,l+1)*2^3+I3(k+1,l)*2^2+I3(k+1,l-1)*2^1+I3(k,l-1)*2^0;
bits = bitand(LBP, 2.^(7:-1:0))>0;
if nnz(diff(bits([1:end, 1]))) <= 2
RIULBP(k,l)=abs(I3(k-1,l-1)-I3(k-1,l))+ abs(I3(k-1,l)-I3(k-1,l+1))+ abs(I3(k-1,l+1)-I3(k,l+1))+ abs(I3(k,l+1)-I3(k+1,l+1))+abs(I3(k+1,l+1)-I3(k+1,l))+abs(I3(k+1,l)-I3(k+1,l-1))+abs(I3(k+1,l-1)-I3(k,l-1));
else
RIULBP(k,l)=9;
end
end
end
RIULBP=uint8(RIULBP);
RIULBPv=reshape(RIULBP,1,size(RIULBP,1)*size(RIULBP,2));
RIUHist=hist(RIULBPv,0:9); % problem
RIUniformHist = [RIUniformHist RIUHist];
end
end
The vector returned by 返回的向量
RIUHist=hist(data, bins)
is the count of how many elements of data
are nearest the point identified by the bins
vector. 是距离
bins
向量所标识的点最近的data
元素数量的计数。 So if you have a value of 178114
, that juts means that there were 178114
elements of data
that were nearest to the matching index in bins
. 因此,如果您的值为
178114
,则意味着在bins
中存在最接近匹配索引的178114
个data
元素。
You can use 您可以使用
[RIUHist, binsOut] = hist(data)
to let Matlab choose the bins (I believe it uses 20 bins) or 让Matlab选择垃圾箱(我相信它使用20个垃圾箱)或
[RIUHist, binsOut] = hist(data, binCount)
To let Matlab choose the bins, but force a certain number of bins (I often use 100 or 200). 要让Matlab选择垃圾箱,但要强制使用一定数量的垃圾箱(我经常使用100或200)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.