微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用dwt和dct分解和重组图像

如何解决使用dwt和dct分解和重组图像

我的想法是先使用dwt2分解图像,然后将dct2应用于系数_逼近,对结果应用水印,然后重新构成图像。

final_image = idwt2( idct2 ( dct2 ( dwt2 (starting_image))))

但是每当我这样做时,我都会失去很多品质,我不知道为什么。这是代码,知道吗?

clear all; clc;

%   read lena img
lena = double(imread('lena.jpg'));

%   read watermark img
%w = imread('mark.png');
load cookiebears.mat

%   compure DWT on lena and watermark
[approximate_lena,horizontal_lena,vertical_lena,diagonal_lena] = dwt2(lena,'haar');

%   i have to save the image first and then open it in order to use it in
%   dct2() omitting this step generate an error
imwrite(uint8(approximate_lena),'ca_lena.jpg');

%   read approximate_lena layer in a variable
lena_ca = double(imread('ca_lena.jpg'));

%   perform DCT on approximation level of lena picture
dct_lena = dct2(lena_ca);

%   embed the watermark into dct_lena
%   insert here function to embed the watermark
%   dct_lena = insert_watermark();

%   Now I can recompose the lena coefficients approximation 
lena_ca_recomposed = idct2(dct_lena);

%   recompose DWT
lena_recomposed = idwt2(lena_ca_recomposed,diagonal_lena,'haar');

如下所示: 在第一行中,左侧有起始图片,而在righr上有合成图片(该图片更暗,细节更少)。 在左侧的第二行中,我们对原始图像上dwt2之后的CA和右侧的idct2组成的CA进行了比较。

Image

解决方法

此问题是由于将图像保存到文件并再次读取而引起的。 我删除了以下几行:

imwrite(uint8(approximate_lena),'ca_lena.jpg');

lena_ca = double(imread('ca_lena.jpg'));

现在可以了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。