clc;
close all;
imtool close all;
clear;
workspace;
format longg;
format compact;
fontSize = 20;
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'moon.tif';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage);
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
uiwait(msgbox('Draw the ROI. Left click to anchor vertices, then right click inside to finish it up.'));
binaryImage =roipolyold();
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Your ROI', 'FontSize', fontSize);
image81 = grayImage == 81;
binaryImage = binaryImage & image81
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Value = 81 AND inside Your ROI', 'FontSize', fontSize);
redChannel = grayImage;
greenChannel = grayImage;
blueChannel = grayImage;
redChannel(binaryImage) = 0;
greenChannel(binaryImage) = 255;
blueChannel(binaryImage) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 2, 4);
imshow(rgbImage, []);
title('RGB image with green', 'FontSize', fontSize);
Best Answer