Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preprocessing to ensure a similar image coverage #3

Open
NathanMolinier opened this issue May 28, 2024 · 0 comments
Open

Fix preprocessing to ensure a similar image coverage #3

NathanMolinier opened this issue May 28, 2024 · 0 comments

Comments

@NathanMolinier
Copy link
Collaborator

NathanMolinier commented May 28, 2024

Description

To limit image generation and maximize image translation, preprocessing steps are applied to the input data to ensure a common field of view (fov) between the image.

Note: Having different fov between contrasts is not exceptional, indeed due the different image protocols this is often the case

Example with the subject sub-balgrist01 from spinegeneric with the two contrasts T1w and T2w

Kapture 2024-05-28 at 13 22 00

Note: We can also notice a difference between the defacing boxes that were used for the two contrasts

To ensure a similar image coverage, arrays full of ones were generated for each original contrast, then after registration of the source contrast (here T2w) and the corresponding array full of ones to the destination contrast (here T1w) the two arrays full of ones (registered T2w and original T1w) were multiplied to create the intersection of the field of views. This intersection was then used to crop the two images. You can find a commented version of the code below:

code
# Set image orientation to RSP
out=subprocess.run(['sct_image',
                        '-i', in_path,
                        '-setorient', 'RSP'])

out=subprocess.run(['sct_image',
                        '-i', dest_path,
                        '-setorient', 'RSP'])

# Create a coverage mask with ones to find the shared fov
out=subprocess.run(['sct_create_mask',
                    '-i', in_path,
                    '-o', in_ones,
                    '-size', '500',
                    '-p', 'center'])

out=subprocess.run(['sct_create_mask',
                    '-i', dest_path,
                    '-o', dest_ones,
                    '-size', '500',
                    '-p', 'center'])

# Register input_image to destination_image
out=subprocess.run(['sct_register_multimodal',
                    '-i', in_path,
                    '-d', dest_path,
                    '-identity', '1', 
                    '-x', 'nn',
                    '-o', in_reg_path,
                    '-owarp', for_warp_path,
                    '-owarpinv', inv_warp_path])

# Bring coverage to destination space
out=subprocess.run(['sct_apply_transfo',
                    '-i', in_ones,
                    '-d', dest_path,
                    '-w', for_warp_path,
                    '-x', 'linear',
                    '-o', in_ones_reg])
        

# Multiply fovs to extract the shared fov between the 2 images
out=subprocess.run(['sct_maths',
                        '-i', dest_ones,
                        '-mul', in_ones_reg,
                        '-o', mask_path])


# Crop registered contrast
out=subprocess.run(['sct_crop_image',
                        '-i', in_reg_path,
                        '-m', mask_path,
                        '-o', input_crop_path])

# Crop dest contrast
out=subprocess.run(['sct_crop_image',
                        '-i', dest_path,
                        '-m', mask_path,
                        '-o', dest_crop_path])

But unfornately, sct_crop_image is not acting as expected and only maximum coordinate of the mask are kept.
Kapture 2024-05-28 at 13 43 54

To fix this, I will then multiply both images with the shared fov mask before cropping. To set all the non-shared pixel to zero.

Kapture 2024-05-28 at 17 15 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant