how to show output of this code

4 vues (au cours des 30 derniers jours)
veenu arora
veenu arora le 19 Août 2015
i have the following code and i want to know output of these operations, i just want my matlab to show the last result
% Author: MLAB Innovation
% wtmark function performs watermarking in DCT domain
% It processes the image into 64x64 blocks.
% im = Input Image
% wt = Watermark Image/ Image to hide
% embimg = Output Embedded image
% Checking Dimnesions
clear all;
clc;
im=imread('lena.png'); % original image
wt=imread('w.jpg'); % images used for watermark/hide
hold on;
if length(size(im))>2 % check original image is RGB or gray
im=rgb2gray(im); % convert into gray for further processing
end
resize the image such that it can be breaked into 8x8 blocks easily
im = imresize(im,[512 512]); % Resize original image so that to break into 8x8 blocks
watermark = imresize(im2bw((wt)),[32 32]);% Resize and Change in binary to fit into 8x8 block
x={}; % empty cell which will consist all blocks or subimage or original image
this will break the image into 8x8 blocks and than take DCT or those blocks
dct_img=blkproc(im,[8,8],@dct2); % DCT of image using 8X8 block
m=dct_img; % DCT transformed original image in which watermark will be inserted
k=1; dr=0; dc=0;
% dr is to address 1:8 row every time for new block in x
% dc is to address 1:8 column every time for new block in x
% k is to change the no. of cell
%%%%%%%%%%%%%%%%%To divide original image in to 64 sub images of 64X64 blocks each %%%%%%%%%%%%%%%%%%
for ii=1:64:512 % To address row -- 64X64 blocks of image
for jj=1:64:512 % To address columns -- 64X64 blocks of image
for i=ii:(ii+63) % To address rows of blocks
dr=dr+1;
for j=jj:(jj+63) % To address columns of block
dc=dc+1;
z(dr,dc)=m(i,j);
end
dc=0;
end
x{k}=z; k=k+1; % concatinate the total 4096 sub images of 8x8 blocks into cell
z=[]; dr=0; % clear z and dr for next round
end
end
nn=x;
% save x in nn it consist of DCT reansformed original image into cell of
% 64 sub images having 64x64 blocks of size each
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%To insert watermark in to blocks%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i=[]; j=[]; w=1; wmrk=watermark; welem=numel(wmrk); % welem - no. of elements in watermark image
for k=1:64
kx=(x{k}); % Extracting DCT transformed original block of 8x8 size into kx for processing
for i=1:8 % To address row of block
for j=1:8 % To adress column of block
if (i==8) && (j==8) && (w<=welem) % Eligiblity condition to insert watremark
% i=1 and j=1 - means embedding element in first bit of every 8x8 block
if wmrk(w)==0 % if watermark pixel is black
kx(i,j)=kx(i,j)+35; % raise original DCT image pixel by watermark values 35
elseif wmrk(w)==1 % if watermark pixel is white
kx(i,j)=kx(i,j)-35; % down original DCT image pixel by watermark values 35
end
end
end
end
w=w+1;
x{k}=kx; kx=[]; % Watermark value will be replaced in block
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%To recombine 64x64x64 cells in to original watermarked image of 512x512 size %%%%%%%%%
i=[]; j=[]; data=[]; count=0;
embimg1={}; % Changing complete row cell of 4096 into 64 row cell
for j=1:8:64
count=count+1;
for i=j:(j+7)
data=[data,x{i}];
end
embimg1{count}=data;
data=[];
end
% Change 8 row cell in to particular columns to form image
i=[]; j=[]; data=[];
embimg=[]; % final watermarked image
for i=1:8
embimg=[embimg;embimg1{i}]; % Final watermarked image
end
embimg=(uint8(blkproc(embimg,[8 8],@idct2))); % inverse DCT transform
imwrite(embimg,'out_new.jpg') % save watermarked image
imshow('out_new.jpg')

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by