Error using round(resh​ape(messag​e,Mm*Nm,1)​./256)

3 views (last 30 days)
Hello,
What may be the problem with the following code line?
message=round(reshape(message,Mm*Nm,1)./256); using this I want to check message isn't too large to fit in cover image.
Where message=double(imread('lena.jpg')) and [Mm Nm] is the size of the message.
Thanks in advance

Answers (2)

James Tursa
James Tursa on 6 Nov 2014
What does the error message say?
Double check the size of the variable message to make sure it really is Mm x Nm.
Note that you can replace reshape(message,Mm*Nm,1) with message(:)
  2 Comments
vaishali
vaishali on 6 Nov 2014
Edited: James Tursa on 6 Nov 2014
Thank you for your fast response .
The error says "To RESHAPE the number of elements must not change."
And this is the code segment
close all;
clear;
cover = imread('cheeta.jpg');
[a1 h1 v1 d1] = dwt2(cover,'haar');
[a2 h2 v2 d2] = dwt2(h2,'haar');
k=50; % set minimum coeff difference
blocksize=8; % set the size of the block in cover to be used for each bit in watermark
cover_object=h2;
%figure,imshow(cover);title('Original'); % determine size of cover image
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2);
% determine maximum message size based on cover object, and blocksize
max_message=Mc*Nc/(blocksize^2); % read in the message image
msg='lena.jpg';
message=double(imread(msg));
Mm=size(message,1); %Height
Nm=size(message,2); %Width % reshape the message to a vector
message=round(reshape(message,Mm*Nm,1)./256);
James Tursa
James Tursa on 6 Nov 2014
What is size(message)? In particular, what is size(message,3)?

Sign in to comment.


Roger Stafford
Roger Stafford on 6 Nov 2014
Does 'lena.jpg' produce a third dimension for color? If so, that would account for your error message; you would have more than Mm*Nm elements in 'message'.

Community Treasure Hunt

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

Start Hunting!