clc;
close
all
;
imtool
close all
;
clear;
workspace;
format
longg
;
format
compact
;
fontSize = 20;
if
(~isdeployed)
cd(fileparts(which(mfilename)));
end
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
folder = fullfile(matlabroot,
'\toolbox\images\imdemos'
);
baseFileName =
'cameraman.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'
)
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid
on
;
title(
'Histogram of original image'
,
'FontSize'
, fontSize);
xlim([0 grayLevels(end)]);
localMinImage = imerode(grayImage, true(3));
localMaxImage = imdilate(grayImage, true(3));
subplot(2, 2, 3);
imshow(localMinImage, []);
title(
'Local Min (eroded) Image'
,
'FontSize'
, fontSize);
subplot(2, 2, 4);
imshow(localMaxImage, []);
title(
'Local Max (dilated) Image'
,
'FontSize'
, fontSize);