调用期间未分配输出参数

时间:2015-10-06 01:10:18

标签: matlab image-processing

我正在尝试创建一个递归绘制/填充算法,该算法在具有相同值的二进制图像中填充与给定像素(使用8个邻居)相关的任何内容。我正在传递图像(img),像素坐标(x,y),要填充的值(索引),要填充的点的单元格(25,1)列表,以及数量有色点(pt)。我的代码如下所示适用于给定的连接区域,直到最深的递归返回,此时它会给出错误

Output argument "pt" (and maybe others) not assigned during call to "paintfill". 

当我说它有效时,我的意思是每个点都正确地添加到点,并且img中的像素被更新为索引。

function [ img, points, pt] = paintfill( img, x, y, index, points, pt)

sz = size(img);
if y <= sz(1) && x <= sz(2) %Valid pixel
    if img(y,x) == 255 %Unprocessed foreground pixel
        img(y,x) = index;
        points{pt,1} = [y,x];
        pt = pt+1;
        % 8 Neighbor
        [img, points, pt] = paintfill(img, x+1, y+1, index, points, pt);
        [img, points, pt] = paintfill(img, x+1, y, index, points, pt);
        [img, points, pt] = paintfill(img, x+1, y-1, index, points, pt);
        [img, points, pt] = paintfill(img, x, y+1, index, points, pt);
        [img, points, pt] = paintfill(img, x, y-1, index, points, pt);
        [img, points, pt] = paintfill(img, x-1, y+1, index, points, pt);
        [img, points, pt] = paintfill(img, x-1, y, index, points, pt);
        [img, points, pt] = paintfill(img, x-1, y-1, points, pt);
    end
end
end

我丢失的地方是pt作为输入传入,所以怎么能不分配?

0 个答案:

没有答案