clc;
close all;
clear;
workspace;
format short g;
format compact;
fontSize = 25;
baseFileName = 'o4s1_11.bmp';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
grayImage1 = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(grayImage1)
if numberOfColorChannels > 1
grayImage1 = grayImage1(:, :, 2);
end
subplot(2, 2, 1);
imshow(grayImage1, []);
axis on;
axis image;
caption = sprintf('Image1');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, .96]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
fullFileName = fullfile(pwd, 'blankv5.bmp');
grayImage2 = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(grayImage2)
if numberOfColorChannels > 1
grayImage2 = grayImage2(:, :, 2);
end
subplot(2, 2, 2);
imshow(grayImage2, []);
axis on;
axis image;
caption = sprintf('Image2');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
subplot(2, 2, 3);
histogram(grayImage2);
grid on;
threshold = 128;
binaryImage = grayImage1 < threshold;
binaryImage = imclearborder(binaryImage);
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
axis image;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
grayImage2(binaryImage) = grayImage1(binaryImage);
subplot(2, 2, 4);
imshow(grayImage2, []);
axis on;
axis image;
caption = sprintf('Final Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
Best Answer