clc;
close all;
imtool close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
folder = 'C:\Users\Amal\Documents\Temporary';
baseFileName = 'phantom.png';
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);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2);
end
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(grayLevels, pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]);
meanImage = imfilter(grayImage, ones(9)/81);
subplot(2, 2, 3);
imshow(meanImage, []);
title('Mean Image', 'FontSize', fontSize);
hp = impixelinfo();
set(hp,'Units', 'Normalized', 'Position',[.8 .98 .300 .20]);
binaryImage = meanImage < 150;
binaryImage = bwareaopen(binaryImage, 1000);
binaryImage = imclearborder(binaryImage);
subplot(2, 2, 4);
imshow(binaryImage, []);
[labeledImage, numberOfSpots] = bwlabel(binaryImage);
measurements = regionprops(labeledImage, grayImage, 'MeanIntensity', 'Centroid');
allIntensities = [measurements.MeanIntensity]
for spot = 1 : numberOfSpots
theLabel = sprintf('Spot %d = %.2f', spot, allIntensities(spot));
x = measurements(spot).Centroid(1);
y = measurements(spot).Centroid(2);
text(x, y, theLabel, 'Color', 'r', 'FontWeight', 'Bold', 'FontSize', 12);
end