1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
% haar 2d transform
% read the RGB image
% RGB = imread('102.jpg');
% imshow(RGB);
% title('This is the 102.jpg picture in RGB mode');
% % read the grayscale image
% I = rgb2gray(RGB); % convert to grayscale
% figure,imshow(I);
% title('This is the 102.jpg picture in GRAYSCALE mode');
name = 'photo_grey';
n = 256;
M = load_image(name,n);
%M = rescale(crop(M,n));
MW = M;
j = log2(n)-1;
%Select the sub-part of the image to transform.
A = MW(1:2^(j+1),1:2^(j+1));
%Compute average and differences along the vertical direction.
Average_vert = ( A(1:2:size(A,1),:) + A(2:2:size(A,1),:) )/sqrt(2);
Differences_vert = ( A(1:2:size(A,1),:) - A(2:2:size(A,1),:) )/sqrt(2);
%Concatenate them in the vertical direction to get the result.
A = cat3(1, Average_vert, Differences_vert );
% Display the result of the vertical transform.
%clf; % clear figure
imageplot(M,'Original image',1,2,1);
imageplot(A,'Vertical transform',1,2,2);
% Compute average and differences along the horizontal direction.
Average_horiz = ( A(:,1:2:size(A,1)) + A(:,2:2:size(A,1)) )/sqrt(2);
Differences_horiz = ( A(:,1:2:size(A,1)) - A(:,2:2:size(A,1)) )/sqrt(2);
% Concatenate them in the horizontal direction to get the result.
A = cat3(2, Average_horiz, Differences_horiz );
% Assign the transformed data.
MW(1:2^(j+1),1:2^(j+1)) = A;
% Display the result of the horizontal transform.
clf;
imageplot(M,'Original image',1,2,1);
subplot(1,2,2);
plot_wavelet(MW,log2(n)-1);
title('Transformed'); |
Partager