graph.route_through_array, a route is "outside"
Hello, A contour is extracted from a greyscale image ("walls") where the background is set to 255. Several points near the contour are used to compute a path with graph.route_through_array: mincost = graph.route_through_array(walls ,p1,p2,fully_connected=True) One found path is not completely inside the array. When fully_connected=False is used all the paths are inside the chromosomes (i.e. they do not cross regions where grey level=255). How to get a minimal cost route "inside" a particle (<>255)? Thank you Jean-Patrick <https://lh6.googleusercontent.com/-YBi4a6avWfw/UJvgFAyisjI/AAAAAAAAA98/A5ADk...>
In addition to a snippet as Stéfan suggests, could you include a bit more information about the expected results vs. what you get? Also, what do you mean by this:
One found path is not completely inside the array.
Are the coordinates of the output path outside the shape of the array? (Less than zero or larger than the size along a given axis?) Or do you just mean that the path is not completely within the non-255 "foreground" region of the array? If the latter, then this is not a bug, and you need to understand better how the path-finding code works. The documentation for route_through_array states:
Simple example of how to use the MCP and MCP_Geometric classes. See the MCP and MCP_Geometric class documentation for explanation of the path-finding algorithm.
So read up on what the MCP class is actually doing. There you will find that it finds the minimum-cost path between the start and end points, weighted according to the value of the pixel. (There are important considerations with the geometric vs. non-geometric weighting that you'll also need to read about.) Given this, clearly a two-pixel long path through pixels with value 255 will be lower-cost than a 300-pixel path through pixels with value 1. Thus, 255-valued pixels don't pose an impenetrable barrier or anything, as you may perhaps be expecting for some reason. (Also note that this means zero-valued pixels may not behave as you imagine either.) The way to get true impenetrable barriers is to use floating-point images and set the "don't-go-here" pixels to numpy.inf. Even so, your example image seems a bit odd -- the "background" is dark on the image, but you say it's 255-valued? And are you just using the chromosomal staining intensity as the image to do the pathfinding on (after setting the background to 255)? This would mean the paths will try to avoid regions of high staining intensity, which seems odd. So perhaps you're using an inverted image? This is why you need to provide much more detail when asking questions. Zach On Nov 8, 2012, at 11:59 AM, jip wrote:
Hello,
A contour is extracted from a greyscale image ("walls") where the background is set to 255. Several points near the contour are used to compute a path with graph.route_through_array: mincost = graph.route_through_array(walls ,p1,p2,fully_connected=True)
One found path is not completely inside the array. When fully_connected=False is used all the paths are inside the chromosomes (i.e. they do not cross regions where grey level=255).
How to get a minimal cost route "inside" a particle (<>255)?
Thank you
Jean-Patrick
--
On Nov 8, 2012, at 1:56 PM, Zachary Pincus wrote:
Given this, clearly a two-pixel long path through pixels with value 255 will be lower-cost than a 300-pixel path through pixels with value 1.
Err, sorry, this is clearly in error. A two-pixel long path through pixels with value 255 will be lower-cost than a *600-pixel* path through pixels with value 1.
Le jeudi 8 novembre 2012 19:56:15 UTC+1, Zachary Pincus a écrit :
In addition to a snippet as Stéfan suggests, could you include a bit more information about the expected results vs. what you get?
Also, what do you mean by this:
One found path is not completely inside the array.
Are the coordinates of the output path outside the shape of the array? (Less than zero or larger than the size along a given axis?) Or do you just mean that the path is not completely within the non-255 "foreground" region of the array? I mean the path is not completely within the non 255 "foreground"
If the latter, then this is not a bug, and you need to understand better how the path-finding code works. The documentation for route_through_array states:
Simple example of how to use the MCP and MCP_Geometric classes. See the MCP and MCP_Geometric class documentation for explanation of the path-finding algorithm.
So read up on what the MCP class is actually doing. There you will find that it finds the minimum-cost path between the start and end points, weighted according to the value of the pixel. (There are important considerations with the geometric vs. non-geometric weighting that you'll also need to read about.)
Given this, clearly a two-pixel long path through pixels with value 255 will be lower-cost than a 300-pixel path through pixels with value 1. Thus, 255-valued pixels don't pose an impenetrable barrier or anything, as you may perhaps be expecting for some reason.
because of a naïve idea based on binary image ...
(Also note that this means zero-valued pixels may not behave as you imagine either.) The way to get true impenetrable barriers is to use floating-point images and set the "don't-go-here" pixels to numpy.inf.
Even so, your example image seems a bit odd -- the "background" is dark on the image, but you say it's 255-valued?
This is an error, I overlayed the path on the original image instead of the one with the background set to 255.
And are you just using the chromosomal staining intensity as the image to do the pathfinding on (after setting the background to 255)? This would mean the paths will try to avoid regions of high staining intensity,
Thats true, the staining is lower where the chromosomes are touching, than on the chromatids or on the bright centromeric regions.
which seems odd .
So perhaps you're using an inverted image?
this is a fluorescent staining with DAPI, tthe background is dark. This is why you need to provide much more detail when asking questions.
Zach Thanks a lot
JPat
On Nov 8, 2012, at 11:59 AM, jip wrote:
Hello,
A contour is extracted from a greyscale image ("walls") where the background is set to 255. Several points near the contour are used to compute a path with graph.route_through_array: mincost = graph.route_through_array(walls ,p1,p2,fully_connected=True)
One found path is not completely inside the array. When fully_connected=False is used all the paths are inside the chromosomes (i.e. they do not cross regions where grey level=255).
How to get a minimal cost route "inside" a particle (<>255)?
Thank you
Jean-Patrick
--
participants (4)
-
Jean-Patrick Pommier
-
jip
-
Stéfan van der Walt
-
Zachary Pincus