Borrar filtros
Borrar filtros

The matrices rgb and imag1 have same values,same dimensions but different class.But while displaying images imag1 and rgb are different.Why is it so?

2 visualizaciones (últimos 30 días)
clc;
clear all;
close all;
imag1=imread('lena.jpg');
subplot(1,2,1);
imshow(imag1);
v=rgb2gray(imag1);
r=1;
[rows, columns] = size(v);
N=rows;
M=columns;
subplot(1,3,1);
imshow(v);
if(M~=N)
I=imresize(v,[M,M]);
else
I=v;
end
x(1)=0.8;
r=1;
c=0.505;
for i=1:((M*M)*8)
x(i+1)=4*(x(i)*(1-x(i))*x(i));
if(x(i)>c)
w(i)=0;
else if(x(i)<=c)
w(i)=1;
end
end
end
while r<((M*M)+1)
for i=1:M
for j=1:M
k(r)=I(i,j);
l(r)=k(r);
r=r+1;
end
end
end
r=1;
for r1=1:(M*M)
for c1=1:8
if(r<(((M*M)+1)*8))
z=de2bi(l(r1),8);
b(:,r)=z(c1);
r=r+1;
end
end
end
%%%%Cipher creation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:(M*M*8)
encrypt(i)=bitxor(w(i),b(i));
end
%%%%%%%%%%binary to decimal
k=1;
l=1;
j=1;
while(l<=(M*M))
k1=encrypt(k:(j*8));
cipher=bi2de(k1);
c(l)=cipher;
k=(j*8)+1;
j=j+1;
l=l+1;
end
%%%%%string to image
l1=1;
while (l1<(M*M)+1)
for i=1:M
for j=1:M
v2(i,j)=c(l1);
l1=l1+1;
end
end
end
subplot(1,3,2);
imshow(v2);
% v3=im2uint8(v2);
% results = NPCR_and_UACI(v,v3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DECRYPTION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:(M*M*8)
decrypt(i)=bitxor(encrypt(i),w(i));
end
l=1;
jj=1;
kk=1;
while(l<=(M*M))
k2=decrypt(kk:(jj*8));
cipher1=bi2de(k2);
c1(l)=cipher1;
kk=(jj*8)+1;
jj=jj+1;
l=l+1;
end
l2=1;
while (l2<(M*M)+1)
for i=1:M
for j=1:M
d(i,j)=c1(l2);
l2=l2+1;
end
end
end
rgb=d(:,:,[1 1 1]);
subplot(1,3,3);
imshow(rgb);
end
This is the code.Now the problem is that rgb is 256*256*3
whose matrix values are same as matrix of original image.But I'm
unable to get the image as such.

Respuestas (1)

Stephen23
Stephen23 el 9 de En. de 2017
Editada: Stephen23 el 10 de En. de 2017
"Why is it so?"
Because the different classes get treated differently.
The output from imread is (most likely) of class uint8.
imshow assumes that uint8 image data is between 0 and 255, and that double image data is between 0 and 1. This has been explained multiple times on this forum:
So you need to convert the double data to the range [0,1], or convert the image to uint8 using im2uint8, or use the second optional input to specify the input data range:
imshow(I,[0,255])

Community Treasure Hunt

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

Start Hunting!

Translated by