How can I link edges in crystal boundaries

3 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2021-1-2
编辑:Image Analyst 2021-1-2
So let's be clear. Do you want
  1. only the hollow outlines, but filled in (and not the solid blobs)
  2. only the solid blobs (not the outlines)
  3. 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?
Frederik Link
Frederik Link 2021-1-4
Dear Image Analyst,
i would like to get case 3).
Talking about a better segmentation algorithm, i used gradient based and Thresholding (otu's method) for segmentation. Below is the original image from which i am trying to extract the crystals (which are dark grey).

请先登录,再进行评论。

回答(1 个)

Sanchari
Sanchari 2024-5-21
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:
  1. 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.
  2. 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.
  3. 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:
  1. bwboundaries (MathWorks Documentation): https://www.mathworks.com/help/images/ref/bwboundaries.html?searchHighlight=bwboundaries&s_tid=srchtitle_support_results_1_bwboundaries
  2. imclose (MathWorks Documentation): https://www.mathworks.com/help/images/ref/imclose.html
  3. morphologicl operations (MathWorks Documentation): https://www.mathworks.com/help/images/morphological-dilation-and-erosion.html
  4. Detecting a cell using image segmentation (MathWorks Documentation Examples): https://www.mathworks.com/help/images/detecting-a-cell-using-image-segmentation.html
  5. Watershed segmentation (MathWorks Documentation): https://www.mathworks.com/help/images/ref/watershed.html
  6. 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
  7. 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!

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by