I've got some image data that I've binarized. The image contains two curves, from which I'd like to compute the distance between (eventually computing an average radius for each point in the picture). I've done the computation, but it's done in C programmer style, and fairly ugly
data = ImageData[ b ] ;
{h, w} = Dimensions[data] ;
min = Table[0, {w}] ;
max = Table[0, {w}] ;
averageRadiusList = {} ;
scale = 0.1 / w ;
For [ column = 1, column < w + 1, column++,
For [ row = 1, row < h/2, row++,
If [
data[[row, column]] != 1,
min[[column]] = row ; Break
]
]
For [ row = h, row > h/2, row--,
If [
data[[row, column]] != 1,
max[[column]] = row ; Break
]
]
If [ min[[column]] != 0 && max[[column]] != 0,
AppendTo[
averageRadiusList, {column * scale,
scale * (max[[column]] - min[[column]])/2} ]
]
]
I was wondering if there's a more natural "Mathematica way" of doing things ... something that is presumably more elegant, efficient, compact, and more general?
Internal`Bag
is an undocumented function. You can find some information plus links to other sources in this question $\endgroup$