I have two distance maps that describe distances from blue segment and the red segment. I need to compute a single weight map that describes transition from blue segment to the red segment. The weight map should have values in the 0-1 range where 0 is one segment and 1 is the other one.

There are the distance maps with the respective segments highlighted:

enter image description here enter image description here

Having $d_{1}$ and $d_{2}$ the distances in the first and second image, I tried the following formula for computing the transition weight map:


where $d_{1max}$, $d_{2max}$ are maximum distances found in the first and second image. The numerator have range $<0, d_{1max}+d_{2max}>$ so the result is in $<0,1>$ range. This resulted in the following map:

enter image description here

However, there are sharp transitions between each segment and the map.

I have also tried multiplicative formula:

$$d=\bar{d_{1}}\cdot (1 - \bar{d_{2}})$$

where $\bar{d_{1}}, \bar{d_{2}}$ are distances normalized to $<0,1>$ range. This resulted in little better transition, but still suffers from the same problem:

enter image description here

Do you have any other ideas how to combine the distance maps to obtain transition map?


1 Answer 1


An obvious choice would be $\frac{d_1}{d_1+d_2+\epsilon }$, where $\epsilon$ is a small value to prevent division by zero.

Using your images, I get:

top = ColorNegate[Binarize[ImageApply[StandardDeviation, 
bottom = ColorNegate[Binarize[ImageApply[StandardDeviation, 
tDist = ImageData[DistanceTransform[top]];
bDist = ImageData[DistanceTransform[bottom]];

\[Epsilon] = 10^-10;
Image[tDist/(tDist + bDist + \[Epsilon])] // ImageAdjust

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.