Auto fill an image based on edge line
이전 댓글 표시
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
Image Analyst
2012년 6월 30일
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.
채택된 답변
추가 답변 (1개)
Walter Roberson
2012년 6월 30일
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
Philip
2012년 6월 30일
Walter Roberson
2012년 6월 30일
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
2012년 6월 30일
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
2012년 6월 30일
Thanks, Anton -- I probably would have missed that possibility, as I have rarely used 4 connectivity.
카테고리
도움말 센터 및 File Exchange에서 Object Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!