Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer
How simple. Thanks! – Libor Dec 26 '12 at 17:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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