Stitching tweak walkthrough
Tweaking BakingTray and StitchIt for high stitching accuracy
Last updated
Tweaking BakingTray and StitchIt for high stitching accuracy
Last updated
This page is a walkthrough explaining how to improving stitching accuracy using BakingTray and StitchIt. It's description of a real session during which a mistake a was made that then needed correction.
We begin by stitching a section and looking at it:
The fact the red tile is above the green on one side and below on the other tells me there is a rotation problem.
The bidirectional scanning correction in ScanImage wasn’t set quite right. We can fix this post- hoc, although the correction is a bit hackish at the moment.
Indeed, upon zooming in to an area with obvious features the microns per pixel is very far off:
Indeed, microns per pixel is very far off:
What are the values?
We know it needs to be a larger number so the tiles end up overlapping more. Let’s try just one axis first:
Note that now IM
has a length of 2. When we run exploreChessboard
with IM
having a length of 2, we see the two images side by side:
And if we zoom in:
It looks much closer. They are offset because of the rotation we noted earlier, but we’ll fix that later. Let’s do the other axis too.
Closer. But’ll play with rotation before going back to mics per pixel. [NOTE: AT THIS POINT I WAS ASSUMING THAT THE GREEN FIBRE AT THE UPPER OVERLAP REGION IS PART OF THE RED BELOW IT. TURNS OUT LATER THAT IT WASN’T, BUT I DIDN’T REALISE THAT HERE]
To make this easier I will use affineMatGen that is in BakingTray
. I don’t have this function in my path on my desktop PC so I add it now:
Create a matrix with a small rotation and add it to IM(2).params:
Let’s see what that does. Stitch and explore as before. In the area we were looking at before, stuff is better:
But I really care about the sample edges right now, as rotations are really obvious there. Especially along the dorsal and ventral surfaces. I therefore re-explore with a lower threshold and look there.
We can do better. There is still rotation and it looks like we didn’t over-compensate. Let’s start fine-tweaking by comparing the above, nicer, version to a new version:
That wasn’t enough [NOT SHOWN] so repeat with more rotation:
That still wasn’t enough [NOT SHOWN] so repeat with more rotation:
Finally this is much better:
Certainly not perfect. Never is perfect. But very much better. Try another 0.05 degrees and compare what we just did to that:
This is again slightly better [NOT SHOWN]. We can leave the rotation for now and go back and explore the dataset more carefully, considering microns per pixel again.
The region we first concentrated on looks better than before the rotation correction:
But maybe microns per pixel in Y still needs tweaking? We need to pan around the sample to see what’s going on elsewhere. Can’t base everything on just one area. I see this, which I don’t like. This is miles out and can only be explained by stage motion errors, or the sample shifting, or a tilted focal plane, or the X value still being wrong. Tilted focal plane is unlikely to have such a big effect, though. [NOTE: THIS IS WHEN I STARTED TO QUESTION WHAT THAT FIBRE WAS AT THE START]
I also see this, which looks very much like tilted focal plane, but that’s an error along the other scan axis.
Let’s go with my X value being wrong. Let’s look around for other evidence of this.
Yes, it looks like that’s what’s happening. Note that I’m paying attention to regions near the middle of the tiles. Looking at the grid image quickly in Fiji for this microscope I see this:
I had to rotate tiles 90 degrees to stitch, so the left and right edges are the ones I care about. Note there is pincushion distortion there. The other two axes seem good. Let’s correct the grid image first. The X value was set based upon pixels near a corner, so we’ll not touch it yet. I also note that this grid image has a bidirectional scanning artefact too.
Let’s have a fiddle:
This looks like we’ve over-compensated, but we know that the grid image looks square.
So we need to tweak X. This is why what I should have done was fix the barrel distortion before doing anything else.
Iterate a bit until stuff looks good. We cycle through:
And now we see:
That stuff that was previously bad is now good. Pan around a bit. It all looks about as good as expected considering the tilt in the focal plane. This can only be corrected by tilting the stage. The only other option would be affine transformation in Z, but that would require very dense sampling in Z which we don’t typically do.
In this case we want to tweak an already acquired sample so we commit our changes to the recipe file:
It would also be a good idea to add these changes to the frameSizes settings file in BakingTray
so all future samples have these good parameters saved with them.