【问题标题】:How to solve Output argument (and maybe others) not assigned during call如何解决调用期间未分配的输出参数(可能还有其他参数)
【发布时间】:2017-12-06 19:31:19
【问题描述】:

我正在尝试编写一个实现以下目标的脚本:

  1. 循环遍历 dicom 图像中的每个像素。
  2. 如果像素值超过用户定义的阈值 (t1),则: 覆盖用户定义大小的过滤器内核/块。 查找块/内核中所有值的百分位数 (t2)。 求块中小于 t2 的所有像素的平均值。 将原始像素 > t1 替换为小于 t2 的像素的平均值 百分位数。

我已经尝试使用 blockproc 函数,如下所示:

function bkgdsub()
clc;

dimX = 5;        %Size of the kernel/block 
dimY = dimX;

bfmap = dicomread('IM8');
myfilter = @filter;

subimg = blockproc(bfmap, [dimX dimY], myfilter, 'PadPartialBlocks', false);
imshow(subimg)

end

function subtract = filter(block_struct)

dimX = 5;          %Set the 2D size of the kernel footprint (z, y).
dimY = dimX;
t1 = 100;   %Set threshold 1 (t1) 
t2 = 75;     %Set percentile threshold (t2)

avg = [];
singlevalue = ones([dimX dimY]);

for n = 1:dimX
    for m = 1:dimY
        if block_struct.data(n,m) >= t1;

            pc = prctile(blockstruct.data, t2)

                for i = 1:size(blockstruct.data, 1)
                    for j = 1:size(blockstruct.data, 2)
                        if blockstruct.data(i, j) < pc
                            avg = [avg blockstruct.data(i, j)];
                        end
                    end
                end

            avgMn = mean(avg(:))

            singlevalue(n,m) = avgMn
        end
    end
end
end

我遇到以下错误:

函数 BLOCKPROC 在评估用户时遇到错误 提供的函数句柄,FUN。

错误的原因是:

在调用期间未分配的输出参数“减去”(可能还有其他参数) 到“C:...\test.m>过滤器”。

blockprocFunDispatcher 中的错误(第 14 行) output_block = fun(block_struct);

blockprocInMemory 中的错误(第 81 行)[ul_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...

blockproc 中的错误(第 237 行) result_image = blockprocInMemory(source,fun,options);

bfsubtract2 中的错误(第 15 行)subimg = blockproc(bfmap, [dimX dimY], myfilter, 'PadPartialBlocks', false);

有什么想法可以解决这个问题吗?也感谢使用 blockproc 对这些错误的任何见解。

发送。

【问题讨论】:

    标签: matlab image-processing filtering


    【解决方案1】:

    所以事实证明,使用 nlfilter 更容易实现。如果以后有人需要,下面的代码块。

    function main()
    clc;            %Clear the command window
    
    dimX = 3;       %Set the 2D size of the kernel footprint (z, y).
    dimY = dimX;
    w = [dimY dimX];
    
    t1 = 100;       %Set threshold 1 (BF) 
    t2 = 75;        %Set percentile threshold 
    
    
    %kernel1=ones(5, 5)
    
    kernel = xlsread('testgrid.xlsx')   %loads in the test matrix from first sheet of excel file
    
    bfmap = dicomread('IM8');
    
    fun = @windfilt;
    
    Subtract = nlfilter(kernel, w, fun)
    
    
    
    end 
    
    function y = windfilt(A)
    
        t1 = 7;
        t2 = 75;
        avg = [];
    
        [m, n] = size(A);
    
        if A(2, 2) >= t1             %Set back to t1
            pc = prctile(A(:), t2);
    
            for i = 1:size(A, 1)
                for j = 1:size(A, 2)
                    if ((A(i, j) <= pc) & (A(i, j) ~= 0))     
                        avg = [avg A(i, j)];
                    end
                end
            end
    
            y = median(avg(:));
            clear avg
    
        else          
            y = A(2, 2);      %Set y = to the center pixel value if ~> t1
        end
    
    end
    

    【讨论】:

      【解决方案2】:

      你应该仔细阅读你的错误信息:

      在调用 filter

      期间未分配输出参数 "subtract"(可能还有其他参数)

      因此,解决方案是在某处的filter 中定义subtract

      【讨论】:

        猜你喜欢
        • 2013-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多