matlab - 使用 dwt 和 dct 分解和重构图像
问题描述
我的想法是先使用分解图像dwt2
,然后应用dct2
到 coefficients_approximation,对结果应用水印,然后重新组合图像。
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, horizontal_lena,vertical_lena, diagonal_lena, 'haar');
正如您在下面看到的:在第一行中,左侧是起始图片,右侧是最终图片(更暗,细节更少)。在左侧的第二行中,我们比较dwt2
了原始图像上的 CA 和右侧重组后的 CAidct2
解决方案
问题是由将图像保存到文件并再次读取引起的。我删除了以下几行:
imwrite(uint8(approximate_lena), 'ca_lena.jpg');
和
lena_ca = double(imread('ca_lena.jpg'));
现在它可以工作了
推荐阅读
- java - Android ImageView在RelativeLayout中的Buttons下消失
- c# - 如何获得可绘制路径?
- android - 如何在kotlin中将数据从一个片段传递到另一个片段?
- angular - 使用带有 Observable 和不带表格的 Angular Material Paginator
- node.js - 关系表不存在
- arrays - 在 Julia 中将数组转换为 DataFrame 或保存为 CSV
- scala - 以下代码中的错误是什么?没有得到预期的输出
- reactjs - React JS 中的两个固定导航栏
- python - QT Designer 窗口未在 Pycharm 中打开
- javascript - 在 StorybookJS 中模拟 useState