How to delete the branches?
Ältere Kommentare anzeigen

I have a matrix which just consist by 0 and 1, like the figure above (1 is black and 0 is white). It's kind of river, but there is some noise like the red arrows above.
Is there some ways to identify these small segment lines and delete these small segment lines?
Calculating the length (pixel) of these small segment lines is not necessary, but I am interested to know it.
Any suggestion will be appreciated.
Akzeptierte Antwort
Weitere Antworten (1)
darova
am 24 Sep. 2019
1 Stimme
I have an idea:
- Find pairs of branch/end points smaller than desired length
- Select circle area between points. Find biggest area in this circle (if there are) and remove it
- Place modificated circle area into original image

See the attached script
12 Kommentare
rui gao
am 25 Sep. 2019
rui gao
am 1 Okt. 2019
darova
am 2 Okt. 2019
Please upload testnoise.jpg. There is something wrong with image
rui gao
am 3 Okt. 2019
darova
am 3 Okt. 2019
What about this simple way?
clc,clear
I0 = imread('test_denoise.png');
I1 = imdilate(I0,ones(30)); % make lines thick
I2 = bwmorph(I1,'thin',100); % thin lines
I00 = 255*cat(3,I0,I0*0,I0*0);
I11 = 255*cat(3,I1*0,I1*0,I1);
I22 = 255*cat(3,I2*0,I2,I2*0);
I = I00 + I11 + I22;
imshow(I)
imwrite(I,'test_denoise11.png')
The code produces:

RED - original image
BLUE - image after imdilate()
CYAN - final image
rui gao
am 3 Okt. 2019
rui gao
am 4 Okt. 2019
darova
am 4 Okt. 2019
Maybe separate lines and remove smallest. Add or remove some lines manually
Fill small gaps between lines using imdilate() and bwmorph()('thin' operation

rui gao
am 4 Okt. 2019
rui gao
am 4 Okt. 2019
rui gao
am 4 Okt. 2019
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
