5 Replies - 2814 Views - Last Post: 09 January 2012 - 12:37 AM Rate Topic: -----

#1 muhammad_bobby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 08 January 2012 - 04:13 AM

NEWBIE... need your help...

this matlab code for dct watermarking with grayscale image...

can you help me change my matlab code from the grayscale to RGB ???

please help mee... T_T

this my matlab code dct watermarking.... # I using matlab R2009a ^^

clc;
clear all;

start_time=cputime;

k=50;
blocksize=8;

file_name='baboon.jpg';
cover_object=double(rgb2gray(imread(file_name)));

Mc=size(cover_object,1);	     
Nc=size(cover_object,2);	        

max_message=Mc*Nc/(blocksize^2);

file_name='lena.jpg';
message=double(rgb2gray(imread(file_name)));
Mm=size(message,1);	    
Nm=size(message,2);	                
message=round(reshape(message,Mm*Nm,1)./256);

if (length(message) > max_message)
    error('Message too large to fit in Cover Object')
end

message_pad=ones(1,max_message);
message_pad(1:length(message))=message;

watermarked_image_r=cover_object;

x=1;
y=1;
for (kk = 1:length(message_pad))

    dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
    
    if (message_pad(kk) == 0)

        if (dct_block(5,2) < dct_block(4,3))
                temp=dct_block(4,3);
                dct_block(4,3)=dct_block(5,2);
                dct_block(5,2)=temp;
        end
        
    elseif (message_pad(kk) == 1)
        
        if (dct_block(5,2) >= dct_block(4,3))
                temp=dct_block(4,3);
                dct_block(4,3)=dct_block(5,2);
                dct_block(5,2)=temp;
        end
    end
    
    if dct_block(5,2) > dct_block(4,3)
        if dct_block(5,2) - dct_block(4,3) < k
            dct_block(5,2)=dct_block(5,2)+(k/2);
            dct_block(4,3)=dct_block(4,3)-(k/2);            
        end
    else  
         if dct_block(4,3) - dct_block(5,2) < k
            dct_block(4,3)=dct_block(4,3)+(k/2);  
            dct_block(5,2)=dct_block(5,2)-(k/2);
        end
    end

    watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block);    
    
    if (x+blocksize) >= Nc
        x=1;
        y=y+blocksize;
    else
        x=x+blocksize;
    end
end

watermarked_image_int=uint8(watermarked_image);
imwrite(watermarked_image_int,'dct1_watermarked_circuit.jpg','jpg');

elapsed_time=cputime-start_time,

subplot(211);imshow(cover_object,[]);title('Original Image')
subplot(212);imshow(watermarked_image,[]);title('Watermarked Image')




this my extraction watermarking matlab code..

clc;
clear all;

start_time=cputime;

blocksize=8;    

file_name='dct1_watermarked_circuit.jpg';
watermarked_image=double(imread(file_name));

Mw=size(watermarked_image,1);
Nw=size(watermarked_image,2);

max_message=Mw*Nw/(blocksize^2);

file_name='lena.jpg';
orig_watermark=double(rgb2gray(imread(file_name)));

Mo=size(orig_watermark,1);
No=size(orig_watermark,2);

x=1;
y=1;
for (kk = 1:max_message)


    dct_block=dct2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1));
    
    if dct_block(5,2) > dct_block(4,3)
        message_vector(kk)=0;
    else
        message_vector(kk)=1;
    end
 
    if (x+blocksize) >= Nw
        x=1;
        y=y+blocksize;
    else
        x=x+blocksize;
    end
end

message=reshape(message_vector(1:Mo*No),Mo,No);

elapsed_time=cputime-start_time,

subplot(212);imshow(message,[]);title('Recovered Message')
subplot(211);imshow(watermarked_image,[]);title('Watermarked Image')



If you want help me, you can send to my email : <Email removed>
I will send you my M file matlab code :D

thanks

This post has been edited by Atli: 08 January 2012 - 05:36 AM
Reason for edit:: Don't post your email in the forums.


Is This A Good Question/Topic? 0
  • +

Replies To: How to change Matlab DCT Watermarking from Grayscale to RGB

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 08 January 2012 - 05:40 AM

I don't know a thing about Matlab, but reading through that I see a few calls to a rgb2gray function. I'd start by removing those.

P.S.
I've changed the title of this thread. We already know you are asking for help, you don't need to put that as your title. You should use it to describe your question.

This post has been edited by Atli: 08 January 2012 - 05:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 muhammad_bobby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 08 January 2012 - 06:47 AM

OK thanks...

I sorry because I new member :D

^_^
Was This Post Helpful? 0
  • +
  • -

#4 muhammad_bobby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 08 January 2012 - 07:19 AM

UP UP UP...!!!

^_^
Was This Post Helpful? 0
  • +
  • -

#5 muhammad_bobby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 08 January 2012 - 12:03 PM

help...!!!
Was This Post Helpful? 0
  • +
  • -

#6 muhammad_bobby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: How to change Matlab DCT Watermarking from Grayscale to RGB

Posted 09 January 2012 - 12:37 AM

:helpsmilie: :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1