Morphological Method to Remove Tails of Ellipse Shape Sperms

1 visualización (últimos 30 días)
Peyman Ghasemi
Peyman Ghasemi el 3 de Oct. de 2017
Comentada: Javane Javaherchian el 21 de Jul. de 2022
Hi all;
I have used Otsu Thresholding in order to get the attached image (sperm Images). I want to segment the sperm heads. The problem is about the tails depicted in the image. I have some ellipse-like sperm heads that sometimes lines (or other extra parts) are attached to them. I need a morphological method (or any other methods) to remove the extra parts from binary image so that just "ellipse" or "circle"-like objects remain. In other words "Is there any morphological process that is sensitive to the shape of the objects?".
Is there any way to do this, without changing the ellipse-like heads of the sperms?
Thank you very much;
Peyman

Respuestas (3)

Image Analyst
Image Analyst el 15 de Jul. de 2022
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'sperm.jpeg';
% baseFileName = 'org.jpg';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 1);
else
grayImage = rgbImage;
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 3, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Display histogram
subplot(2, 3, 2);
histogram(grayImage, 256);
grid on;
title('Histogram of Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
threshold = 128;
mask = grayImage < threshold;
% Display mask image.
subplot(2, 3, 3);
imshow(mask);
axis('on', 'image');
drawnow;
caption = sprintf('Mask using a threshold of %.1f', threshold);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Do a morphological opening on the image.
radius = 3; % You can adjust this parameter to affect how much gets removed.
se = strel('disk', radius, 0);
mask = imopen(mask, se);
% Get rid of abnormally small blobs (noise) and unreadlistically large blobs.
% Only take blobs between 10 pixels and 2000 pixels.
mask = bwareafilt(mask, [10, 2000]);
subplot(2, 3, 4);
imshow(mask);
axis('on', 'image');
drawnow;
title('Opened Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(mask, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 3, 5);
imshow(coloredLabelsImage);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'all');
numberOfBlobs = size(blobMeasurements, 1);
caption = sprintf('%d Individual Sperms', numberOfBlobs)
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Get the areas
allAreas = [blobMeasurements.Area];
% Get the diameters
allDiameters = [blobMeasurements.EquivDiameter];
% Show size histogram of Areas.
subplot(2, 3, 6);
histogram(allAreas);
grid on;
xlabel('Area in Pixels', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Count', 'FontSize', fontSize, 'Interpreter', 'None');
title('Histogram of Areas', 'FontSize', fontSize, 'Interpreter', 'None');
  3 comentarios
Image Analyst
Image Analyst el 18 de Jul. de 2022
No, you have to do it a frame at a time. Then you can use the actual boundaries from bwboundaries, or the bounding box or ellipse from regionprops.

Iniciar sesión para comentar.


Javane Javaherchian
Javane Javaherchian el 15 de Jul. de 2022
Hi Peyman,
I have the same problem. Would you please tell that you could find the answer?
Many thanks,
Javane

Image Analyst
Image Analyst el 15 de Jul. de 2022
Did you try imclose?
  1 comentario
Javane Javaherchian
Javane Javaherchian el 15 de Jul. de 2022
Hi,
Yes. But it did not work. I want to remove the part of object (tail here) and just thresholding the head in video. Do you have any other suggestion? Many thanks

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by