索引超出图像中的矩阵尺寸

时间:2015-08-06 04:45:11

标签: matlab image-processing matrix-indexing

 clc;
rgb = imread('apple.jpg');
rgb = imresize(rgb,[200,200]);
mlab = makecform('srgb2lab');
lab = applycform(rgb,mlab);
k=1;
 for i=1:k*3:200
     for j=1:k*3:200
       m = region(i,j,lab);
        [a,b,c] = size(m);
         m1 = region(1,1,m);
         m2 = region((a-3),1,m);
         m3 = region(1,(b-3),m);
         m4 = region((a-3),(b-3),m);
         Amean = (m1(:,:,2) + m2(:,:,2) + m3(:,:,2) + m4(:,:,2))/4;
         Bmean = (m1(:,:,3) + m2(:,:,3) + m3(:,:,3) + m4(:,:,3))/4;
         Lmean = (m1(:,:,1) + m2(:,:,1) + m3(:,:,1) + m4(:,:,1))/4;
 end;
end

在上面的代码中,我正面临索引超过矩阵值的问题,而我正在计算循环之间的Amean和Bmean值。

但是当我只计算Lmean时,那就完美了。

所以请给我解决这个问题。

region.m是

function [median,c] = region(a,b,IM)
IM = imresize(IM,[200,200]);
        c1 = imcrop(IM,[a b 3 3]);
        m1 = mean(mean(c1));
        median = m1;
        c = c1;

end

0 个答案:

没有答案