MATLAB: There some error in watermarking image

if run it show black image

if true
% code
endclc;
close all;
clear all;
base = imread('watermark.png');
watermark = imread('base.png');
figure(1)
imshow(base)
title('Original Image ')
figure(2)
imshow(watermark)
title('Watermark Image')
base=im2double(base);
watermark=double(watermark);
bits=1;
% Now, we shift the watermark image over 8(-)bits to the right
watermark_shifted=bitshift(watermark,-(8-bits));
for i=1:bits
base=bitset(round(base),i,0);
end
watermarked_image = uint8(base+watermark_shifted);
figure(3)
imshow(watermarked_image)
title('Watermarked Image')
imwrite(watermarked_image,'invsible watermarked image.bmp'); % Save modified image

Best Answer

You used im2double(base) which is going to make the values be between 0 and 1. Then in your "for" loop, you round() that, which is going to give you either 0 or 1 exactly; you then bitset() bit #1 to 0, which is going to clear the bottom bit, leaving you with 0 if you started with 0, and leaving you with 0 if you started with 1. The only thing that might be left is watermark_shifted, which itself is only going to be 0 or 1.
Related Question