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