0
我正在拍摄一个图像处理类,我们需要使用matlab。作为一项任务,我们需要创建一个计算灰度图像直方图的函数。我的代码是能处理256箱,但是当我尝试了128箱就遇到这样的错误:黑白图像直方图(MatLab)
Error using accumarray, First input SUBS and third input SZ must satisfy ALL(MAX(SUBS)<=SZ).
我的代码如下:
function hist = imgrayhist(imggray,n)
%read the image
i = imread(imggray);
%calculate bin threshold
threshold = 256/n;
%Calculate which bin each pixel belongs to
im_level = floor(i(:)/threshold);
%tranform the matrix to a vector
j = im_level(:);
hist = accumarray(j+1,1,[n 1]);
end
我知道这是一个出界错误,但我不知道如何解决这个问题。 谢谢
非常感谢你。这解决了我的问题 – Kai