blockproc 假定您正在输出实际图像。您不能将其用于多个输出。如果您真的希望它与blockproc 一起工作,那么不幸的是,您需要调用blockproc 四次,每次都为方向提取不同的系数集。另请注意,2D DWT 仅适用于 灰度 图像,因此您需要在实际进行任何处理之前转换为灰度。您选择的梨图像是彩色/RGB 图像。
我想参考这篇文章,了解如何在给定输入函数的情况下选择Nth 输出:How do I get the second return value from a function without using temporary variables?。您需要将此代码保存到名为nth_output.m 的文件中,该文件允许您以编程方式从函数中提取所有输出变量并仅选择一个输出。
function value = nth_output(N,fcn,varargin)
[value{1:N}] = fcn(varargin{:});
value = value{N};
end
调用函数时只需省略额外的输出参数只会给您第一个输出,这就是您的blockproc 代码正在执行的操作。一旦你这样做了,就需要创建 4 个匿名函数来捕获来自 dwt2 的每个输出,并运行 blockproc 4 次。确保为每个匿名函数指定所需的输出,因此 1 到 4 并且除了输入函数的输入参数之外,您只需提供要运行的函数的句柄。
因此,请尝试以下操作:
I = rgb2gray(imread('pears.png'));
fun1 = @(block_struct) nth_output(1, @dwt2, block_struct.data,'dmey');
fun2 = @(block_struct) nth_output(2, @dwt2, block_struct.data,'dmey');
fun3 = @(block_struct) nth_output(3, @dwt2, block_struct.data,'dmey');
fun4 = @(block_struct) nth_output(4, @dwt2, block_struct.data,'dmey');
I = rgb2gray(I);
cA = blockproc(I,[64 64],fun1);
cH = blockproc(I,[64 64],fun2);
cV = blockproc(I,[64 64],fun3);
cD = blockproc(I,[64 64],fun4);
cA、cH、cV 和 cD 包含每组方向所需的 DWT 系数。