[Python] Invalid Argument Error During Image Normalization Process

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I've tried making my image variable a raw string, but no matter what, I still get an invalid argument error. I know my image paths are correct, and I know they use slashes but I thought os.path.join meant converting to a raw string wasn't necessary. At this point, I'm confused as to what to do.

    # Path to images root folder
    images_path = "ADNI1Complete 1Yr 1.5T"

    # Function to normalize an image
    def normalize_image(image_path):
    try:
    # Load image
    nifti_image = nib.load(image_path)
    image_data = nifti_image.get_fdata()

    # Normalize image
    img_min = image_data.min()
    img_max = image_data.max()
    normalized_image = (image_data - img_min) / (img_max - img_min)

    # Save normalized image
    nifti_image = nib.Nifti1Image(normalized_image, nifti_image.affine, nifti_image.header)
    nib.save(nifti_image, image_path)
    except Exception as e:
    print(f"Error processing {image_path}: {e}")


    # Normalize all the images
    for root, dirs, files in os.walk(images_path):
    for file in files:
    if file.endswith(".nii"):
    image_path = os.path.join(root, file)
    normalize_image(image_path)

    Continue reading...

Compartilhe esta Página