AllenCellModeling / aicsimageio

Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python
https://allencellmodeling.github.io/aicsimageio
Other
202 stars 51 forks source link

Data vs. Dims Dimensions Mismatch #565

Closed tejasthy closed 3 months ago

tejasthy commented 3 months ago

System and Software

Description

A clear description of the bug I am having trouble extracting data from a CZI file due to a mismatch in the dimensions of data and dims. ValueError: different number of dimensions on data and dims: 10 vs 9

` image = AICSImage(read_path) print('Image shape=', image.shape)

# Print the dimensions of the image
print(f"Image dimensions: {image.dims}")

data = image.get_image_data("CZYX", T=0)`

Image shape= (1, 2, 278, 640, 640) Image dimensions: <Dimensions [T: 1, C: 2, Z: 278, Y: 640, X: 640]>

Expected Behavior

What did you expect to happen instead? I expected to be able to extract the data from the image file and then split the two channels using a for loop into two separate tiff files.

Reproduction

A minimal example that exhibits the behavior.

from aicsimageio.writers import OmeTiffWriter

def Save_tiff_from_CZIFile(path,save_path):
    image = AICSImage(read_path)
    print("Image shape=", image.shape)

    # Print the dimensions of the image
    print(f"Image dimensions: {image.dims}")

# the following calls all throw mismatch errors
    data = image.get_image_data("CZYX", T=0)
    # image.data()
    # data = image.data
    # print(image.data)
    # print(image.xarray_data)

    # Loop through each channel and save it as a separate TIFF file
    for channel_index in range(image.shape[1]):  # data.shape[1] gives the number of channels
        channel_data = image[:, channel_index, :, :, :]  # Extract the channel data
        output_filename = f"channel_{channel_index + 1}.tiff"

        # Write the channel data to a TIFF file
        with OmeTiffWriter(output_filename) as writer:
            writer.save(channel_data)

    # Get an AICSImage object
    print(image.metadata)  # returns the metadata object for this file format (XML, JSON, etc.)
    print(image.channel_names)  # returns a list of string channel names found in the metadata
    print(image.physical_pixel_sizes.Z)  # returns the Z dimension pixel size as found in the metadata
    print(image.physical_pixel_sizes.Y)  # returns the Y dimension pixel size as found in the metadata
    print(image.physical_pixel_sizes.X)  # returns the X dimension pixel size as found in the metadata

base_filename = config['folder_path']
read_path = base_filename + config['img_name']

Save_tiff_from_CZIFile(read_path, base_filename)

Environment

Any additional information about your environment