How can I fit a perfect square onto a ndarray matrix containing the edges of a fuzzy image of an imperfect square?

Viewed 67

Context: Microscopy.

I'm trying to stitch together small images (can refer to as sub-images or tiles) of a fuzzy grid to make a larger "mosaic" or "atlas" of the overall grid, such that these sub-images are lined up perfectly. The orientation is random overall, but consistent from tile to tile, and the four sides of a tile typically cut through several squares in the grid. I've used scikit-image to get the edges of each square separately as an Nx2 matrix (ndarray). What I think would be great is if I could fit a proper square (I do mean the kind with four sides and four right angles -- not a number multiplied by itself in case that's unclear) over each edge/silhouette of a square (I do have unrelated edges detected that pick up noise so need to get rid of those), but a) not sure how to do that and b) the squares themselves have noise--for example a piece of sample or other contaminant falling right on the edge of a square distorts the shape a bit. Image for Context

In the images above, I'm showing one such sub-image/tile (I have others which line up as neighbors to this, with slight (~1%) overlap. I figure if I have the geometric centers of all of the squares, I'll have no trouble finding the correct dimensions for creating the larger mosaic by average distance between neighboring squares in the grid is consistent. Please feel free to berate me mercilessly if I'm going about this poorly, or ask any follow-up questions if I failed to mention anything relevant.

Also maybe worth mentioning: The script I'm attempting to write needs to do this in an automated, fast (no human interaction) way behind-the-scenes, and for other grid images not just the one you see here, and that's important because other images will likely be fuzzier, as this is what's called a "bare" grid, but others will have "nanowires" (imagine this but the black part is almost furry/hairy).

Thanks in advance!!

0 Answers
Related