111.png
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.

 Réponse acceptée

rui gao
rui gao le 23 Sep 2019

0 votes

Maybe I can delete these segment lines in ArcGIS as the small segment lines can be identified as short length.

4 commentaires

darova
darova le 23 Sep 2019
Is it solution using MATLAB?
rui gao
rui gao le 23 Sep 2019
No. I have tried to use a small window to filter it, but it takes a long time, and I am not sure the whether the result can achieve my goal or not.
Initially, I thought it could be solved by MATLAB. But now, I reckon that ArcGIS can address it efficiently although there is some converting process which take some time.
I am working on this now. I will let you know if you are interested in this.
darova
darova le 23 Sep 2019
See if bwmorph can manage it
I1 = bwmorph(I,'spur',inf)
rui gao
rui gao le 24 Sep 2019
WeChat Image_20190923190308.png
Oops, for this kind of situation, the left red line should be remained, but it was deleted.
Maybe, we should add something ???

Connectez-vous pour commenter.

Plus de réponses (1)

darova
darova le 24 Sep 2019

1 vote

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
1Untitled.png
See the attached script

12 commentaires

rui gao
rui gao le 25 Sep 2019
Thanks for your suggestions. I will try it later, and let you know the result of mine.
rui gao
rui gao le 1 Oct 2019
I am sorry for the delayed response.
What you showed me is a really amazing work for me. Thanks.
How about the situation I attached here, "test_denoise.jpg"? I test it with the code you provided, and because of the complicated situations, this code cannot achieve the goal I want.
Additionally, I draw several lines in Paint (ShouldBe.png) to show what the final result looks like. (It's a kind of river network)
I am not familiar with this field, and I am trying to test some thoughts that you inspired me. Any further advice would be appreciated.
darova
darova le 2 Oct 2019
Please upload testnoise.jpg. There is something wrong with image
rui gao
rui gao le 3 Oct 2019
Sorry for that. This should work.
darova
darova le 3 Oct 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:
test_denoise6_fin.png
RED - original image
BLUE - image after imdilate()
CYAN - final image
rui gao
rui gao le 3 Oct 2019
Hi Darova,
Thanks for your reply, and it is an option. Compared with your result, the similar thing I did in Python is not acceptable.
But I was wondering whether we can do something focusing on the branch points. I attached the figure to show the main channel based on the result you got. For other thin red lines, we can reckon that they are noise. My untenable thought is:
  1. find all the branch/end points and delete a part of lines like you suggested before.
  2. find pairs of branch/end points again, and delete the line which is smaller than a threshold. Finally, we can get a skeleton, but not connected.
  3. set a threshold and connect those segment lines.
In step 2, we may delete a part of the main channel that I showed in "example.png", but most (all) part of small segment lines can be deleted.
After step 3, we may get a network like I showed in "example.png" (red arrows)
rui gao
rui gao le 4 Oct 2019
Oops~
Now, I thought these 3 steps below should work:
  1. find pairs of branch points, and delete the line between these two branch points if the distance is smaller than a threshold;
  2. using a loop to delete the line whose length is smaller than another threshold until it cannot find any satisfying endpoints;
  3. connect endpoints (I suppose I have finished this part).
Keep going ...
darova
darova le 4 Oct 2019
Maybe separate lines and remove smallest. Add or remove some lines manually
Fill small gaps between lines using imdilate() and bwmorph()('thin' operation
gif_animation.gif denoise_final.png
rui gao
rui gao le 4 Oct 2019
"example_3.png" is what I got now.
I am still working on gaining a better result.
rui gao
rui gao le 4 Oct 2019
Hi Darova, could you please send me the code for this processing?
  • Manual processing may not be accepted, because I need a tons of similar processing.
  • Some flaws are acceptable even there are two endpoints which should be connected
darova
darova le 4 Oct 2019
Sure, see attached script
Just pick some points to add lines (press Enter to finish)
rui gao
rui gao le 4 Oct 2019
Thank you so much.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by