Hi all,
my typical (raster) image consists of many lines that are changing their distance to the other lines. The data are extracted from a biological sample that shows a pattern.
I want to calculate for each point of the lines the distance to the closest other line. My idea is to take a small portion of the image around the target point, delete all (bright) pixels that are directly connected, and calculate the minimum of all the distances to the left-over (bright) pixels.
s0 = 20; (* half size of the sub-image *)
d0 = ImageData[img0];
a0 = ReplacePar ConstantArray[0, {2 s0 + 1, 2 s0 + 1}], {s0 + 1, s0 + 1} ->
1]; (* make an image with a white pixel in the center *)
pos1 = DeleteCases[
Position[d0,
1], _?(#[[1]] <= s0 || #[[2]] <= s0 || #[[1]] >=
Dimensions[d0][[1]] - s0 || #[[2]] >=
Dimensions[d0][[2]] - s0 &),
1]; (* extract bright pixels from original image *)
repl =
(imgsm1 = Take[d0, Sequence @@ Outer[Plus, #, {-s0, s0}]]; (*
Take sub-image from original image *)
imgsm2 = Subtract[imgsm1, GeodesicDilation[a0, imgsm1]]; (*
delete pixels connected to center pixel *)
(# ->
Min[Sqrt[
N@(Plus @@@ ((# - {s0 + 1, s0 + 1} & /@
Position[imgsm2, 1])^2))], 100]) (*
calculate min distance of all left-over pixles *)
) & /@ pos1;
d1 = ReplacePart[d0, repl];
img1 = Colorize[Image[d1/25], ColorFunction -> (Hue[1 - #] &),
ColorRules -> {0 -> Black}]
The original image and the result are here: 

The code works but is very slow. Does someone have an idea how to accelerate this?
Thanks!
Max