qixinmei 发表于 2011-5-20 20:10:55

求助对索引超出矩阵的疑问-有代码

在MRI图像处理是,采用交互式方法,先从病灶区分割一矩形,再对里面的图像进行分割,问题出现在分割出矩形后,索引超出矩阵。不知如何处理,请高人解析。
clear;
close all;
clc;
%format long;
I0=imread('linsaiyun-e0.tif');
figure,imshow(I0);
I=imcrop;figure,imshow(I);
=size(I);
windowsize=3;
I_temp=I;
for i=2:m-1
    for j=2:n-1
      I_temp(i,j)=round(mean2(I(i-1:i+1,j-1:j+1)));
    end
end
I_average=I_temp;
%L=zeros(256,256);%建一个256×256的矩阵
I_p=imadd(I,1);
I_average_p=imadd(I_average,1);
=size(I_p);
hist_2d(1:p,1:q)=zeros(p,q);
for i=1:p
    for j=1:q
      hist_2d(I_p(i,j),I_average_p(i,j))=hist_2d(I_p(i,j),I_average_p(i,j))+1;
    end
end
total=p*q;
hist_2d_1=hist_2d/total;


??? Attempted to access hist_2d(102,91); index out of bounds because size(hist_2d)=.
Error in ==> ksw_2d_ga_improve at 35
      hist_2d(I_p(i,j),I_average_p(i,j))=hist_2d(I_p(i,j),I_average_p(i,j))+1;
页: [1]
查看完整版本: 求助对索引超出矩阵的疑问-有代码