fileName = 'white spots.jpg';
grayImage = imread(fileName);
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = grayImage(:, :, 3);
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
g.WindowState = 'maximized'
blurredImage = imfilter(grayImage, kernel);
imshow(blurredImage, []);
horizontalProfile = improfile(blurredImage, [1, columns], [rows/2, rows/2]);
verticalProfile = improfile(blurredImage, [columns/2, columns/2], [1, rows]);
horizontalProfile = movmean(horizontalProfile, 199);
verticalProfile = movmean(verticalProfile, 199);
plot(horizontalProfile, 'b-', 'LineWidth', 2)
plot(verticalProfile, 'r-', 'LineWidth', 2)
backgroundImage = zeros(rows, columns);
backgroundImage(row, col) = sqrt(horizontalProfile(col)^2 + verticalProfile(row)^2);
backgroundImage = rescale(backgroundImage, 0, 1);
imshow(backgroundImage, []);
title('Background Image', 'FontSize', fontSize, 'Interpreter', 'None');
grayImage = uint8(double(grayImage) ./ backgroundImage);
title('Background Corrected Image', 'FontSize', fontSize, 'Interpreter', 'None');
mask = bwareafilt(mask, [60, inf]);
props = regionprops(mask, 'Area', 'MajorAxisLength', 'MinorAxisLength');
aspectRatios = [props.MajorAxisLength] ./ [props.MinorAxisLength];
keepers = find(aspectRatios > 5);
labeledImage = bwlabel(mask);
mask = ismember(labeledImage, keepers);
props = regionprops(mask, 'Area', 'MajorAxisLength', 'MinorAxisLength');
allAreas = sort([props.Area], 'descend')
aspectRatios = [props.MajorAxisLength] ./ [props.MinorAxisLength]
title('Final Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');