Skip to content

Algorithms and ends mapping

Eugene Katrukha edited this page Jun 12, 2026 · 2 revisions

This page contains a bit of "in-depth" explanation/illustration
of algorithms in CurveMorph and ends mapping.
Let's start with a bit more straightforward

XY interpolation

For two ROIs, it re-samples them with the same number of equidistant
points along the normalized length line. The segment number is equal
to the length of the longer ROI in pixels.
Then it linearly interpolates XY coordinates of each resampled point.
The only thing the algorithms needs to know is ends to ends mapping
or corresponence.
Let's see an example, where "first" and "last" ends of ROIs are "aligned".
XY interpolation (first last)

This would be the output for any ends mapping settings:
"Closest" or "Always first/last".
But if the ends of one ROI are switched, then for "Always first/last"
the result will look like:

XY interpolation (closest)

While for the "Closest" it would be the same as in the first picture,
since "first" end of left ROI is the closest to the "last" end of the ROI on the right.

Shape morphing

This algorithm resamples ROI in the same manner.
But instead of XY coordinates interpolation, it interpolates angles
between resampled segments. That produces an interpolated shape,
but for a proper morph, one needs to account for the translation
between ROIs. So if we choose "Always first", the translation
will be applied between the coordinates of "first" and "first" ends:

Morphing first

Notice that the interpolated position of the "first" end forms a straight line.

Now, the result of "Always last" will look like this,
where the "last" end will be translated along the line:

Morphing last

And the "Closest" setting will use the mapping between the "first" end of ROI1
and the "last" end of ROI2, since the distance between them is the shortest:

Morphing closest

Practically, in my opinion, this mode is helpful
if you analyze something that appears to have a clamped or pinned end
and in 90% of cases, you can safely choose "Closest".

Using centroid

But if the clamped end is not observed, and both ends seem to move
independently, you can activate "Use centroid" option.
In this case, the translation will be calculated via the center of mass.

This is how it will look for the "Closest" option:
Morphing centroid closest

For this mode, "Closest" restores the mapping between closest ends.
But if using "Always first/last", we can force "inverse" mapping,
but there would be no difference between "Always first/last" options,
since in this case we do not use ends positions:

Morphing centroid first last

Clone this wiki locally