필터 지우기
필터 지우기

save line segments as binary mask

조회 수: 2 (최근 30일)
em
em 2014년 11월 15일
댓글: Guillaume 2014년 11월 15일
I have a skeleton stored as a set of line segments in the vector ln[x0,y0,x1,y1;...]. I can draw the skeleton on the image of size(r,c) by
im=zeros(r,c);
imshow(im)
line(ln(:,[1,3])',ln(:,[2,4])','color','w','LineWidth',1);
How can I save the skeleton displayed on the image as a binary mask, with pixels on lines being 1 and everything else being 0?

답변 (1개)

Guillaume
Guillaume 2014년 11월 15일
If you have the Computer vision toolbox, you can use insertshape to draw the lines straight into your image.
If not, you can use getframe to capture the content of the figure. Unfiortunately, my experience with getframe is that it doesn't work too well and doesn't return an image the same size as you started with.
Your final option is to write your own line drawing algorithm. Bresenham's algorithm is a simple and efficient one.
  댓글 수: 2
em
em 2014년 11월 15일
I need the mask matrix, and I have line segments already, so insertshape probably doesn't apply to my case.
getframe doesn't return the same image size, like you said.
Guillaume
Guillaume 2014년 11월 15일
I thought you only had the endpoints of your segments, in which case, insertshape is exactly what you want. You use it to draw the lines on an blank image.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by