# Filling one type of holes in a binary image

4 Ansichten (letzte 30 Tage)
Aktham Shoukry am 1 Feb. 2022
Kommentiert: Aktham Shoukry am 1 Feb. 2022
Hello, I am trying to obtain a mask from this image, such that the gray represents the walls and the nice plus-shaped channels should be the "holes" to be filled. There are other semi-rectangular holes that are basically grains that I do not want it filled. I tried imfill, imclose, bwareaopen, and combinations of these but still could not reach a satisfying solution. Can you please help me out?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Steve Eddins am 1 Feb. 2022
Based on your description of what you're trying to do, I ask the question: how are the semi-rectangular grains, which you want to keep, different from the channels, which you want to fill? Well, the channels are relatively thin in one dimension, either horizontally or vertically. So, perhaps a morphological erosion can be constructed that will keep a portion of each grain, while completely eliminating the channels.
First, a bit of preprocessing.
A = rgb2gray(rgb);
B = imcomplement(A);
imshow(B)
The channels seem to be approximately 10 pixels thick, while the grains around 50-by-50. Let's erode with a square structuring element with a size that's in between.
C = imerode(B,ones(25,25));
imshow(C)
Next, use morphological reconstruction to restore the original grain shapes.
D = imreconstruct(C,B);
imshow(D)
Finally, complement once more to make the grains dark again.
E = imcomplement(D);
imshow(E)
Is this what you are looking for? If you need to eliminate the partial grains along the image border, see imclearborder.
##### 9 Kommentare7 ältere Kommentare anzeigen7 ältere Kommentare ausblenden
Steve Eddins am 1 Feb. 2022
Thanks! And welcome to MATLAB Answers!
Aktham Shoukry am 1 Feb. 2022
Thank you again!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Image Segmentation finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by