clc;
clearvars;
close all;
workspace;
fontSize = 20;
folder = 'C:\Users\Kurniawan\Documents';
baseFileName = 'tile.jpg';
fullFileName = fullfile(folder, baseFileName);
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(rgbImage);
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
blueChannel = rgbImage(:, :, 3);
subplot(2, 2, 2);
imshow(blueChannel, []);
title('Blue Channel Image', 'FontSize', fontSize);
binaryImage = blueChannel < 163;
binaryImage = bwareaopen(binaryImage, 10000);
binaryImage = imfill(binaryImage, 'holes');
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
tileBoundary = bwboundaries(binaryImage);
subplot(2, 2, 4);
imshow(rgbImage, []);
title('Original Color Image with Boundary', 'FontSize', fontSize);
hold on;
thisBoundary = tileBoundary{1};
xCoordinates = thisBoundary(:, 2);
yCoordinates = thisBoundary(:, 1);
plot(xCoordinates, yCoordinates, 'b-', 'LineWidth', 3);