将一个图像复制到另一个图像的区域时索引越界

时间:2014-04-09 14:55:50

标签: matlab image-processing indexoutofboundsexception

当有人将calcification_image放入位于中心周围的contour_image区域时,有人可以帮我修复这个索引越界错误吗? 代码在matlab中

function [final_image] = addCalcificationToContour(contour_image, calcification_image)
final_image=contour_image;
calcificationI=1;
calcificationJ=1;
contour_image_size=size(contour_image)
calcification_image_size=size(calcification_image)
    for finalImageI=int32(size(contour_image,2)/2)-size(calcification_image,2)/2:int32(size(contour_image,2)/2+size(calcification_image,2)/2)-1
        calcificationI=calcificationI+1;
        calcificationJ=1;
        for finalImageJ=int32(size(contour_image,1)/2)-size(calcification_image,1)/2:int32(size(contour_image,1)/2+size(calcification_image,1)/2)-1

            final_image(finalImageI,finalImageJ)=calcification_image(calcificationI,calcificationJ);

            calcificationJ=calcificationJ+1;
        end
    end
figure;imshow(calcification_image);
end

产生的错误消息如下:

  

尝试访问calcification_image(241,1);索引超出范围   因为size(calcification_image)= [240,305,3]。

     

addCalcificationToContour出错(第12行)               final_image(finalImageI,finalImageJ)= calcification_image(calcificationI,calcificationJ);

1 个答案:

答案 0 :(得分:0)

我通过重写代码来修复错误... 不仅我没有处理RGB颜色,我还使用了反向行和列坐标...