简体   繁体   English

将图像分成不重叠的块并在每个块上应用 2D DWT

[英]Divide an image into non-overlapping blocks and applying the 2D DWT on each block

I am working on creating an image splicing detection software so I need to divide the image into non-overlapping blocsk and apply Discrete Meyer Wavelet Transform on each block of the image我正在创建一个图像拼接检测软件,所以我需要将图像分成不重叠的块并对图像的每个块应用离散迈耶小波变换

I have tried the blockproc function to do that but I got no result:我已经尝试了blockproc函数来做到这一点,但我没有得到任何结果:

I = imread('pears.png');

fun = @(block_struct)...
    dwt2(block_struct.data,'dmey');

C = blockproc(I,[64 64],fun);

So how can I access the [cA,cH,cV,cD ] of dwt2 using the above code?那么如何使用上述代码dwt2[cA,cH,cV,cD ]?

blockproc assumes that you are outputting an actual image. blockproc假设您正在输出实际图像。 You cannot use this for multiple outputs.您不能将其用于多个输出。 If you truly want this to work with blockproc , you will unfortunately need to call blockproc four times, with each time extracting the different set of coefficients for the directions.如果您真的希望它与blockproc ,不幸的是,您将需要调用blockproc四次,每次都为方向提取不同的系数集。 Also note that the 2D DWT only works for grayscale images, so you need to convert to grayscale before actually doing any processing.另请注意,2D DWT 仅适用于灰度图像,因此您需要在实际进行任何处理之前转换为灰度。 The pears image you've chosen is a colour / RGB image.您选择的梨图像是彩色/RGB 图像。

I'd like to reference this post on how to select the N th output given an input function: How do I get the second return value from a function without using temporary variables?我想参考这篇关于如何在给定输入函数的情况下选择第N个输出的文章: 如何在不使用临时变量的情况下从函数中获取第二个返回值? . . You will need to save this code to a file called nth_output.m , which allows you to programatically extract all output variables from a function and choose only one output.您需要将此代码保存到名为nth_output.m的文件中,该文件允许您以编程方式从函数中提取所有输出变量并仅选择一个输出。

function value = nth_output(N,fcn,varargin)
  [value{1:N}] = fcn(varargin{:});
  value = value{N};
end

Simply omitting the extra output arguments when you call the function only gives you the first output, which is what your blockproc code is doing.在调用函数时简单地省略额外的输出参数只会为您提供第一个输出,这就是您的blockproc代码所做的。 Once you do that, it's a matter of creating 4 anonymous functions to capture each output from dwt2 , and running blockproc 4 times.一旦你这样做了,就需要创建 4 个匿名函数来捕获dwt2每个输出,并运行blockproc 4 次。 Make sure you specify which output you want for each of the anonymous functions, so 1 up to 4 and you simply provide a handle to the function you want to run in addition to the input arguments that go into the function.确保为每个匿名函数指定所需的输出,例如14并且您只需提供要运行的函数的句柄以及进入函数的输入参数。

Therefore, try something like this:因此,尝试这样的事情:

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 , and cD contain the DWT coefficients you need for each set of directions. cAcHcVcD包含每组方向所需的 DWT 系数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM