Skip to content

Nifti.save_batch does not work as expected? #2033

@itruonghai

Description

@itruonghai

Dear author,

I try to recover the original image after going through the model. I have tried the following command (saver = NiftiSaver)

for val_data in val_loader:
            val_images, val_labels = val_data["image"], val_data["label"]
            # print(val_data)

            roi_size = (160, 160, 160)
            sw_batch_size = 4
            val_outputs = sliding_window_inference(val_images, roi_size, sw_batch_size, model)
            val_outputs = post_pred(val_outputs)
            
            val_labels = post_label(val_labels)
            value = compute_meandice(
            y_pred=val_outputs,
            y=val_labels,
            include_background=False,
            )
            metric_count += len(value)
            metric_sum += value.item() * len(value)
            saver.save_batch(val_outputs, val_data["image_meta_dict"])

Here is my transforms to

val_transforms = Compose(
            [
                LoadImaged(keys=["image", "label"]),
                AddChanneld(keys=["image", "label"]),
                Spacingd(
                    keys=["image", "label"],
                    pixdim=(0.76, 0.76, 2),
                    mode=("bilinear", "nearest"),
                ),
                RandSpatialCropd(
                    keys=["image", "label"],
                    roi_size=(200, 200, 64),
                    random_size=False,
                    random_center=False
                ),
                ToTensord(keys=["image", "label"]),
            ]
        )

As the result., the segmentation of (200,200,96) image is placing on the top left of the images (it does not recover as the original ones?). How can I solve this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions