N 维小波变换

发布于 2024-11-25 13:02:47 字数 1989 浏览 3 评论 0 原文

我遇到了这个令人惊奇的回复多次应用 MATLAB 的 idwt2我自己执行了它来理解它。但是,我不知道如何使用它来处理 RGB 图像。所以,我有 3 个问题。

  1. 如何将代码应用于 RGB 图像,仅在输出中显示变换后的图像,以及沿行和列的高频和低频分量,是否可以将所有分量的融合视为单个图像?我知道我必须放置 cat 运算符,但我不明白如何去做。

  2. 其次,我也得到了一张令人惊讶的图像!我很困惑,因为我似乎无法理解其中的原因。我还附加了相同的代码以及显示如何生成此图像的语句。

    3.dwt函数签名中的术语db1意味着什么?

代码:

    load woman;             % Load image data
%startImage=imread('pic_rgb.jpg');  % IF I WANT TO WORK WITH RGB IMAGE
    nLevel = 3;             % Number of decompositions
    nColors = size(map,1);  % Number of colors in colormap
    cA = cell(1,nLevel);    % Approximation coefficients
    cH = cell(1,nLevel);    % Horizontal detail coefficients
    cV = cell(1,nLevel);    % Vertical detail coefficients
    cD = cell(1,nLevel);    % Diagonal detail coefficients
    startImage = X;
    for iLevel = 1:nLevel,
      [cA{iLevel},cH{iLevel},cV{iLevel},cD{iLevel}] = dwt2(startImage,'db1');



     startImage = cA{iLevel};
    end

    figure;colormap(map);
    imagesc(dwt2(startImage,'db1')); %THIS GIVES THE MAZED IMAGE INSTEAD OF THE TRANSFORMED IMAGE
    figure;
    tiledImage = wcodemat(cA{nLevel},nColors);
    for iLevel = nLevel:-1:1,
     tiledImage = [tiledImage                   wcodemat(cH{iLevel},nColors); ...
                    wcodemat(cV{iLevel},nColors) wcodemat(cD{iLevel},nColors)];

    end
    figure;

    imshow(tiledImage,map);

    %reconstruct
    fullRecon = cA{nLevel};
    for iLevel = nLevel:-1:1,
      fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db1');
    end
    partialRecon = cA{nLevel};
    for iLevel = nLevel:-1:1,
      partialRecon = idwt2(partialRecon,[],[],[],'db1');
    end
    figure;
    imshow([X fullRecon; partialRecon zeros(size(X))],map,...
           'InitialMagnification',50);

I came across this amazing response Applying MATLAB's idwt2 several times which I executed to understand it myself. However, I am unable to get how to use the same with work with an RGB image. So, I have 3 Questions.

  1. How would the code be applied to an RGB image with only the transformed image displayed in the output that is along with the high and low frequency components along row and column,is it possible to view the fusion of all the components as a single image? I am aware that I have to put cat operator, but I cant understand how to go about it.

  2. Secondly, I am also getting a mazed image! I am perplexed since I cannot seem to follow the reason. I have also attached the same code with the statement showing how this image has been generated.

    3.What does the term db1 in the function signature of dwt imply?

CODE:

    load woman;             % Load image data
%startImage=imread('pic_rgb.jpg');  % IF I WANT TO WORK WITH RGB IMAGE
    nLevel = 3;             % Number of decompositions
    nColors = size(map,1);  % Number of colors in colormap
    cA = cell(1,nLevel);    % Approximation coefficients
    cH = cell(1,nLevel);    % Horizontal detail coefficients
    cV = cell(1,nLevel);    % Vertical detail coefficients
    cD = cell(1,nLevel);    % Diagonal detail coefficients
    startImage = X;
    for iLevel = 1:nLevel,
      [cA{iLevel},cH{iLevel},cV{iLevel},cD{iLevel}] = dwt2(startImage,'db1');



     startImage = cA{iLevel};
    end

    figure;colormap(map);
    imagesc(dwt2(startImage,'db1')); %THIS GIVES THE MAZED IMAGE INSTEAD OF THE TRANSFORMED IMAGE
    figure;
    tiledImage = wcodemat(cA{nLevel},nColors);
    for iLevel = nLevel:-1:1,
     tiledImage = [tiledImage                   wcodemat(cH{iLevel},nColors); ...
                    wcodemat(cV{iLevel},nColors) wcodemat(cD{iLevel},nColors)];

    end
    figure;

    imshow(tiledImage,map);

    %reconstruct
    fullRecon = cA{nLevel};
    for iLevel = nLevel:-1:1,
      fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db1');
    end
    partialRecon = cA{nLevel};
    for iLevel = nLevel:-1:1,
      partialRecon = idwt2(partialRecon,[],[],[],'db1');
    end
    figure;
    imshow([X fullRecon; partialRecon zeros(size(X))],map,...
           'InitialMagnification',50);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2024-12-02 13:02:47

我对其他问题的回答中使用的示例图像是 <一个href="http://www.mathworks.com/help/techdoc/creating_plots/f2-10709.html#f2-155" rel="nofollow noreferrer">索引图像,因此有一些更改需要使该代码适用于 RGB 图像

我将首先解决您关于传递给 'db1' 参数的问题="nofollow noreferrer">DWT2。这指定用于分解的小波类型(在本例中为 Daubechies 小波) 。有关可用小波的更多信息,请参阅函数 WFILTERS< 的文档/a> 和 WAVEINFO

我将通过向您展示如何修改我的其他答案中的代码以适用于 RGB 图像来解决您的前两个问题。我将使用示例 'peppers.png' 图像。您首先需要加载图像并定义每个颜色分量具有的值的数量。由于示例图像是无符号 8 位整数类型(最常见的情况),nColors 将为 256:

X = imread('peppers.png');  %# Load sample image
nColors = 256;              %# Number of values per color component

如果您的图像是较大的无符号整数类型(例如 'uint16' >),查找颜色值数量的一般方法是使用函数 INTMAX 如下所示:

nColors = double(intmax(class(X)))+1;

对于后续代码,假定图像类型为 'uint8'

应用分解与索引图像情况没有什么不同。系数矩阵将只是 M×N×3 矩阵,而不是 M×N 矩阵:

nLevel = 3;             %# Number of decompositions
cA = cell(1,nLevel);    %# Approximation coefficient storage
cH = cell(1,nLevel);    %# Horizontal detail coefficient storage
cV = cell(1,nLevel);    %# Vertical detail coefficient storage
cD = cell(1,nLevel);    %# Diagonal detail coefficient storage
startImage = X;
for iLevel = 1:nLevel,  %# Apply nLevel decompositions
  [cA{iLevel},cH{iLevel},cV{iLevel},cD{iLevel}] = dwt2(startImage,'db1');
  startImage = cA{iLevel};
end

创建平铺图像以显示每次分解的水平、垂直和对角分量的代码将由于以下原因而改变:事实上,我们现在正在处理 3-D 矩阵,并且必须使用 CAT函数而不是串联运算符 []

tiledImage = wcodemat(cA{nLevel},nColors);
for iLevel = nLevel:-1:1
  tiledImage = cat(1,cat(2,tiledImage,...
                           wcodemat(cH{iLevel},nColors)),...
                     cat(2,wcodemat(cV{iLevel},nColors),...
                           wcodemat(cD{iLevel},nColors)));
end
figure;
imshow(uint8(tiledImage-1));  %# Convert to unsigned 8-bit integer to display

这将给出下图,显示每个分解步骤的水平(右上)、垂直(左下)和对角线(右下)分量,以及缩小图像(左上):

在此处输入图像描述

重建步骤与其他答案相同。只需要修改显示最终图像的代码:

fullRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
  fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db1');
end
partialRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
  partialRecon = idwt2(partialRecon,[],[],[],'db1');
end
figure;
tiledImage = cat(1,cat(2,X,uint8(fullRecon)),...
                   cat(2,uint8(partialRecon),zeros(size(X),'uint8')));
imshow(tiledImage,'InitialMagnification',50);

您将得到一个显示原始 RGB 图像(左上)、使用所有存储的细节系数矩阵的完全重建图像(右上)以及部分重建图像的图像。 - 不使用任何存储的细节系数矩阵重建图像(左下):

在此处输入图像描述

The sample image used in my answer to that other question was an indexed image, so there are a few changes that need to be made to get that code working for an RGB image.

I'll first address your question about the 'db1' argument passed to DWT2. This specifies the type of wavelet to use for the decomposition (in this case, a Daubechies wavelet). More information about available wavelets can be found in the documentation for the functions WFILTERS and WAVEINFO.

I'll address your first two questions by showing you how to modify the code from my other answer to work for an RGB image. I'll use the sample 'peppers.png' image. You'll first want to load your image and define the number of values each color component has. Since the sample image is an unsigned 8-bit integer type (the most common situation), nColors will be 256:

X = imread('peppers.png');  %# Load sample image
nColors = 256;              %# Number of values per color component

If your images are larger unsigned integer types (e.g. 'uint16'), a general way to find the number of color values is to use the function INTMAX like so:

nColors = double(intmax(class(X)))+1;

For the ensuing code, an image type of 'uint8' is assumed.

Applying the decompositions is no different than in the indexed image case. The coefficient matrices will simply be M-by-N-by-3 matrices instead of M-by-N matrices:

nLevel = 3;             %# Number of decompositions
cA = cell(1,nLevel);    %# Approximation coefficient storage
cH = cell(1,nLevel);    %# Horizontal detail coefficient storage
cV = cell(1,nLevel);    %# Vertical detail coefficient storage
cD = cell(1,nLevel);    %# Diagonal detail coefficient storage
startImage = X;
for iLevel = 1:nLevel,  %# Apply nLevel decompositions
  [cA{iLevel},cH{iLevel},cV{iLevel},cD{iLevel}] = dwt2(startImage,'db1');
  startImage = cA{iLevel};
end

The code to create the tiled image to show the horizontal, vertical, and diagonal components for each decomposition will change due to the fact that we are now working with 3-D matrices and must use the CAT function instead of the concatenation operator []:

tiledImage = wcodemat(cA{nLevel},nColors);
for iLevel = nLevel:-1:1
  tiledImage = cat(1,cat(2,tiledImage,...
                           wcodemat(cH{iLevel},nColors)),...
                     cat(2,wcodemat(cV{iLevel},nColors),...
                           wcodemat(cD{iLevel},nColors)));
end
figure;
imshow(uint8(tiledImage-1));  %# Convert to unsigned 8-bit integer to display

This will give the following image showing the horizontal (top right), vertical (bottom left), and diagonal (bottom right) components for each decomposition step, along with the reduced image (top left):

enter image description here

The reconstruction steps are unchanged from the other answer. Only the code for displaying the final images needs to be modified:

fullRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
  fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db1');
end
partialRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
  partialRecon = idwt2(partialRecon,[],[],[],'db1');
end
figure;
tiledImage = cat(1,cat(2,X,uint8(fullRecon)),...
                   cat(2,uint8(partialRecon),zeros(size(X),'uint8')));
imshow(tiledImage,'InitialMagnification',50);

And you will get an image showing the original RGB image (top left), the fully-reconstructed image using all of the stored detail coefficient matrices (top right), and the partially-reconstructed image using none of the stored detail coefficient matrices (bottom left):

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文