labsyspharm / ashlar

ASHLAR: Alignment by Simultaneous Harmonization of Layer/Adjacency Registration
https://labsyspharm.github.io/ashlar/
MIT License
124 stars 42 forks source link

Getting grid like pattern after image stitch many tiff files. #166

Open kuldeep203 opened 1 year ago

kuldeep203 commented 1 year ago

I have many microscope images. i have stitched all the images but getting line between the two images and one image overlap with other due to which my stitched images seems to be blured. i am attaching the image for your reference. microscope can you suggest me what i am missing. thanks in advance for helping.

jmuhlich commented 1 year ago

I think you need the --flip-y option which flips the tiles before stitching.

kuldeep203 commented 1 year ago

I am again getting the same results as previous one. i am attaching my code.

from ashlar import fileseries, thumbnail, reg
import numpy as np

from tifffile import imread, imwrite, TiffFile

readers = []
for i in range(3):
    readers.append(fileseries.FileSeriesReader(
        '/home/kuldeep/Downloads/Inferencing_with_Button/Input/',
        pattern='image_{series:3}.jpg',
        overlap=0.1,
        width=11,
        height=1,
        layout='snake',
        direction='horizontal', )
    )
print(len(readers))
aligner0 = reg.EdgeAligner(readers[0], channel=0, filter_sigma=15, verbose=True)
aligner0.run()

mosaic_args = {}
mosaic_args['verbose'] = True
mosaic_args['flip_mosaic_y'] = True
aligners = []
aligners.append(aligner0)

mosaics = []
for j in range(1, 2):
    aligners.append(
        reg.LayerAligner(readers[j], aligners[0], channel=j, filter_sigma=15, verbose=True)
    )
    aligners[j].run()
    print("aligners[0].mosaic_shape", aligners[0].mosaic_shape, aligners[0])
    mosaic = reg.Mosaic(
        aligners[j], aligners[0].mosaic_shape, None, **mosaic_args
    )
    mosaics.append(mosaic)
print(type(mosaic))
writer = reg.PyramidWriter(mosaics, r"/home/kuldeep/Downloads/Inferencing_with_Button/16*16.ome.tif",
                           verbose=True)
writer.run()
jmuhlich commented 1 year ago

Sorry, I meant --flip-y on the command line, not --flip-mosaic-y which is what you used there -- they are subtly different. To implement flip-y in your script, add these lines after constructing the readers list:

for r in readers:
  r.metadata._positions = r.metadata.positions * [-1, 1]

(note this assigns back to _positions not positions) You do not need to use mosaic_args['flip_mosaic_y'] = True at all.

However a bigger issue is that your example image appears to show a 17x17 grid but your FileSeriesReader arguments say width=11, height=1. It seems like you should actually be passing width=17, height=17 but perhaps there are other parts of your processing pipeline not shown here.

Would you mind sharing your images so I could take a closer look?

jmuhlich commented 1 year ago

One other tip: to paste multiple lines of code in a comment here, wrap it in three back-quotes on each end, not one. Single back-quotes are for highlighting an inline code statement and do not work for multiple lines. I edited your comment accordingly to make the code easier to read.

kuldeep203 commented 1 year ago

Thanks for the reply. Actually in the code it was 17*17. and it stitched well except grid like structure and second thing at stitched part pic is more blurred. i am attaching the picture for your reference. due to size limit not able to attach 17x17. so just attached 17x3. Input (17x3).zip Thanks for your continue support.