6
$\begingroup$

enter image description here
I have an object (orange color object) and I know its centroid/center mass C. I want program to automatically find another point ( can be point 1, point 2, point 3 or point 4 and so on) such that the line connect point C and one of those points (so as green line in figure 2) must stay inside the object. Moreover, the green line length must be as long as possible, or at least 3/4 of the maximum length. The yellow point in figure bottom is not qualified because the violet line which connect it to the center mass C has a part which is not inside the object.

Any idea? I am doing it on Matlab (image processing)

$\endgroup$

migrated from stackoverflow.com Oct 25 '11 at 17:15

This question came from our site for professional and enthusiast programmers.

  • 4
    $\begingroup$ This seems too poorly constrained. For example, any orange pixel in the neighbourhood of C would meet your requirements for the example above. But more troubling: the center of mass need not be inside the object in the first place. $\endgroup$ – wim Oct 19 '11 at 0:50
  • 1
    $\begingroup$ Thankx for comment. I forget that the line length must be as long as possible. I edited my question. $\endgroup$ – John Oct 19 '11 at 0:52
  • 4
    $\begingroup$ So you are basically looking for the largest subspace that is convex? $\endgroup$ – Maurits Oct 19 '11 at 10:03
  • $\begingroup$ You will need to find a reliable way to distinguish between the object and the background in order to have a reproducible way of saying whether or not a line is staying inside the shape or not. One way to do this would be thresholding. $\endgroup$ – mpenkov Oct 19 '11 at 10:50
1
$\begingroup$

How about:

  • Separate the foreground from the background and keep a list of indices or a logical mask from the background
  • Convert the image to a (rho, theta) coordinate space, meaning that each pixel is encoded by the angle and length of vector from the origin to itself. You can scan along this vector to see if you encounter any background pixels. Have a look at the so-called Trace Transform

  • Alternatively you can stay in the original coordinate domain and use Bresenham's line algorithm to get all pixels belonging to a scan-line between a point and the center and then comparing them against the list of background labeled pixels.

Perhaps you can optimize a bit by starting on the edge of the foreground shape, working your way inward to the center, discarding any scan-line the moment it encounters a background labeled pixel.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy