【发布时间】:2018-11-22 17:54:34
【问题描述】:
我在 Matlab 中为“直方图匹配”构建了一些程序。
当我尝试实现函数“conVector”时出现错误
“索引超出数组范围。”谁能帮我解决这个错误?
这是我的完整代码。谢谢!
function [newImage] = histShape (srcimg,destimg)
%find the histogram of the image
src = imgHist(srcimg);
dest = imgHist(destimg);
sna = normalizationHist(src);
dna = normalizationHist(dest);
conVector(sna,dna);
end
function [Hist] = imgHist (img)
[Rows,Cols] = size(img);
Hist = zeros(1,256);
for i=1:Rows
for j=1:Cols
Hist(img(i,j)+1)=Hist(img(i,j)+1)+1;
end
end
end
function [Ahist] = normalizationHist (hist)
[Rows,Cols] = size(hist);
Ahist = hist;
for i=2:256
Ahist(i)=Ahist(i-1)+hist(i);
end
Ahist = Ahist/(Rows*Cols);
end
function [cv] = conVector(SNA,DNA)
cv=zeros(1,257);
s = 1;
d = 1;
while s<=256
if DNA(d)<SNA(s)
d = d+1;
else
cv(s)=d;
s = s+1;
end
end
end
【问题讨论】:
-
在
conVector函数中,如果DNA(end) >= SNA(end)您将继续递增d直到它超出数组边界。
标签: matlab