How to segment cells(round) and bacterias(longitudinal) and label them ?

1 次查看(过去 30 天)
I would like to segment the cells(round) and bacterias(thin lines) in the image and label them respectively in a robust manner without using any machine learning methods. I can now draw the boundaries of the cells that intersect with the border by padding the borders and thus enclosing the incomplete cells. However, I don't know how to proceed from here.
Below is my code so far:
% Read image
I2 = imread("images like the one i uploaded");
% Convert RGB to Grayscale
I2_gray = rgb2gray(I2);
% Enhance image
I2_enhanced = imadjust(I2_gray);
% Binarise Image
I2_binarised = imbinarize(I2_enhanced);
% Set up threshold-based filter to remove noise
I2_binarised = bwpropfilt(I2_binarised, 'Area', [120, 15856]); %How can i do this by algorithm over trial and error?
% Edge detection
I2_edge = edge(I2_binarised);
% Mask 4 borders
% - pad top + left then remove
I2_padTL = padarray(I2_edge,[1 1],1,'pre');
I2_padTLfilled = imfill(I2_padTL,'holes');
I2_padTLfilled = I2_padTLfilled(2:end,2:end);
% - pad top + right then remove
I2_padTR = padarray(padarray(I2_edge,[1 0],1,'pre'),[0 1],1,'post');
I2_padTRfilled = imfill(I2_padTR,'holes');
I2_padTRfilled = I2_padTRfilled(2:end,1:end-1);
% - pad bottom + left then remove
I2_padBL = padarray(padarray(I2_edge,[1 0],1,'post'),[0 1],1,'pre');
I2_padBLfilled = imfill(I2_padBL,'holes');
I2_padBLfilled = I2_padBLfilled(1:end-1,2:end);
% - pad bottom + right then remove
I2_padBR = padarray(I2_edge,[1 1],1,'post');
I2_padBRfilled = imfill(I2_padBR,'holes');
I2_padBRfilled = I2_padBRfilled(1:end-1,1:end-1);
% - put together sub-images
I2_filled = I2_padTLfilled | I2_padTRfilled | I2_padBLfilled | I2_padBRfilled;
% display segemented image
imshow(I2_filled),hold on;
% label shapes with color
[B, L, N]= bwboundaries(I2_filled);
for k=1:length(B)
boundary = B{k};
if k == 3 || k == 6
fill(boundary(:,2), boundary(:,1), 'b','LineWidth', 2);
else
fill(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
end
end

回答(1 个)

Shreeya
Shreeya 2023-11-17
Hello,
I understand that you want to classify the circular and longitudinal shapes in the images without the use of any machine/deep learning methods. You can follow the below mentioned approach to perform the task using image processing and computer vision methods:
  • Binarize the image using the “imbinarize” function. The document linked below talks about the usage of this function. https://www.mathworks.com/help/images/ref/imbinarize.html
  • Perform a flood fill operation such that the entire cell is highlighted, rather than only the borders. This is required for creating connected components for further processing. MATLAB’s “imfill” function can be used for this purpose. Refer to the documentation for more details: https://www.mathworks.com/help/images/ref/imfill.html
  • The next step would require noise removal to remove any unwanted pixel clusters in the image. There are several approaches for this. Refer to the documentation below to understand the usage and choose a filter which best suits the requirements. https://www.mathworks.com/help/images/noise-removal.html
  • After all the processing, you can apply the “regionprops” method on the image. This function returns the properties of connected components such as centroid, major axis length, minor axis length and eccentricity. Find the documentation below: https://www.mathworks.com/help/images/ref/regionprops.html
  • Having acquired the eccentricity, e, of the shape, it can be classified as a circle if e is tending to zero and a longitudinal shape if e is tending to one.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by