MathOnco / valis

Virtual Alignment of pathoLogy Image Series
https://valis.readthedocs.io/en/latest/
MIT License
119 stars 29 forks source link

IndexError: list index out of range #138

Closed KOBE24DUNK closed 2 months ago

KOBE24DUNK commented 2 months ago
from valis import registration,valtils
slide_src_dir="/data/Multiplex/valis/examples/example_datasets/ihc"
results_dst_dir="/data/Multiplex/results_images"
merged_slide_dst_f = "/data/Multiplex/merged/merged_slides.ome.tiff"  # Where to save merged slide
registrar = registration.Valis(slide_src_dir, results_dst_dir)
rigid_registrar, non_rigid_registrar, error_df = registrar.register()
def cnames_from_filename(src_f):
    """Get channel names from file name
    Note that the DAPI channel is not part of the filename
    but is always the first channel.
    """
    f = valtils.get_name(src_f)
    return ["DAPI"] + f.split(" ")[1:4]

channel_name_dict = {f:cnames_from_filename(f) for f in registrar.original_img_list}

merged_img, channel_names, ome_xml = \
    registrar.warp_and_merge_slides(merged_slide_dst_f,
                                    #pyramid=False,
                                    channel_name_dict=None,
                                    drop_duplicates=False)

registration.kill_jvm() # Kill the JVM

==== Measuring error

Measuring error: 100%|██████████| 5/5 [00:00<00:00, 7.58image/s] merging DAPI from ihc_2 merging DAPI from ihc_4 merging DAPI from ihc_3 merging DAPI from ihc_5 merging DAPI from ihc_1 Traceback (most recent call last): File "/data/Multiplex/merge.py", line 30, in registrar.warp_and_merge_slides(merged_slide_dst_f, File "/usr/local/src/valis/valtils.py", line 35, in wrapper return f(*args, **kwargs) File "/usr/local/src/valis/registration.py", line 4789, in warp_and_merge_slides ome_xml_obj = slide_io.create_ome_xml(out_xyczt, bf_dtype, is_rgb=False, File "/usr/local/src/valis/slide_io.py", line 3114, in create_ome_xml updated_channel_names = check_channel_names(channel_names, is_rgb, nc=c) File "/usr/local/src/valis/slide_io.py", line 3040, in check_channel_names updated_channel_names = [channel_names[i] if File "/usr/local/src/valis/slide_io.py", line 3041, in (channel_names[i] is not None and channel_names[i] != "None") IndexError: list index out of range

Is there any suggestion for this issue? Many thanks!

KOBE24DUNK commented 2 months ago

This even occurs after I output the ome.tiff file from Zeiss (ZEN 3.10), which was then splitted by channel into several single-channel ome.tiff files.

cdgatenbee commented 2 months ago

Hi @KOBE24DUNK, Based on your code, it looks like you are using the example brightfield IHC dataset, but with the code for merging immunofluorescence images. The problem is that this code will try to merge RGB images, which isn't what it is designed to do. If you do want to merge brighfield RGB images, let me know and I can probably put something together. However, if you would like to test aligning and merging immunofluorescence images (such as CyCIF), please use the code above (valis/examples/register_and_merge_cycif.py), but with the example dataset located in valis/examples/example_datasets/cycif/. If you would like to test aligning brightfield images, please use the example code in valis/examples/register_ihc.py, with the IHC dataset you are currently using (valis/examples/example_datasets/ihc/).

Best, -Chandler

KOBE24DUNK commented 2 months ago

Hi @KOBE24DUNK, Based on your code, it looks like you are using the example brightfield IHC dataset, but with the code for merging immunofluorescence images. The problem is that this code will try to merge RGB images, which isn't what it is designed to do. If you do want to merge brighfield RGB images, let me know and I can probably put something together. However, if you would like to test aligning and merging immunofluorescence images (such as CyCIF), please use the code above (valis/examples/register_and_merge_cycif.py), but with the example dataset located in valis/examples/example_datasets/cycif/. If you would like to test aligning brightfield images, please use the example code in valis/examples/register_ihc.py, with the IHC dataset you are currently using (valis/examples/example_datasets/ihc/).

Best, -Chandler

Hi Chandler, Thanks a lot for your quick and kind reply. You are exactly right, and I do think CyCIF is my answer.

When I ran this pipeline via Docker (Valis-WSI 1.1.0) using my own ome.tiff files, it reported similar error like in #101 : "/usr/local/src/valis/valtils.py:24: UserWarning: unable to call VipsForeignLoadTiffFile tiff2vips: no SUBIFD tag".

======= An update: the Valis-WSI v1.1.0 is running smoothly in python 3.10 (in windows) without error, after installing the libvips. I guess that issue might be from the Docker image?

Thanks a lot for your so great software! Kobe24dunk

cdgatenbee commented 2 months ago

Hi @KOBE24DUNK, Glad you were able to get this resolved :) I still need to see if I can figure out what is going on with the Docker container (a related but separate issue), but I'll go ahead and close this issue.

Best, -Chandler

KOBE24DUNK commented 2 months ago

Hi @KOBE24DUNK, Glad you were able to get this resolved :) I still need to see if I can figure out what is going on with the Docker container (a related but separate issue), but I'll go ahead and close this issue.

Best, -Chandler

Thank you Chandler!

I can't help but express my gratitude and praise for your tool over and over again. It really works and is so helpful to my work! I think it will be probably a not rare requirement for some users to merge brighfield RGB image. Therefore, if you could add it in, I think it will be super nice!! ;)

Now I'm testing color overlapping in merged images. The next thing for me is to do segmentation based on the overlapped colors (I'm first trying Qupath as you recommended). I'll also appreciate it if you have any suggestions on this. :)

Thank you so much for your time and best wishes, Kobe24dunk