【发布时间】:2016-09-29 16:15:39
【问题描述】:
我正在学习图像处理课程,我们需要使用 matlab。作为一项任务,我们需要创建一个计算灰度图像直方图的函数。我的代码能够处理 256 bin,但是当我尝试 128 bin 时遇到此错误:
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
我知道这是一个越界错误,但我不知道如何解决这个问题。 谢谢
【问题讨论】: