错误'索引越界'用于虹膜诊断matlab

时间:2015-06-06 16:03:37

标签: matlab image-processing image-segmentation

我正在使用带有GUI的matlab进行虹膜诊断。当我开始运行我的编码时,它显示错误说"尝试访问circleiris(2);索引越界,因为numel(circleiris)= 1。"

Error in IRISDIAGNOSIS>pushbutton2_Callback (line 501)
[x,y] = circlecoords([circleiris(2),circleiris(1)],circleiris(3),size(eyeimage));

这是此错误的编码

%create accumulator for pixel location
imgsize = size(eyeimage);
l1 = zeros([imgsize(1), imgsize(2)]);  
l2 = zeros([imgsize(1), imgsize(2)]);
l3 = zeros([imgsize(1), imgsize(2)]);
l4 = zeros([imgsize(1), imgsize(2)]);

 %get pixel coords for circle around iris
[x,y]   =circlecoords([circleiris(2),circleiris(1)],circleiris(3),size(eyeimage));
ind2 = sub2ind(size(imagewithcircles),double(y),double(x));

%get pixel coords for circle around pupil
[xp, yp] =   circlecoords([circlepupil(2),circlepupil(1)],circlepupil(3),size(eyeimage));
ind1 = sub2ind(size(imagewithcircles), double(yp), double(xp));


[xc, yc] = segmentcircle([circle1(2), circle1(1)], circle1(3), size(eyeimage));
ind3 = sub2ind(size(imagewithcircles), double(yc), double(xc));


[xd, yd] = segmentcircle([circle2(2), circle2(1)], circle2(3),  size(eyeimage));
ind4 = sub2ind(size(imagewithcircles), double(yd), double(xd));

这是segmentiris的功能

 function [circleiris, circlepupil, irl, iru, icl, icu, circle1, circle2] = segmentiris(eyeimage)

 % define range of pupil & iris radii

%CASIA
lpupilradius = 28;
upupilradius = 75;
lirisradius = 80;
uirisradius = 150;



 % define scaling factor to speed up Hough transform
 scaling = 0.4;

reflecthres = 240;

 % find the iris boundary
[row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2,   0.20, 0.19, 1.00, 0.00);

circleiris = [row col r];

rowd = double(row);
cold = double(col);
rd = double(r);

irl = round(rowd-rd);
iru = round(rowd+rd);
icl = round(cold-rd);
icu = round(cold+rd);

imgsize = size(eyeimage);

if irl < 1 
irl = 1;
end


if icl < 1
icl = 1;
end


if iru > imgsize(1)
iru = imgsize(1);
end


if icu > imgsize(2)
icu = imgsize(2);
end

% to find the inner pupil, use just the region within the previously
% detected iris boundary
imagepupil = eyeimage(irl:iru,icl:icu);

%find pupil boundary
[rowp, colp, r] = findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00);

rowp = double(rowp);
colp = double(colp);
r = double(r);

row = double(irl) + rowp;
col = double(icl) + colp;

row = round(row);
col = round(col);
r1 = 1/3 *(rd - r);
r2 = 2/3 * (rd - r);
rnew1 = r1 + r;
rnew2 = r2 + r;

circlepupil = [row, col, r];
circle1 = [row, col, rnew1];
circle2 = [row, col, rnew2];

有人知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

错误表明circleiris数组没有索引2.在您发布的代码中,您正在调用circleiris(2)。您可以在此行之前插入display(circleiris);%get pixel coords for circle around iris以查看circleiris数组的外观(大小和值)。

答案 1 :(得分:0)

问题就在这里:

use strict;
use warnings;     
my $dataStore =  {
    'items1' => {
        'items2' => {
            'items3' => {
                'counts' => [
                    '534'
                ]
}}}};


my $temp_hash = $dataStore;
my $key;
my $flag=0;
while (1) {
foreach  $key ( keys %$temp_hash) {

        if (ref($temp_hash->{$key}) eq 'HASH') {
                $temp_hash=$temp_hash->{$key};
        }

        elsif (ref($temp_hash->{$key}) eq 'ARRAY') {
                my $arr = $temp_hash->{$key};
                print join (',', @$arr);
                $flag =1;

        }
}
last if $flag ==1 ;
}

我们无法访问% find the iris boundary [row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.20, 0.19, 1.00, 0.00); circleiris = [row col r]; ,但我假设它正在执行某种圆形霍夫变换。 findcircle应该是三个元素,但如果我怀疑您的circleiris函数是真的,这意味着您选择的参数会将findcirclerow呈现为为空col使得circleiris = [row col r]的长度为1.在此之后,您的脚本假定circleiris的长度为3,但是您得到一个越界错误,因为{由于circleiriscircleiris为空,{1}}的长度仅为1。我建议在row函数之后立即输入调试语句,或者执行col并查看此输出的内容。我怀疑它会是空的。

因此,您应该尝试更改此函数的参数,直到获得良好的结果。从评论中的语言来看,您可能没有编写您向我们展示的代码,因此请询问您从何处获得有关如何根据您的应用更改参数的建议。

祝你好运!