From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stitch 2D Data

Solved!
Go to solution

Attached a vi containing 3 datasets that needs to be stitched together.

I mean, there is a certain, unknown overlap, between end of 1st & start of 2nd and between end of 2nd & start of 3th.

In the graph it’s clear that overlap 2/3 longer is than 1/2.

 

Array “Shift” tell us the X&Y shift to apply to the datasets so that they indeed overlap, check the graph.

I got these numbers by visually checking the overlap regions so that peaks & valleys over there maps while adjusting both X and Y values.

 

Anyone knows an algorithm to get these values automatically??

Thanks for your inputs… …

0 Kudos
Message 1 of 8
(2,617 Views)

They only overlap if the rotation is 30 degrees. Is this a known constant or does the rotation also need to be optimized?

0 Kudos
Message 2 of 8
(2,589 Views)
Solution
Accepted by topic author Alain_S

To simplify the analysis, we need to make certain assumptions, for example if we can assume that the point density is similar between all the traces (and they probably are!), we could do something as follows. It seems to get the same shifts as you automatically (within ~0.5). In the most general case, this is a hard problem, though.

I am sure there are many other ways to do all that.

 

Note that things simplify dramatically when using complex datatypes. No subVI needed for shifting and rotating. The first loop just applies the 30 degree rotation.

 

 

ShisftAndStitch.png

Message 3 of 8
(2,577 Views)

As a quick followup, here's a graph for the "mean r" difference after shifting as a function of overlap. The min is the optimal overlap and the mean of the point differences is the optimal xy shift.

 

ShiftAndStitchBestOverlap.png

 

If the data points are not roughly equally spaced along the each of the three arcs, you could probably fit each to a low order polynomial (or other suitable function), then generate a set of closely spaced points for each segment where the points are sorted and have equal distance steps along each arc.

 

What is the typical noise in the data?

0 Kudos
Message 4 of 8
(2,569 Views)

Thanks Altenbach, works like a charm!

No need to optimize the rotation, it’s always 30 degrees.

Processing the full data through your code returns the expected circle.

 

0 Kudos
Message 5 of 8
(2,550 Views)

I am glad it works, made it all up from scratch :).

 

If it really is a circle, you might be able to use "fitting on a sphere" (works for circles if you keep z=0), then align the centers. There even might be a global solution that forces all r to be equal, but that would need to be written first. 😄

0 Kudos
Message 6 of 8
(2,536 Views)

@altenbach wrote:

 

If it really is a circle, you might be able to use "fitting on a sphere" (works for circles if you keep z=0), then align the centers. 


Nah, too much noise. (It would work for noise-free data, even if there are gaps or no overlaps at all! :D)

 

In fact, that's the first thing I tried yesterday, then decided it's probably not a circle. 😄

 

In your case, the second set results in a larger radius (200+ larger!), causing gross misalignment. I still think that entire things could be rewritten to globally force a single radius, but unique center for each trace.  Here's a discussion of the current algorithm for fitting on a sphere.

 

Basically, we would have N traces, N midpoints, and a single radius. Somebody could investigate (not me at the moment ;)).

 

ShiftAndStitchCircle.png

 

 

As you can see below, it works perfectly for noise-free simulated data:

 

ShiftAndStitchCircleNoNoise.png

 

 

Message 7 of 8
(2,532 Views)

I too started from matching the segments on the theoretical perfect circle since I knew it was a circle, at least it should be.

But a perfect circle exist on black board and drawing paper, in real world … … … can be a bit un-circle.

Segment 2 has a “flat part” in the middle returning that way larger radius.

 

So I tried to use the peaks & valleys (what you call noise I suppose) as beacons to match the segments. Some kind of cross correlation but then in 2D. Unfortunately, not being a mathematician, I don’t know how to implement this, thus started this thread!

0 Kudos
Message 8 of 8
(2,516 Views)