Code covered by the BSD License  

Highlights from
Fast Parsing of Line Segments in a BW Mask

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 3.96 KB File ID: #32863
image thumbnail

Fast Parsing of Line Segments in a BW Mask

by Jonathan Sullivan

 

12 Sep 2011

Quickly determines the portions of a line/curve that are inside and outside of a binary mask.

| Watch this File

File Information
Description

LINEINMASK determines portions of the line in and out of a mask

  [inX inY] = LINEINMASK(XS,YS,BW,XV,YV) computes a the segments of the
      line specified by verticies XV and YV that are inside the mask BW.
      Points XS and YS specify the limits (or pixel values) of the
      coordinates of the matrix BW.

  [inX inY] = LINEINMASK(BW,XV,YV) assumes XS=1:N and YS=1:M where
      [M,N]=SIZE(BW).

  [inX inY] = LINEINMASK(...,METHOD) Uses the given method to create the
      polygon from the mask.
          Inner | Outer | {Exact}

  [inX inY outX outY] = LINEINMASK(...) outputs the segments of the line
      both in and out of the mask.

  Example:
      I = imread('rice.png');
      level = graythresh(I);
      bw = im2bw(I,level);
      bw = bwareaopen(bw, 50);
      [a b] = size(bw);
      xv = b*rand(10,1);
      yv = a*rand(10,1);
      [inX inY outX outY] = lineinmask(bw,xv,yv,'exact');
      figure
      imagesc(bw)
      colormap(bone)
      hold on;
      h1 = plot(inX,inY,'r');
      h2 = plot(outX,outY,'b');
      legend([h1 h2],'Inside Mask','Outside Mask');

By J Sullivan, August 2011

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Curve intersections

MATLAB release MATLAB 7.12 (2011a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
polygon Jonathan Sullivan 12 Sep 2011 15:52:38
mask2poly Jonathan Sullivan 12 Sep 2011 15:52:38
poly2mask Jonathan Sullivan 12 Sep 2011 15:52:38
intersection Jonathan Sullivan 12 Sep 2011 15:52:38
fast Jonathan Sullivan 12 Sep 2011 15:52:38
parse Jonathan Sullivan 12 Sep 2011 15:52:38
curve Jonathan Sullivan 12 Sep 2011 15:52:38
line Jonathan Sullivan 12 Sep 2011 15:52:38
segments Jonathan Sullivan 12 Sep 2011 15:52:38

Contact us at files@mathworks.com