不确定MATLAB中的hist函数如何工作 [英] Not sure how the hist function in MATLAB works
问题描述
我不太确定MATLAB中的hist函数如何工作.我似乎没有什么问题.
I am not very sure how the hist function in MATLAB works. I seem to have few problems with it.
基本上,在下面的代码中,我试图运行旋转不变的统一局部二进制模式(LBP)代码.我的LBP代码没有问题,但是问题是hist函数(在下面的代码中表示).
Bascially, in the code below, i am trying to run the rotation invariant Uniform Local Binary Pattern(LBP) code. I have no problem with the LBP code but the problem is with hist function(indicated in the code below).
问题是我应该得到的范围是从0:9开始,但是当我应用直方图函数时,我得到的值大于9(例如35、27)甚至是值(例如178114).
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.
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
推荐答案
RIUHist=hist(data, bins)
是data
的多少个元素最接近bins
向量所标识的点的计数.因此,如果您的值为178114
,则表明存在data
的178114
个元素,这些元素最接近bins
中的匹配索引.
is the count of how many elements of data
are nearest the point identified by the bins
vector. 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
.
您可以使用
[RIUHist, binsOut] = hist(data)
让Matlab选择垃圾箱(我相信它会使用20个垃圾箱)或
to let Matlab choose the bins (I believe it uses 20 bins) or
[RIUHist, binsOut] = hist(data, binCount)
让Matlab选择垃圾箱,但强制使用一定数量的垃圾箱(我经常使用100或200).
To let Matlab choose the bins, but force a certain number of bins (I often use 100 or 200).
这篇关于不确定MATLAB中的hist函数如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!