如何解决输出参数(或其它)调用

问题描述:

我想编写一个脚本,实现了如下期间未分配:如何解决输出参数(或其它)调用

  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>过滤器”。 (block_struct);

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

错误blockprocInMemory(线81)[ul_output fun_nargout] = blockprocFunDispatcher(乐趣,block_struct,...

错误blockproc(线237) result_image = blockprocInMemory(源,好玩的,选项);

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

对我怎么能解决这个任何想法任何有识之士INT o使用blockproc这些错误也是值得赞赏的。

Tx。

您应仔细阅读您的错误信息:

输出参数“减”(或其它)通话过程中没有分配给过滤

所以,解决的办法是在filter的某个地方定义subtract

因此,这变得更容易与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