adamancer / stitch2d

A Python script used to stitch a two-dimensional grid of tiles into a mosaic
MIT License
26 stars 6 forks source link

How to Maintain Color with Array #2

Closed LungWizard closed 2 years ago

LungWizard commented 2 years ago

First, I would like to thank you for making this available, I have been using it for stitching the whole slide images our lab has been producing with wonderful results.

I recently upgraded from version 0.5 to version 1.0 and while I was updating the script I made I noticed that the correct color was not maintained when creating an array before saving. However, the correct color was maintained when saving the stitched image directly.

Unfortunately, I am not sure exactly how to troubleshoot the issue and I was wondering if someone might be able to provide some advice. I will attempt to upload my testing script as well as some “demo” images so someone can try to recreate what I am saying.

TestFiles.zip

adamancer commented 2 years ago

Glad you've found it useful! The reason the two images are different is that opencv, which is what the script uses to read and align the images, orders the color channels as BGR, not RGB. If you reverse the order of the color channels, it will display as expected:

X_arr = X_arr[...,::-1]

I'll add that to the docs and think about adding an option to return the stitched array in a particular order.

LungWizard commented 2 years ago

Thank you so much! I am not sure why I had not considered that previously as I have run into a similar issue when working with other images in python.