Auto fill an image based on edge line
Ältere Kommentare anzeigen
Is there a way to automatically fill an image (as though using the paint bucket tool in Photoshop) based on a line that runs from one side of the image to another?
For example, if I have the following image:
edge_win =
0 0 0 0 0
1 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 0 0 0 0
where the ones represent the line, is it possible to produce the following image:
filled_win =
2 2 2 2 2
1 1 2 2 2
0 0 1 1 1
0 0 0 0 0
0 0 0 0 0
The fill value can be any value other than zero or one. However, the original line (ones) may run either from left to right, or from top to bottom, so it may be difficult to do this using a loop...
Many thanks.
1 Kommentar
Image Analyst
am 30 Jun. 2012
This is ambiguous. I do have a Photoshop-like magic wand demo if you want it. But, for your example, do you want all connected zero regions to have a distinct label (if so, just call bwlabel(~edge_win, 4)) or do you want only the upper left zero region to be 2 and don't touch any other zero regions (leave them as zero as in your example)? You can do it either ways, but you need to clarify. If you want just one particular region changed, then there are several ways to do it (labeling, region growing) depending on what information you're going to start with. Let me know if you still want my 79 line magic_wand.m demo.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 30 Jun. 2012
filled_win = 1 + bwlabel( ~edge_win );
This would fill one side of the line with 2's and the other side with 3's, and the line itself would be 1's.
4 Kommentare
Philip
am 30 Jun. 2012
Walter Roberson
am 30 Jun. 2012
No, you didn't do anything wrong, I didn't think it through carefully enough. This approach is probably not going to work. It might work if you ran a simple dilation on ~edge_win and then did a bit of fix-up. There are probably better ways but they do not come to mind at the moment.
Anton Semechko
am 30 Jun. 2012
Actually the solution is much easier. You just have to use pixel connectivity of 4 instead of 8, which is used by default. So for example:
a=[0 0 0 0 0
1 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 0 0 0 0];
b=1+bwlabel(~a,4)
b =
2 2 2 2 2
1 1 2 2 2
3 3 1 1 1
3 3 3 3 3
3 3 3 3 3
Walter Roberson
am 30 Jun. 2012
Thanks, Anton -- I probably would have missed that possibility, as I have rarely used 4 connectivity.
Kategorien
Mehr zu Object Analysis 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!