N 维小波变换
我遇到了这个令人惊奇的回复多次应用 MATLAB 的 idwt2
我自己执行了它来理解它。但是,我不知道如何使用它来处理 RGB 图像。所以,我有 3 个问题。
-
如何将代码应用于 RGB 图像,仅在输出中显示变换后的图像,以及沿行和列的高频和低频分量,是否可以将所有分量的融合视为单个图像?我知道我必须放置 cat 运算符,但我不明白如何去做。
-
其次,我也得到了一张令人惊讶的图像!我很困惑,因为我似乎无法理解其中的原因。我还附加了相同的代码以及显示如何生成此图像的语句。
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对其他问题的回答中使用的示例图像是 <一个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:如果您的图像是较大的无符号整数类型(例如
'uint16'
>),查找颜色值数量的一般方法是使用函数 INTMAX 如下所示:对于后续代码,假定图像类型为
'uint8'
。应用分解与索引图像情况没有什么不同。系数矩阵将只是 M×N×3 矩阵,而不是 M×N 矩阵:
创建平铺图像以显示每次分解的水平、垂直和对角分量的代码将由于以下原因而改变:事实上,我们现在正在处理 3-D 矩阵,并且必须使用 CAT函数而不是串联运算符
[]
:这将给出下图,显示每个分解步骤的水平(右上)、垂直(左下)和对角线(右下)分量,以及缩小图像(左上):
重建步骤与其他答案相同。只需要修改显示最终图像的代码:
您将得到一个显示原始 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: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: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:
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
[]
: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):
The reconstruction steps are unchanged from the other answer. Only the code for displaying the final images needs to be modified:
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):