yfukai / m2stitch

MIST-inspired microscope image stitching package
Other
63 stars 11 forks source link

Blending? #414

Open smith6jt-cop opened 11 months ago

smith6jt-cop commented 11 months ago

Hello! Thank you for your work here.

I was able to stitch my images with the example script, but there is line visible in the overlap. Is there something I can do to change this? stitched_image.zip Thanks!

yfukai commented 11 months ago

Hi @smith6jt-cop , thanks for your interest! Unfortunately the image merging is not implemented in the package, but I suspect those lines may be actually due to shading (nonuniform illumination). There are several packages (including ours ) for the shading correction, and it may be worth trying to perform some shading correction before stitching.

I found recently other researchers are trying to build a package for stitching. https://github.com/multiview-stitcher/multiview-stitcher There might appear functions for merging in the near future.

I hope this helps!

smith6jt-cop commented 11 months ago

That helps, thanks! I did correct with BaSiCpy, but ran all 17 z-planes at once rather than one z-plane at a time so maybe wasn't the best. I really liked being able to keep the data as a dask array between illumination correction and stitching. However, the best results I've seen so far for stitching come from the Gid/Collection Stitching in FIJI which is also a lot faster.

Thank you for the link; that looks promising!

yfukai commented 11 months ago

Thanks! For now the algorithm uses only a single core, and it is natural that Fiji implementation works faster. I have a will to implement faster stitching (and also blending), but now am prioritizing the other project considering the existence of other ongoing projects such as one I noted. For BaSiCPy, we're now implementing the parameter autotuning which may help more robust performance.

I hope I can make a tutorial colab or Jupyter notebook for standard shading-correction-and stitching workflow.

Anyway thanks for your interest!

jeffhsu3 commented 9 months ago

For blending I'm doing something like:

from stitching.blender import Blender
blender = Blender()
bsizes = [(img.shape[1], img.shape[0]) for img in ic_conv]
result_df["y_pos2"] = result_df["y_pos"] - result_df["y_pos"].min()
result_df["x_pos2"] = result_df["x_pos"] - result_df["x_pos"].min()
corners = result_df[['x_pos2', 'y_pos2']].values
masks = [255 * np.ones(img.shape[:-1], np.uint8) for img in ic_conv] 

print('Calculating seam mask')
finder = cv2.detail_DpSeamFinder("COLOR_GRAD")
ic_conv = [cv2.cvtColor(i, cv2.COLOR_GRAY2RGB) for i in img_list]
seam_mask = finder.find(ic_conv, corners, masks)

out, out_mask = blender.create_panorama(ic_conv, seam_mask, corners, bsizes)

Where ic_conv is the arrray of images in cv2.COLOR_GRAY2RGB