【发布时间】:2017-12-06 19:31:19
【问题描述】:
我正在尝试编写一个实现以下目标的脚本:
- 循环遍历 dicom 图像中的每个像素。
- 如果像素值超过用户定义的阈值 (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