我正在尝试编写一个实现以下目标的脚本:
我尝试过使用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在评估用户时遇到错误 提供功能手柄,乐趣。
错误的原因是:
在通话期间未分配输出参数“减去”(可能还有其他) 到“C:... \ test.m&gt;过滤器”。
blockprocFunDispatcher出错(第14行) output_block = fun(block_struct);
blockprocInMemory中的错误(第81行)[ul_output fun_nargout] = blockprocFunDispatcher(乐趣,block_struct,...
块中的错误(第237行) result_image = blockprocInMemory(source,fun,options);
bfsubtract2(第15行)中的错误subimg = blockproc(bfmap,[dimX dimY], myfilter,'PadPartialBlocks',false);
有关如何解决这个问题的任何想法?使用blockproc对这些错误的任何了解也很受欢迎。
的Tx。
答案 0 :(得分:0)
您应该仔细阅读错误消息:
在调用过滤器
期间未分配输出参数“减去”(可能还有其他人)
因此,解决方案是在某处subtract
内定义filter
。
答案 1 :(得分:0)
因此,使用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