Image processing for Developers

Here you can discuss topics such as focus stacking, stitching and other techniques that relate to the processing of micrographs.
Post Reply
Message
Author
User avatar
Automizer
Posts: 9
Joined: Wed Apr 24, 2024 2:39 pm
Location: Switzerland

Image processing for Developers

#1 Post by Automizer » Sun May 12, 2024 10:20 pm

Hello ,
Currently i am developing a software for my microscopes. Therefore i was on the search for already existing focus stacking and image stitching API's (application programming interface). Luckily the python opencv library has some image stitching functions.
Today i found a nice python script that lets one do image stitching of microscope silde images.

Code: Select all

# import the necessary packages
from imutils import paths
import numpy as np
import argparse
import imutils
import cv2
import time
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", type=str, required=True,
	help="path to input directory of images to stitch")
ap.add_argument("-o", "--output", type=str, required=True,
	help="path to the output image")
ap.add_argument("-c", "--crop", type=int, default=0,
	help="whether to crop out largest rectangular region")
args = vars(ap.parse_args())
# grab the paths to the input images and initialize our images list
print("[INFO] loading images...")
imagePaths = sorted(list(paths.list_images(args["images"])))
images = []
# loop over the image paths, load each one, and add them to our
# images to stich list
for imagePath in imagePaths:
	image = cv2.imread(imagePath)
	images.append(image)
# initialize OpenCV's image sticher object and then perform the image
# stitching
print("[INFO] stitching images...")
stitcher = cv2.createStitcher(
	cv2.Stitcher_SCANS
) if imutils.is_cv3() else cv2.Stitcher_create(
	cv2.Stitcher_SCANS
)
# Reduce cropping by setting the compositing resolution to 'full resolution'
stitcher.setCompositingResol(-1)  # This sets stitching at full available resolution

(status, stitched) = stitcher.stitch(images)


# write the output stitched image to disk
cv2.imwrite(str(time.time())+args["output"], stitched)
# display the output stitched image to our screen
cv2.imshow("Stitched", stitched)
cv2.waitKey(0)

# usage: 
# python3 image_stitch.py -i public/media/tmp_image_stitching_images/ -o python_image_stitch.jpg
I tried `enblend` and unfortunately it does not work at all, giving me error messages like:

Code: Select all

enblend: warning: some images are redundant and will not be blended
enblend: note: usually this means that at least one of the images
enblend: note: does not belong to the set
enblend: info: loading next image: public/media/tmp_image_stitching_images/2024-05-13_00:08:33.png 1/1
enblend: warning: some images are redundant and will not be blended
enblend: note: usually this means that at least one of the images
enblend: note: does not belong to the set
enblend: info: loading next image: public/media/tmp_image_stitching_images/2024-05-13_00:08:34.png 1/1
enblend: warning: some images are redundant and will not be blended
enblend: note: usually this means that at least one of the images
enblend: note: does not belong to the set
enblend: info: writing final output
The images are of pretty good quality, none is like the other, exposure time and whitbalance both are set to manual and do not change for each image.

If anyone knows other API's i am glad if you are willing to share information about them, so maybe i can include it in my software :)

Anyways, here is the result:
Image

MichaelG.
Posts: 4048
Joined: Mon Apr 10, 2017 8:24 am
Location: North Wales

Re: Image processing for Developers

#2 Post by MichaelG. » Mon May 13, 2024 7:53 am

Very nice too !

MichaelG.
Too many 'projects'

Sure Squintsalot
Posts: 407
Joined: Mon May 16, 2022 3:44 pm

Re: Image processing for Developers

#3 Post by Sure Squintsalot » Tue May 14, 2024 12:01 am

That's really pretty good; I don't see any blending or stitching artifacts. Did you do any pre-stitching sharpening beforehand?

If you were to print this image at, say 300dpi, how large (X cm x Y cm) would your print be?

User avatar
Automizer
Posts: 9
Joined: Wed Apr 24, 2024 2:39 pm
Location: Switzerland

Re: Image processing for Developers

#4 Post by Automizer » Tue May 14, 2024 1:15 pm

i did not do any preprocessing of the images, i just made sure my camera settings are manual exposure and manual white balance
if DPI corresponds to pixels per inch you can do some math:

image width : 6000px ,
image width in inch: 6000/300 = 20
image width in mm: 20*25.4 = 508 mm = 50.8 cm
its almost a square image so the resulting print would be 50x50 cm or 20x20 inch

User avatar
Automizer
Posts: 9
Joined: Wed Apr 24, 2024 2:39 pm
Location: Switzerland

Re: Image processing for Developers

#5 Post by Automizer » Thu May 16, 2024 10:45 am

it seems unfortunately the python cv2 image stitcher is not very good. it did not work for this under part of a insect wing, so i had to create a custom script, i maybe will improve it here is a partial result
Image

Post Reply