iam new to matlab..i was trying to understand this code..there is something wrong with this code..after the 3rd figure is displayed...nothing happens...what is the correction to be made?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
chaithra
el 27 de En. de 2014
Respondida: Walter Roberson
el 27 de En. de 2014
%This was used at the 2004 Cyber Summer Camp
%This program hides a message image in the lower
%bit planes of a cover image
%read in cover image filename
covername = input('Enter image file name with extension (like jennifer.bmp): ', 's');
%read in message image filename
messagename = input('Enter message image file name with extension: ', 's');
%open cover and message image files
cover = imread(covername);
message = imread(messagename);
%display on screen the two images
figure(1), imshow(cover); title('Original Image (Cover Image)');
figure(2), imshow(message);title('Image to Hide (Message Image)');
%change to double to work with addition below
cover=double(cover);
message=double(message);
%imbed = no. of bits of message image to embed in cover image
imbed=4;
%shift the message image over (8-imbed) bits to right
messageshift=bitshift(message,-(8-imbed));
%show the message image with only embed bits on screen
%must shift from LSBs to MSBs
showmess=uint8(messageshift);
showmess=bitshift(showmess,8-imbed);
figure(3),imshow(showmess);title('4 Bit Image to Hide');
%now zero out imbed bits in cover image
coverzero = cover;
for i=1:imbed
coverzero=bitset(coverzero,i,0);
end
%now add message image and cover image
stego = uint8(coverzero+messageshift);
figure(4),imshow(stego);title('Stego image');
%save files if need to
%4 bit file that was embedded = same as file extracted imwrite(showmess,'showmess4.bmp'); %use bmp to preserve lower bits
%jpg will get rid of them
%stego file
imwrite(stego,'stego4.bmp');
1 comentario
Walter Roberson
el 27 de En. de 2014
To check: no figure 4 comes up with a title "Stego image" ?
I suggest you put
drawnow()
after the title() call for figure 3.
Respuesta aceptada
Walter Roberson
el 27 de En. de 2014
You imread() message and then double() it. You then calculate messageshift from it. That makes messageshift double() as well. You then try to add messageshift to cover, where cover is the result of imread() and so is unlikely to be double; more likely to be uint8. So you are trying to add a uint8 array to a double array. That's not a valid operation in MATLAB: you can only add uint8 and double if the double is a scalar instead of an array.
Solution:
stego = uint8(double(coverzero)+messageshift);
0 comentarios
Más respuestas (1)
Image Analyst
el 27 de En. de 2014
You might want to break this
figure(3),imshow(showmess);title('4 Bit Image to Hide');
up into three separate lines and step on them in the debugger:
figure(3);
imshow(showmess);
title('4 Bit Image to Hide');
figure(3) will display the third figure - a blank window. After you display the third figure (and this is where you said it stops responding), then the next line is the imshow() line. Step on that line in the debugger. Does it display anything or does it just hang? If you don't know how to use the debugger (you're not alone - it's an all too common occurrence), then see this http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
2 comentarios
Image Analyst
el 27 de En. de 2014
You forgot to include the error message. I'm guess it's this line:
stego = uint8(coverzero+messageshift);
Are both of those uint8, uint16, or double? Does their sum exceed 255 if they're uint8? If not, maybe try this:
stego = uint8(double(coverzero)+double(messageshift));
Ver también
Categorías
Más información sobre Encryption / Cryptography en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!