Error in Image Embedding....

2 visualizzazioni (ultimi 30 giorni)
amitesh kumar
amitesh kumar il 6 Mar 2011
Hello i am trying to run following code...
i=imread('lena.tif');
s=double(i);
j=imread('watermark.bmp');
w=double(j);
[m,n]=size(s);
[g,h]=size(w);
x=dec2bin(s,8); % decimal to binary transformation
y=double(x);
y=y-48;
plane=cell(1,8);
for r=1:8
plane{r}=y(:,r);
end
for r=1:8
planes{r}=reshape(plane{r},m,n);
end
but i am getting error as follows: ??? Operands to the and && operators must be convertible to logical scalar values.
Error in ==> dec2bin at 31 if any(d < 0) any(~isfinite(d))
Error in ==> Un2 at 13 x=dec2bin(s,8); % decimal to binary transformation
my image size is 512*512 ans watermark size is 64*64.. any one would like to suggest me how can i debug it...thnax and regards....
  3 Commenti
amitesh kumar
amitesh kumar il 6 Mar 2011
sorry sir..from now onwards i'll keep this in mind. one thing i would like to say that ur previous answer regarding log-polar help me a lot regarding getting idea about it. thanx a lot....
David Young
David Young il 6 Mar 2011
Thanks!
David

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 6 Mar 2011
dec2bin() is not documented as accepting anything other than a scalar.
In practice, dec2bin() accepts a vector, but it does not accept an array of 2 or more dimensions. Thus:
dec2bin(s(:),8)

Più risposte (2)

amitesh kumar
amitesh kumar il 6 Mar 2011
Thnx sir for ur answer.
w(m,n)=0;
planes{8}=ones(m,n);
planes{8}= and(planes{8},w); % Adding the WaterMark
for r=1:8
frames(:,:,1,r)=planes{r};
end
iy=zeros(m*n,8);
for r=1:8
iplanes{r}=reshape(planes{r},(m*n),1);
iy(:,r)=iplanes{r}(:,1);
end
if i am trying to execute further after modifying as u previouly suggested me ,it's showing another error as
??? Attempt to grow array along ambiguous dimension.
Error in ==> Un2 at 24
w(m,n)=0;
here i tried also by changing the w(m,n)as w(g,h) but in this case it is showing error as
??? Error using ==> and
Inputs must have the same size.
Error in ==> Un2 at 26
planes{8}= and(planes{8},w); % Adding the WaterMark
so sir i would again expect ur suggestion regarding this error
thanx and regards....
  1 Commento
Walter Roberson
Walter Roberson il 6 Mar 2011
Using w(m,n) = 0 could result in "Attempt to grow array along ambiguous dimension" if w (your watermark image) was 3 dimensional, such as would be the case if it is an RGB image. You need to test for that case and figure out what you want to do if it happens.

Accedi per commentare.


amitesh kumar
amitesh kumar il 7 Mar 2011
thnku so much Walter...got executed prog successfully...i am getting original image, watermark image in perfect manner ..but the final image as figure 3 is not coming as embedded one. as it coming in improper manner. showing some blur effect.this is the further code which i am using in continuation with above mentioned code...everything working fine just i am getting embedded image not in a proper way.
iy1=zeros(1,m*n);
for L=1:m*n
for r=1:8
iy1(L)=iy1(L)+iy(L,9-r)*(2^(r-1));
end
end
s_plus_w=reshape(iy1,m,n);
s_plus_w=uint8(s_plus_w);
imwrite(s_plus_w,'img.tif');
imshow('img.tif');
figure,imshow(j)
figure,montage(frames)
and again thnku so much for giving me ur precious time to sort out my doubts.
  2 Commenti
Walter Roberson
Walter Roberson il 7 Mar 2011
I'll need to see the full corrected code, not just the additional steps.
amitesh kumar
amitesh kumar il 7 Mar 2011
Here i am giving the full corrected code...
i=imread('lena.tif');
s=double(i);
j=imread('watermark.bmp');
w1 = rgb2gray(j);
w=double(w1);
[m,n]=size(s);
[g,h]=size(w);
x=dec2bin(s(:),8); % decimal to binary transformation
y=double(x);
y=y-48;
plane=cell(1,8);
for r=1:8
plane{r}=y(:,r);
end
for r=1:8
planes{r}=reshape(plane{r},m,n);
end
w(m,n)=0;
planes{8}=ones(m,n);
planes{8}= and(planes{8},w); % Adding the WaterMark
for r=1:8
frames(:,:,1,r)=planes{r};
end
iy=zeros(m*n,8);
for r=1:8
iplanes{r}=reshape(planes{r},(m*n),1);
iy(:,r)=iplanes{r}(:,1);
end
iy1=zeros(1,m*n);
for L=1:m*n
for r=1:8
iy1(L)=iy1(L)+iy(L,9-r)*(2^(r-1));
end
end
s_plus_w=reshape(iy1,m,n);
s_plus_w=uint8(s_plus_w);
imwrite(s_plus_w,'img.tif');
imshow('img.tif');
figure,imshow(j)
figure,montage(frames)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by