Uploaded by Garvit Choudhary

201112207 DIP Lab4

advertisement
DIGITAL IMAGE PROCESSING (DIP) – LAB 4
Jatin Vangani
201112207,
CSE 2
Write and execute programs for image logical operation
1. AND Operation between two images
2. OR operation between two mares
3. Calculate the intersection of two images
4.
Water marking using XOR Operation
% Load the two images
image1 = imread('eagle.jpg');
image2 =
imread('butterfly.jpeg');
% Get the sizes of the images
size1 = size(image1);
size2 = size(image2);
% Check if the sizes match and
resize if necessary
if ~isequal(size1, size2)
if numel(size1) == 3 &&
numel(size2) == 3
% Resize image2 using
bilinear interpolation if both
are color images
image2 =
imresize(image2, [size1(1),
size1(2)]);
else
% Resize image2 using
bilinear interpolation if one or
both are grayscale
image2 =
imresize(image2, [size1(1),
size1(2)], 'bilinear');
end
end
% Perform bitwise AND, OR, and
intersection operations
andoper = bitand(image1,
image2);
union = bitor(image1, image2);
intersection = bitand(image1,
image2);
% Resize the watermark image to
match the original image size
original_image =
imread('eagle.jpg');
watermark =
imread('butterfly.jpeg');
original_height =
size(original_image, 1);
original_width =
size(original_image, 2);
watermark = imresize(watermark,
[original_height,
original_width]);
% Watermarking using XOR
operation
watermarked_image =
bitxor(original_image,
watermark);
% Display the images
figure;
subplot(2,3,1);
imshow(image1);
title('Original Image 1');
subplot(2, 3, 2);
imshow(image2);
title('Original Image 2');
subplot(2, 3, 3);
imshow(andoper);
title('AND Operation');
subplot(2, 3, 4);
imshow(union);
title('OR Operation');
subplot(2, 3, 5);
imshow(intersection);
title('Intersection');
subplot(2, 3, 6);
imshow(watermarked_image);
title('Watermarked Using XOR');
axis off;
% Save the combined images
figure
set(gcf, 'Position', get(0,
'Screensize'));
saveas(gcf,
'combined_images.jpg');
Download