Error. Inputs must have the same size

48 views (last 30 days)
Hello ,I recive the following error for the code bellow .Can you help me please?
Error using bitor.Inputs must have the same size. (line 12)
clc;
clear all;
close all;
cover = input('alegeti poza' , 's');
message = input('introduceti textul dorit ', 's');
x = imread(cover); % cover message
y = imread(message); % message image
n = 3 %input('Enter the no of LSB bits to be subsituted- ');
S = uint8(bitor(bitand(x,bitcmp(2^n-1,8)),bitshift(y,n-8))); %Stego
E = uint8(bitand(255,bitshift(S,8-n))); %Extracted
origImg = double(y); %message image
distImg = double(E); %extracted image
[M N] = size(origImg);
distImg1=imresize(distImg,[M N]);
error = origImg - distImg1;
MSE = sum(sum(error .* error)) / (M * N);
if(MSE > 0)
PSNR = 10*log10(M*N./MSE);
else
PSNR = 99;
end
disp('PSNR of message image to extracted image is')
disp(abs(PSNR))
disp('MSE is')
disp(abs(MSE))

Accepted Answer

Jan
Jan on 16 Mar 2017
Edited: Jan on 16 Mar 2017
The message means, that this fails:
bitor(bitand(x, bitcmp(2^n-1, 8)), bitshift(y, n-8))
Because the bitand and bitshift do not change the size of the inputs, the error is caused by the different sizes of x and y. Is it assumd that both images have the same size? If not, how do you want to consider different sizes?
  1 Comment
Walter Roberson
Walter Roberson on 16 Mar 2017
One difficulty to watch out for is that one of your images might be stored as RGB even though it looks like greyscale, and the other might be stored as true grayscale.
But more likely your images are just different sizes. You should be taking into account that the message will seldom be exactly the same size as the cover image.

Sign in to comment.

More Answers (2)

john j sanabria
john j sanabria on 21 Oct 2017
nop the error is about bitcmp(2^n-1,8), any n it just said "Error using bitcmp ASSUMEDTYPE must be an integer type name."
  2 Comments
john j sanabria
john j sanabria on 21 Oct 2017
one possible solution is "bitand(x,bitcmp(2^n-1,'uint8')" with MATLAB Version: 9.0.0.341360 (R2016a)

Sign in to comment.


Nazish Iqbal
Nazish Iqbal on 7 Jan 2020
%ENCRYPTION
clear all
%READ THE COVER IMAGE
I = imread('C:\Users\dell\Desktop\peppers.jpg');
%READ THE IMAGE TO HIDE
J = imread('C:\Users\dell\Desktop\cube.jpg');
%PREALLOCATE THE OUTPUT IMAGE
Output = zeros(size(I));
%REPRESENT THE NUMBER OF ROWS AND COLUMNS OF THE SECRET IMAGE
%IN BINARY FORMAT
Jsize = de2bi([size(J,1),size(J,2)]);
%RED,GREEN AND BLUE COMPONENTS OF THE SECRET IMAGE
Red_Ch = J(:,:,1);
Green_Ch = J(:,:,2);
Blue_Ch = J(:,:,3);
%CONVERT THE RED COMPONENT OF THE SECRET IMAGE INTO BINARY FORMAT
Encrypt_Red = de2bi(Red_Ch(:),8)';
Encrypt_Red = Encrypt_Red(:)';
%CONVERT THE GREEN COMPONENT OF THE SECRET IMAGE INTO BINARY FORMAT
Encrypt_Green = de2bi(Green_Ch(:),8)';
Encrypt_Green = Encrypt_Green(:)';
%CONVERT THE BLUE COMPONENT OF THE SECRET IMAGE INTO BINARY FORMAT
Encrypt_Blue = de2bi(Blue_Ch(:),8)';
Encrypt_Blue = Encrypt_Blue(:)';
%CALCULATE THE INTERVAL AND CONVERT IT INTO BINARY FORMAT
dt=floor((size(I,1)*size(I,2))/numel(Encrypt_Red));
Bi_dt = de2bi(dt,8);
Info_data = [Bi_dt,Jsize(1,:),Jsize(2,:)];
%RED,GREEN AND BLUE COMPONENT OF THE COVER IMAGE
Red_mat = I(:,:,1);
Green_mat = I(:,:,2);
Blue_mat = I(:,:,3);
% INTERVAL,NUMBER OF COLUMNS, NUMBER OF ROWS
Red_mat(1:24) = bitset(Red_mat(1:24),1,Info_data);
Green_mat(1:24) = bitset(Green_mat(1:24),1,Info_data);
Blue_mat(1:24) = bitset(Blue_mat(1:24),1,Info_data);
%%REPLACE THE LEAST SIGNIFICANT BIT OF THE COVER IMAGE
%WITH THE BINARY FORMAT OF THE SECRET IMAGE
EndValue = numel(Encrypt_Red)*dt+24;
Red_mat(25:dt:EndValue) = bitset(Red_mat(25:dt:EndValue),1,Encrypt_Red);
Green_mat(25:dt:EndValue) = bitset(Green_mat(25:dt:EndValue),1,Encrypt_Green);
Blue_mat(25:dt:EndValue) = bitset(Blue_mat(25:dt:EndValue),1,Encrypt_Blue);
%ENCRYPTED IMAGE
Output(:,:,1) = Red_mat;
Output(:,:,2) = Green_mat;
Output(:,:,3) = Blue_mat;
Output = uint8(Output);
figure,subplot(121),imshow(I); subplot(122),imshow(Output);
%DIFFERENCE BETWEEN THE ORIGINAL AND THE ENCRYPTED IMAGE
figure,imagesc(double(I)-double(Output));colormap(jet);colorbar;
%WRITE THE ENCRYPTED IMAGE IN THE PNG FORMAT
imwrite(Output,'Encrypt_Image1.png');
stuck in line 52.kindly help me
error.PNG

Products

Community Treasure Hunt

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

Start Hunting!