Sir, i need to hide the text in color image without converting it to grey scale.This is the code i did so far.I am using syndrome trllis coding here.

1 view (last 30 days)
clc
close all
clear all
clear stack
Prompt user to select the file
[fn,pn] = uigetfile('*.bmp;*.jpg;*.png','Select your original image');
I = imread([pn,fn]);
% I=imread('lena.jpg');
if size(I,3)==3
I=rgb2gray(I);
end
[r,c]=size(I);
r=r-rem(r,8);
c=c-rem(c,8);
I=imresize(I,[r,c]);
figure,imshow(I);title('cover image');
pause(2)
[row,col]=size(I);
img=I;
%secret message to be embedded
txt1=input('Enter secret text ','s');
N1=numel(txt1);
txt1=repmat(txt1, 1, 1); %Just to make text big for causing distortion in cover image
% txt1=repmat(txt1, 1, r*c/(10*8*N1)) %Just to make text big for causing distortion in cover image
N=numel(txt1);
txt=txt1-0;
Lr=dec2bin(txt,8);
Lrm1 = reshape(Lr,1,N*8);
Lrm=uint8(abs(Lrm1(:)-48));
% Lrm=[1; 0;1]
figure(1)
%%Embedding
%%Standard quantization table
qTable=[16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99];
%DCT
rev=zeros(row,col);
x=zeros(row,col);
for m=1:row/8
for n=1:col/8
s1=img((m-1)*8+1:m*8,(n-1)*8+1:n*8);
d1=dct2(s1);
q1=floor(d1./qTable+0.5);
r1=q1.*qTable;
x((m-1)*8+1:m*8,(n-1)*8+1:n*8)=r1;
end
end
% dct_a=x %future
figure,imshow(uint8(x))
title('Quantized DCT Image');
% x=dct_a;
%%x-xb
x1=x(x~=0);
si= sign(x1);
x1=abs(x1)+eps ;
pho =x1.^-1;
%xb
m=max(x1);
N=ceil(log2(m));
bi=dec2bin(x1,N);
xb=bi(:,N);
xb=uint8(abs(xb-48));
n = numel(xb); %size of the cover
h = 10; %constraint height - default is 10 - drives the complexity/quality tradeof
m = numel(Lrm); % number of message bits
cover = uint8(xb);
message = uint8(Lrm);
cost = pho;
stego = stc_embd_new(cover, message, cost);
% [dist, stego] = stc_embed(cover, message, cost, h); % embed message
% message1 = stc_extract(stego, m, h); % extract check
% disp('extract check');
% all(message == message1)
%
bi(:,N)=char(48+uint8(stego));
x1=bin2dec(bi);
x1=x1.*si;
x(x~=0)=x1;
% dct_b=x
% x=dct_b;
figure,imshow(uint8(x))
title('stego DCT Image');
%IDCT
nimg=zeros(row,col);
for m=1:row/8
for n=1:col/8
q1=x((m-1)*8+1:m*8,(n-1)*8+1:n*8);
k1=idct2(q1);
nimg((m-1)*8+1:m*8,(n-1)*8+1:n*8)=k1; %uint8(k1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
figure, imshow(uint8(nimg));title('stego image');
imwrite(uint8(nimg),'Stego.jpg');
PSNR=psnr(img,nimg)
%%Extraction
%DCT
x=zeros(row,col);
for m=1:row/8
for n=1:col/8
s1=nimg((m-1)*8+1:m*8,(n-1)*8+1:n*8);
d1=dct2(s1);
q1=round(d1);
x((m-1)*8+1:m*8,(n-1)*8+1:n*8)=q1;
end
end
% dct_c=x
figure,imshow(uint8(x))
title('rounded DCT Image');
% x=dct_c;
%%x-xb
x1=x(x~=0);
si= sign(x1);
x1=abs(x1) ;
%xb
m=max(x1);
N=ceil(log2(m));
bi=dec2bin(x1,N);
xb=bi(:,N);
xb=uint8(abs(xb-48));
h = 8; %constraint height - default is 10 - drives the complexity/quality tradeof
m = numel(Lrm); % number of message bits
message3 = stc_extrct_new(xb, m);
message2=char(message3+48);
Lrr = reshape(message2,[],8);
txt2=bin2dec(Lrr);
rectxt=txt2';
disp('Recovered secret message');
disp(char(rectxt));

Answers (1)

Walter Roberson
Walter Roberson on 5 May 2015
if size(I,3)==3
G = I(:,:,2);
B = I(:,:,3);
I = I(:,:,1);
else
G = I;
B = I;
end
[r,c]=size(I);
r=r-rem(r,8);
c=c-rem(c,8);
I=imresize(I,[r,c]);
G = imresize(G,[r,c]);
B = imresize(B,[r,c]);
then go ahead with your existing embedding code. After you have embedded, reconstruct the color image using
I = cat(3,I,G,B);

Community Treasure Hunt

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

Start Hunting!