沃爾什-哈達瑪變換(Walsh-Hadmard Transform,WHT),是一種典型的非正弦函數變換,采用正交直角函數作為基函數,具有與傅里葉函數類似的性質,圖像數據越是均勻分布,經過沃爾什-哈達瑪變換后的數據越是集中于矩陣的邊角上,因此沃爾什變換具有能量集中的性質,可以用于壓縮圖像信息。
Matlab中的Hadamard函數:
格式:H=hadamard( n ) ,返回一個 n * n的hadamard矩陣。







下面對lena圖像進行沃爾什-哈達瑪變換與逆變換的Matlab實現:
~~~
clc;
clear all;
im_l=imread('C:\Users\DELL\Desktop\lena.jpg');
im_l1=im2double(im_l);
im_l2=rgb2gray(im_l1);
%對圖像進行哈達瑪變換
H=hadamard(512);%產生512X512的Hadamard矩陣
haImg=H*im_l2*H;
haImg2=haImg/512;
%對圖像進行哈達瑪逆變換
hhaImg=H'*haImg2*H';
hhaImg2=hhaImg/512;
haImg1=im2uint8(haImg);
hhaImg1=im2uint8(hhaImg2);
subplot(2,2,1);
imshow(im_l);
title('原圖');
subplot(2,2,2);
imshow(im_l2);
title('灰度圖');
subplot(2,2,3);
imshow(haImg2);
title('圖像的二維離散Hadamard變換');
subplot(2,2,4);
imshow(hhaImg1);
title('圖像的二維離散Hadamard逆變換');
~~~
