clc;
fprintf('Beginning to run %s.m ...\n', mfilename);
close all;
imtool close all;
clear;
workspace;
fontSize = 15;
rgbImage = imread('peppers.png');
subplot(3, 2, 1);
imshow(rgbImage, []);
title('Color Image', 'FontSize', fontSize);
greyImage = rgb2gray(rgbImage);
subplot(3, 2, 2);
imshow(greyImage);
title('Gray Scale Image', 'FontSize', fontSize);
[counts, ~] = imhist(greyImage, 255);
T = otsuthresh(counts);
mask = imbinarize(greyImage, T);
mask = bwareaopen(mask, 3000);
mask = imfill(mask, 'holes');
mask = bwperim(mask);
mask = imdilate(mask, ones(5));
mask = imerode(mask, ones(3));
mask = imfill(mask, 'holes');
subplot(3, 2, 3);
imshow(mask);
title('Mask Image', 'FontSize', fontSize);
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
subplot(3, 2, 4);
imshow(maskedRgbImage);
title('Masked RGB Image', 'FontSize', fontSize);
hsvImage = rgb2hsv(maskedRgbImage);
hueChannel = hsvImage(:,:,1);
subplot(3, 2, 5);
imshow(hueChannel, []);
title('Hue Channel Image', 'FontSize', fontSize);
maskH = rgbImage .* repmat(uint8(hueChannel),[1 1 3]);
subplot(3, 2, 6);
imshow(maskH);
title('MaskH Image', 'FontSize', fontSize);
fprintf('Done running %s.m ...\n', mfilename);
0 Comments
Sign in to comment.