How can I link edges in crystal boundaries
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear all,
I am trying to determine the size of crystals from images. In order to determine the crystal sizes with the "bwboundaries" function, I applied prior to this step a few edge detection steps (e.g. canny) as well as some thresholding steps. The attached image shows the final image from which i would like to extract the crystal sizes with bwboundaries. Thereby the crystal contours are displayed in white and the background in black. The 'noholes" option in bwboundaries was chosen to erase any unwanted holes in the crystal-agglomerates. However, since some of the contours of some crystals are not closed, bwboundaries does not fill out the holes in the crystals and therefore the crystal is not detected. I wonder how to link the not connected edges together in order to detect their area as well? Dont worry about the images which are intercepting with the image boundary, they will be negelcted anyways.
Thank you very much for your help in advance!!!
10 comentarios
Image Analyst
el 2 de En. de 2021
Editada: Image Analyst
el 2 de En. de 2021
So let's be clear. Do you want
- only the hollow outlines, but filled in (and not the solid blobs)
- only the solid blobs (not the outlines)
- both the solid blobs plus the outline blobs (filled in)
??? Which case is it? Sounds like you want just case 1. Is that true? Or do you want case 3?
You can try bwconvhull() but I think you'd be better off with a better segmentation algorithm than trying to fix a bad one.
And what do you plan on doing with the blobs, once you have segmented out the blobs of your choice?
Respuestas (1)
Sanchari
el 21 de Mayo de 2024
Hello Frederik,
I understand that you’re trying to determine the size of crystals from an image where the crystal contours are displayed in white against a black background. However, some contours are not fully connected, which is causing issues with the ‘bwboundaries’ function in MATLAB when it tries to detect their area.
A possible solution could be to consider applying morphological operations such as ‘dilation’ followed by ‘erosion’ (also known as ‘closing’) to close the gaps in the contours. This process can help connect nearby edges and create a continuous boundary that can be detected by “bwboundaries”.
Here’s a sample code snippet in MATLAB:
%Assuming BW is your binary image as attached
BW = imread("crystals.jpeg");
se = strel('disk',3);
BW_closed = imclose(BW, se);
BW_dilated = imdilate(BW_closed, se);
BW_filled = imfill(BW_closed, 'holes');
imshow(BW_filled);
This code will perform a ‘closing’ operation on the image, which is a dilation followed by an erosion. The ‘disk’ structuring element with a radius of 3 pixels is used here, but you can adjust this based on the size of the gaps in your contours.
Output:
Do remember to consider the following:
- Parameter Tuning: The choice of structuring element size in morphological operations (strel) significantly affects the result. You might need to experiment with different sizes and shapes to find the best fit for your images.
- Image Quality: The effectiveness of these techniques can be influenced by the quality and resolution of your images. Preprocessing steps like noise reduction might be necessary.
- Object Separation: If dilating merges separate crystals, you might need more sophisticated segmentation techniques, such as watershed segmentation, to separate them properly.
Please refer to the following references to know further about:
- bwboundaries (MathWorks Documentation): https://www.mathworks.com/help/images/ref/bwboundaries.html?searchHighlight=bwboundaries&s_tid=srchtitle_support_results_1_bwboundaries
- imclose (MathWorks Documentation): https://www.mathworks.com/help/images/ref/imclose.html
- morphologicl operations (MathWorks Documentation): https://www.mathworks.com/help/images/morphological-dilation-and-erosion.html
- Detecting a cell using image segmentation (MathWorks Documentation Examples): https://www.mathworks.com/help/images/detecting-a-cell-using-image-segmentation.html
- Watershed segmentation (MathWorks Documentation): https://www.mathworks.com/help/images/ref/watershed.html
- Marker-controlled watershed segmentation: https://www.mathworks.com/help/images/marker-controlled-watershed-segmentation.html?searchHighlight=watershed%20segmentation&s_tid=srchtitle_support_results_1_watershed%2520segmentation
- Separate segmentation operations (ML Answer): https://www.mathworks.com/matlabcentral/answers/165022-when-working-with-an-image-and-filling-in-gaps-do-you-only-choose-one-imerode-imdilate-imopen-i?s_tid=answers_rc1-2_p2_MLT
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!