Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Working with Edge function in MATLAB

  1. Mar 7, 2017 #1


    User Avatar
    Gold Member

    Hi PF!

    Attached is an image I generated using the edge function in MATLAB (except the arrows, obviously). I would like to extract just the coordinates of the pixels from the bottom curve, which I've pointed at with arrows, and only in the domain between the red lines.

    Does anyone know how to do this?

    Thanks so much!

    Attached Files:

  2. jcsd
  3. Mar 7, 2017 #2


    User Avatar
    Gold Member

  4. Mar 10, 2017 #3


    User Avatar
    Gold Member

    Thanks, that was great as far as identifying the region I'm interested in! Now instead of a binary matrix spanning the entire image I have a new matrix of smaller dimensions, given by the red box in the attached image. Since this image has only 1's and 0's, and since I want the bottom line in the box that the arrows point to, I was thinking all I really need is the index (row and column position) of the "bottom" 1 (since 1's denote a white pixel) in for each row. Do you know of a simple way to ask MATLAB for this info?
  5. Mar 11, 2017 #4


    User Avatar
    Gold Member

    I believe it does more than "identifying the region"-- as you hover over the line of interest you get x,y information for each pixel of interest. Manually, you could have your result in maybe 30 min.

    It was not clear in your OP that automation was your intent or generalization for that matter. But not a problem. A couple issues, though.

    Clutter removal. The red box you identify has distracting information (part of your "close valve 2 knob", etc.) You could make a smaller box to get past that, but for future images, you must deal with the possibility of image artifacts appearing randomly in your box.

    Discontinuities in your "line of interest". I count what looks like at least 3 discontinuities. What constitutes an image-artifact discontinuity vs an actual real "notch" occurring in something that is presumably smooth, is up to you to define and manage.

    Concave/Convex (complex line). How nonlinear of an edge to you need to handle?

    Search Orientation. You can create something in MATLAB to handle this "horizontal", "bottom-first-encounter" case fairly simply (advised below), but to make it work in a more general manner (horizontal top-first, or vertical left/right first case) is going to require more consideration.

    This specific problem (hoizontal, bottom-first, no concavities, potential discontinuities, no clutter) lends itself to a search beginning at, say, the leftmost column (c0) and bottommost row (r0) of the rectangle. You can come up with a simple inner-outer loop structure: advancing over all columns (c0 to cn) in the outer loop, and for each column, increment the row elements (from r0 to rn) testing for the first occurrence of a "1" in the inner loop. Store your detection points in a suitable array.

    As far as the discontinuities are concerned, you can post-process your result to smooth the result based on a smoothing algorithm of your design. The point being: isolate this process from the search process.
  6. Mar 12, 2017 #5


    User Avatar
    Gold Member

    Thanks a lot! I really appreciate your help! Makes my life a lot easier!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Working with Edge function in MATLAB
  1. Matlab not working (Replies: 2)

  2. Matlab functions (Replies: 0)

  3. Matlab functions (Replies: 0)

  4. MATLAB function (Replies: 1)