imshow() black image

2 views (last 30 days)
Mostfa Abd El-Aziz
Mostfa Abd El-Aziz on 22 Aug 2020
%% Extraction Step
Ex_watermark=zeros(8);
Watermarked_B=Watermarked_image(:,:,3);
c=0;
for i=1:64:64*64-63
c=c+1;
block_index=key(i:i+63);
blockB=double(reshape(B(block_index),[8,8]));
% discrete cosine transform:
dct_blockB=dct2(blockB);
% Singular Value Decomposition:
[Ub,Sb,Vb]=svd(dct_blockB(dct_idx));
Sbw=reference{i};
sigmaB=Sb(1); % Biggest Singular Value - Host
sigmaBW=Sbw(1); % Biggest Singular Value - Watermarked
% Extracting watermark image:
if sigmaBW>sigmaB
Ex_watermark(c)=1;
end
end
subplot(1,4,4),
imshow(Ex_watermark)
xlabel('Extracted Watermark');
  8 Comments
Image Analyst
Image Analyst on 23 Aug 2020
Mostfa, did you overlook where he said "if not working share the code and data." Not doing that is delaying a solution to your problem. If using [] in imshow() did not solve it, then your image is all zero.
Mostfa Abd El-Aziz
Mostfa Abd El-Aziz on 24 Aug 2020
clc
close all
clear
%% Input images
I=imread('gl1.jpg');
I=imresize(I,[512,512]);
logo=imread('watermark.jpg');
logo=imresize(logo,[64,64]);
figure
subplot(1,4,1)
imshow(I)
title('Host Image')
subplot(1,4,2)
B=I(:,:,3); % Blue Channel
imshow(logo)
xlabel('Logo (Watermark Image)')
gf=100; % Watermark Strength
n_dct=60; % <=64
zigzag=[1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 41 34 27 20 13 6 7 14 21 28 35 42 49 57 ...
50 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 62 63 56 64];
dct_idx=zigzag(1:n_dct);
%% key generation:
key=randperm(512*512,64*64);
%% Block Selection (Embedding Step):
c=0;
Watermarked_B=B;
for i=1:64:64*64-63
c=c+1;
block_index=key(i:i+63);
blockB=double(reshape(B(block_index),[8,8]));
% discrete cosine transform:
dct_blockB=dct2(blockB);
% Singular Value Decomposition:
[U,S,V]=svd(dct_blockB(dct_idx));
sigmaB=S(1); % Biggest Singular Value
% embedding watermark image:
if logo(c)==1
S(1)=sigmaB+gf;
else
S(1)=sigmaB-gf;
end
reference{i}=S;
coeffs=U*S*V; % inverse svd
rec_dct_block=zeros(8);
rec_dct_block(dct_idx)=coeffs;
rec_block=idct2(rec_dct_block); % inverse dct
row_block=reshape(rec_block,1,64);
Watermarked_B(block_index)=row_block;
end
Watermarked_image=I;
Watermarked_image(:,:,3)=Watermarked_B;
subplot(1,4,3),
imshow(Watermarked_image);
title('Watermarked Image')
%% Extraction Step
Ex_watermark=zeros(8);
Watermarked_B=Watermarked_image(:,:,3);
c=0;
for i=1:64:64*64-63
c=c+1;
block_index=key(i:i+63);
blockB=double(reshape(B(block_index),[8,8]));
% discrete cosine transform:
dct_blockB=dct2(blockB);
% Singular Value Decomposition:
[Ub,Sb,Vb]=svd(dct_blockB(dct_idx));
Sbw=reference{i};
sigmaB=Sb(1); % Biggest Singular Value - Host
sigmaBW=Sbw(1); % Biggest Singular Value - Watermarked
% Extracting watermark image:
if sigmaBW>sigmaB
Ex_watermark(c)=1;
end
end
subplot(1,4,4),
imshow(double(Ex_watermark))
xlabel('Extracted Watermark');

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!