Divide an image using just 2 pixel locations

2 views (last 30 days)
Hi, I want to be able to iteratively divide input images into 2 regions with a line formed from 2 input 'cut points'. I was thinking of looking for where this line crossed the image domain boundaries (1200X1600 pixels). Depending on the slope of the line (which we will not know in advance, since we do not know the 'cut points' in advance), I will have a 3-sided or a 4-sided polygon. Then I create a mask using the (ROI-based) poly2mask function.
Would there be a quicker way to do it?
Thanks! Greg

Answers (3)

Image Analyst
Image Analyst on 2 Oct 2013
An image has to be rectangular. What is your line slants across your image at an angle? What then? Do you want two sub images extracted using the bounding box of the quadrilateral? Or do you simply want two binary images, at the full original image resolution that map out where the two regions are? Please explain in much, much more detail what form you want the output image(s) to take on.
  1 Comment
Image Analyst
Image Analyst on 2 Oct 2013
Responding to Gregory's "Answer" below (which should have been a "comment" here):
There is no built-in function that will take a line segment with two endpoints in the image, then extend the line segment to the edges of the image, then give you two binary images out, one representing the left half and one representing the right half. That's just too specialized. You can easily do it in a few lines, and I guess you've already done that.

Sign in to comment.


Gregory
Gregory on 2 Oct 2013
Hi Image Analyst, Thanks for your answer! Inputs are a standard jpg image (1200X1600 pixels) and 2 pixel locations. A straight line between the 2 given pixel locations describes the boundary in the image domain, separating a region of interest (containing objects) and a region of no interest (also containing objects)
The line will inevitably slant across the image at an angle. For final output, I really need just 1 binary image which corresponds to the larger region in the original image (larger will always be the region of interest). I have code to accomplish this, which is based on finding the points which describe the vertices of the triangle or quadrilateral (the algorithm determines how many sides there are) of the smaller region. I just wondered if there was a more elegant way, or perhaps some built in functionality in the image processing toolbox to accomplish the task.
Cheers

Gregory
Gregory on 2 Oct 2013
Hi again ImageAnalyst, I played around with your code elsewhere on mathworks using imline to 'burn' in a line on an image. I then used bwlabel and regionprops to isolate the largest area. Thanks!
  1 Comment
Image Analyst
Image Analyst on 3 Oct 2013
If we're done with this question then mark my answer (not yours) as "Accepted" - thanks.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!