Filter löschen
Filter löschen

How to run this code?

1 Ansicht (letzte 30 Tage)
Afeza Ajirah
Afeza Ajirah am 12 Mai 2017
Kommentiert: Afeza Ajirah am 12 Mai 2017
Hi, i have problem on running this code due to some error. The only output is the displaying of 'original image'. Hopefully, you guys can help me fix it. Thank you so much.
error: Error in Wprocess (line 18)
H1=rgb2gray(I2); %convert it into gray scale image
_______________________________________________________________________________
x=.01;
t=cputime;
I1=imread('lena.jpg');%read image
% I1=imread('mand.jpg');%read image
H=rgb2gray(I1); %convert it into gray scale image
J=imresize(H,[512 512]);%resize image into 512x512 image
J= double(J);
[M,N]=size(J);
figure,imshow(uint8 (J));title('Original image')
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');
[ca,ch,cv,cd] = dwt2(J,Lo_D,Hi_D);
[ca1,ch1,cv1,cd1] = dwt2(ch,Lo_D,Hi_D);
[U,S,V] = svd(ch1);
[m,n]=size(S);
% Copy the original Singular value
Sw=S;
I2=imread('cameraman.jpg');%read Watermark image
H1=rgb2gray(I2); %convert it into gray scale image
J1=imresize(H1,[128 128]);%resize image
[a,b]=size(ch1);
W1= double(J1);
W1=imresize(W1,[a b]);% resize the 1 watermark image
[p,q]=size(W1);
% Watermark insertion
S=S+(x*W1);
[U_w,S_w,V_w]=svd(S);
[cs1]=[U*S_w*V'];
wing = idwt2(ca1,cs1,cv1,cd1,Lo_R,Hi_R);
wing1 = idwt2(ca,wing,cv,cd,Lo_R,Hi_R);
t1=cputime;
figure,imshow(uint8(wing1)),title('Watermarked Image')

Akzeptierte Antwort

KSSV
KSSV am 12 Mai 2017
Your cameraman.jpg image is already a gray image, you are trying to convert it to gray using rgb2gray, that's why error. Try this:
x=.01;
t=cputime;
I1=imread('lena.jpg');%read image
% I1=imread('mand.jpg');%read image
H=rgb2gray(I1); %convert it into gray scale image
J=imresize(H,[512 512]);%resize image into 512x512 image
J= double(J);
[M,N]=size(J);
figure,imshow(uint8 (J));title('Original image')
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');
[ca,ch,cv,cd] = dwt2(J,Lo_D,Hi_D);
[ca1,ch1,cv1,cd1] = dwt2(ch,Lo_D,Hi_D);
[U,S,V] = svd(ch1);
[m,n]=size(S);
% Copy the original Singular value
Sw=S;
I2=imread('cameraman.jpg');%read Watermark image
if size(I2,3)==3
H1=rgb2gray(I2); %convert it into gray scale image
else
H1 = I2 ;
end
J1=imresize(H1,[128 128]);%resize image
[a,b]=size(ch1);
W1= double(J1);
W1=imresize(W1,[a b]);% resize the 1 watermark image
[p,q]=size(W1);
% Watermark insertion
S=S+(x*W1);
[U_w,S_w,V_w]=svd(S);
[cs1]=[U*S_w*V'];
wing = idwt2(ca1,cs1,cv1,cd1,Lo_R,Hi_R);
wing1 = idwt2(ca,wing,cv,cd,Lo_R,Hi_R);
t1=cputime;
figure,imshow(uint8(wing1)),title('Watermarked Image')
  1 Kommentar
Afeza Ajirah
Afeza Ajirah am 12 Mai 2017
Sir!! You are the bestt, thank you so much for helping me out! May God bless you thank you sir

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by