Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image merge stitch #456

Open
alexlsa opened this issue Mar 6, 2024 · 2 comments
Open

Image merge stitch #456

alexlsa opened this issue Mar 6, 2024 · 2 comments

Comments

@alexlsa
Copy link

alexlsa commented Mar 6, 2024

Hi @jcupitt,

When doing stitch operation with merge function, there are some artifacts and misalignment. I tried with mosaic function but i could not achieve a good result

Our system consist of motorized stages (stepper)

How to improve stitched image result, should I increase overlap ratio or decrease ?

You can reach files and stitched img from this drive link

Here is the code :

import time
import pyvips

# overlap joins by this many pixels
H_OVERLAP = 144 
V_OVERLAP = 256 

# number of images in mosaic
ACROSS = 23
DOWN = 15

row = 0
 
def join_left_right(filenames):
    global row
    images = [pyvips.Image.new_from_file(filename) for filename in filenames]
    row = images[0]
    for image in images[1:]:
        row = row.merge(image, 'horizontal', H_OVERLAP - row.width, 0, mblend=50)
    #row = row.mosaic(image, "horizontal", 
    #                 0, 0, 
    #                 image.width * (1 - h_overlap), 0, mblend=100)
    return row

def join_top_bottom(rows):
    image = rows[0]
    for row in rows[1:]:
        image = image.merge(row, 'vertical', 0, V_OVERLAP - image.height, mblend=50)
	#image = image.mosaic(row, "vertical", 
    #                 0, 0, 
    #                 row.height * (1 - v_overlap), mblend=100)
        
    return image

rows = []
files = []
file = []
for i in range(DOWN):
    for j in range(ACROSS):
        file.append("image"+str(i) + "_" + str(j) + ".jpg")
    files.append(file)
    file = []

for y in range(0, DOWN):
    rows.append(join_left_right(files[y]))

image = join_top_bottom(rows)

image.write_to_file("stitched.tif", pyramid=True, tile=True,compression="jpeg")

Thank you from now

@jcupitt
Copy link
Member

jcupitt commented Mar 7, 2024

Hello @alexlsa,

I've not looked at your images, but the general advice is:

  • Camera focal plane: the sensor need to be co-planar with both your object, and with the plane of movement of the translation stage. This can be very hard to get exactly right :( The last time I did this I spent a long time driving the stage left/right/up/down and seeing how specks of dust on the object moved. Each time, you remove the camera, insert shims, and try again.

  • Lens distortion: pincushioning or barrelling needs to be less then a few pixels. There are various ways of measuring and correcting this, the simplest is to get a grating target and image that.

  • Translation stage errors: these are never exactly straight, and especially errors in the cutting of the screws can be significant. It depends how good your stage is. Again, it'd be worth trying to characterise your stage.

A simple experiment is to drive the stage to 100 positions, chosen to get a speck of dust positioned in a 10 x 10 grid filling the field of view of the camera. Find the pixel (x, y) position of the point in each frame and see if those points have a linear relationship, ie. are square-ish. If they are not, you have some uncorrected errors somewhere you need to fix.

@alexlsa
Copy link
Author

alexlsa commented Mar 11, 2024

Thank you @jcupitt ,

Sorry I'm late, I will check and try your recommendations to get a good result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants