Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab Code Interpretation

Subject: Matlab Code Interpretation

From: Twilighter

Date: 11 Dec, 2010 02:26:04

Message: 1 of 5

Hi

I'm a beginner in matlab & image processing filed. i'm concerned about image watermarking using DWT.
some time i find piece of codes uploaded on websites, regarding this subject, but my problem is that most of these coded are not well commented and the author is anonymous ... i can't understand interpret the algorithm, or why he looped here, or added those numbers or reshaped the matrix .... and all my work is dependent on writing matlab codes, i dunno how can i understand a written code without knowing its real algorithm or its based equations, for an experienced eye it could be easy but for me it's such a rocket science ...

I'm Realizing that my question could be not related to the Matlab forum but i need the help of the expert in here. and your experience

this is a piece of code i dont understand its algorithm

% Read the watermark
w=imread('watermark.jpg');
figure
imshow(w)
title('The original watermark');

% Watermark scrambling
Ln=10;
w=Arnold(w,Ln); % this calls a custom function called arnold to do image scrambling
figure
imshow(w)
title('Watermark scrambling');

% Bit graph decomposition
wb=Bitdecom(w); % i dont understand this part and (it's a custom function i will write it below)

% Recombination (what that part does?)
wb1=[wb(:,:,1) wb(:,:,2) wb(:,:,3) wb(:,:,4)];
wb2=[wb(:,:,5) wb(:,:,6) wb(:,:,7) wb(:,:,8)];
wb3=[wb1;wb2];

% Binary data stream into
wbs=reshape(wb3,1,64*64*8); % why he did that ?

-----------------------

function a=Bitdecom(o) (what does this function do & why ?)
L=size(o);
for i=1:L(1)
    for j=1:L(2)
        n=o(i,j);
        for k=1:8
            a(i,j,k)=mod(n,2);
            n=(n-mod(n,2))/2;
        end
    end
end


this is a part of a code ... i hope i have made my point clear thanx ... and looking for your help thanx

Subject: Matlab Code Interpretation

From: mrt

Date: 13 Dec, 2010 12:50:21

Message: 2 of 5

>>
> I'm Realizing that my question could be not related to the Matlab forum but i need the help of the expert in here. and your experience
>
> this is a piece of code i dont understand its algorithm
>
> % Read the watermark
> w=imread('watermark.jpg');
> figure
> imshow(w)
> title('The original watermark');
>
> % Watermark scrambling
> Ln=10;
> w=Arnold(w,Ln); % this calls a custom function called arnold to do image scrambling
> figure
> imshow(w)
> title('Watermark scrambling');
>
> % Bit graph decomposition
> wb=Bitdecom(w); % i dont understand this part and (it's a custom function i will write it below)
>
> % Recombination (what that part does?)
> wb1=[wb(:,:,1) wb(:,:,2) wb(:,:,3) wb(:,:,4)];
> wb2=[wb(:,:,5) wb(:,:,6) wb(:,:,7) wb(:,:,8)];
> wb3=[wb1;wb2];
>
> % Binary data stream into
> wbs=reshape(wb3,1,64*64*8); % why he did that ?
>
> -----------------------
>
> function a=Bitdecom(o) (what does this function do & why ?)
> L=size(o);
> for i=1:L(1)
> for j=1:L(2)
> n=o(i,j);
> for k=1:8
> a(i,j,k)=mod(n,2);
> n=(n-mod(n,2))/2;
> end
> end
> end
>
>
> this is a part of a code ... i hope i have made my point clear thanx ... and looking for your help thanx
wb=Bitdecom(w); is to open compressed bits for watermarking(w)
function is similar function a=Bitdecom(o)
wbs=reshape(wb3,1,64*64*8); DWT is divided into four parts an then again .
so each block is 8x8 blok then 8x8 block .one little block 8*8 two litte block 2*8*8 thats why 64*64 an then one big block 64*64*8

Subject: Matlab Code Interpretation

From: Twilighter

Date: 13 Dec, 2010 13:37:05

Message: 3 of 5


> wb=Bitdecom(w); is to open compressed bits for watermarking(w)
> function is similar function a=Bitdecom(o)
> wbs=reshape(wb3,1,64*64*8); DWT is divided into four parts an then again .
> so each block is 8x8 blok then 8x8 block .one little block 8*8 two litte block 2*8*8 thats why 64*64 an then one big block 64*64*8


First, thank you for your Reply
Second, i didnt understand your explanation ...
open compressed bits? i'm not quite sure i get this ...
also i couldn't understand your sentence here "o each block is 8x8 blok then 8x8 block .one little block 8*8 two litte block 2*8*8 thats why 64*64 an then one big block 64*64*8 "
can you provide me with more detailed answer

thanx for your time

Subject: Matlab Code Interpretation

From: mrt

Date: 13 Dec, 2010 15:35:29

Message: 4 of 5

hi.
do you understand WB1 and WB2 of your code ?
do you want to read this article?

look at the picture please .divided into four parts an then divided again
these blocks are 8x8 blocks.
http://en.wikipedia.org/wiki/Wavelet_compression#Wavelet_compression



> > % Recombination (what that part does?)
> > wb1=[wb(:,:,1) wb(:,:,2) wb(:,:,3) wb(:,:,4)];
> > wb2=[wb(:,:,5) wb(:,:,6) wb(:,:,7) wb(:,:,8)];
> > wb3=[wb1;wb2];
> >
> > % Binary data stream into
> > wbs=reshape(wb3,1,64*64*8); % why he did that ?
> >
> > -----------------------
> >
> > function a=Bitdecom(o) (what does this function do & why ?)
> > L=size(o);
> > for i=1:L(1)
> > for j=1:L(2)
> > n=o(i,j);
> > for k=1:8
> > a(i,j,k)=mod(n,2);
> > n=(n-mod(n,2))/2;
> > end
> > end
> > end
> >
> >
> > this is a part of a code ... i hope i have made my point clear thanx ... and looking for your help thanx
> wb=Bitdecom(w); is to open compressed bits for watermarking(w)
> function is similar function a=Bitdecom(o)
> wbs=reshape(wb3,1,64*64*8); DWT is divided into four parts an then again .
> so each block is 8x8 blok then 8x8 block .one little block 8*8 two litte block 2*8*8 thats why 64*64 an then one big block 64*64*8

Subject: Matlab Code Interpretation

From: Twilighter

Date: 14 Dec, 2010 05:58:05

Message: 5 of 5

i understand the DWT function and what does it do in the image ... that it divides it into 4 bands HH HL LH LL and if it applied aggian it will be a second level Wavelet transform and so on

but i still couldnt get what is the function of each command in this line code & whatit exactly do in the matrix and what is the algorithm used in that code.

it may look so trivial to you but for me as a beginner it still difficult to get.
thanx to your time ...

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us