clc;
clear all;
close all;
workspace;
fontSize = 20;
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
return;
end
end
monochromeImage = imread('pout.tif');
subplot(2, 2, 1);
imshow(monochromeImage);
title('Original Image', 'FontSize', fontSize);
subplot(2, 2, 2);
imshow(monochromeImage);
title('DRAW LINE HERE!!!', 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(monochromeImage);
title('Original Image with lines burned into image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Image Analysis Demo','numbertitle','off')
burnedImage = monochromeImage;
cumulativeBinaryImage = false(size(burnedImage));
subplot(2, 2, 3);
imshow(monochromeImage);
title('Binary Image', 'FontSize', fontSize);
axis on;
again = true;
lineCount = 0;
while again && lineCount < 20
promptMessage = sprintf('Draw line #%d in the upper right image,\nor Quit?', lineCount + 1);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Draw', 'Quit', 'Draw');
if strcmpi(button, 'Quit')
break;
end
lineCount = lineCount + 1;
subplot(2, 2, 2);
hLine = imline(gca);
caption = sprintf('DRAW HERE. Original Image with %d lines in overlay.', lineCount);
title(caption, 'FontSize', fontSize);
singleLineBinaryImage = hLine.createMask();
radius = round(20*rand);
se = strel('disk', radius, 0);
singleLineBinaryImage = imdilate(singleLineBinaryImage, se);
cumulativeBinaryImage = cumulativeBinaryImage | singleLineBinaryImage;
subplot(2, 2, 3);
imshow(cumulativeBinaryImage);
caption = sprintf('Binary mask of the %d lines', lineCount);
title(caption, 'FontSize', fontSize);
burnedImage(cumulativeBinaryImage) = 255;
subplot(2, 2, 4);
cla;
imshow(burnedImage);
caption = sprintf('New image with %d lines burned into image', lineCount);
title(caption, 'FontSize', fontSize);
end