clc;
clear all;
close all;
workspace;
format long g;
format compact;
fontSize = 15;
folder = pwd;
fullFileName = fullfile(folder, 'fibres.png')
grayImage = imread(fullFileName);
if ndims(grayImage) > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 3, 1);
imshow(grayImage);
colormap gray;
axis('on', 'image');
caption = sprintf('Original Image');
title(caption, 'fontSize', fontSize)
drawnow;
g = gcf;
g.Units = 'normalized';
g.Position = [0.1, 0.2, 0.8, 0.7]
maxOfOpenings = zeros(size(grayImage), 'like', grayImage);
angleOfMax = zeros(size(grayImage));
lengthOfLine = 30;
for theta = 1 : 0.25 : 180
fprintf('Theta = %.2f.\n', theta);
SE = strel('line', lengthOfLine, theta);
thisImage = imopen(grayImage, SE);
maxOfOpenings = max(maxOfOpenings, thisImage);
thisIsMax = (thisImage == maxOfOpenings);
angleOfMax(thisIsMax) = theta;
if rem(theta, 10) == 1
subplot(2, 3, 2);
imshow(thisImage, []);
axis('on', 'image');
caption = sprintf('Opened with line at %d degrees', theta);
title(caption, 'fontSize', fontSize)
subplot(2, 3, 3);
imshow(maxOfOpenings, []);
axis('on', 'image');
caption = sprintf('Output After theta = %d', theta);
title(caption, 'fontSize', fontSize)
drawnow;
subplot(2, 3, 4);
imshow(angleOfMax, []);
axis('on', 'image');
caption = sprintf('Angle Of Max');
title(caption, 'fontSize', fontSize)
impixelinfo;
drawnow;
end
end
axis('on', 'image');
subplot(2, 3, 5:6);
histogram(angleOfMax);
grid on;
title('Distribution of Angle of Max', 'fontSize', fontSize);
xlabel('Angle of Max', 'fontSize', fontSize);
ylabel('Count', 'fontSize', fontSize);