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

Question about how to create low-resolution images from high-resolution images to run on UniRes #20

Open
jueqiw opened this issue Feb 26, 2023 · 1 comment

Comments

@jueqiw
Copy link

jueqiw commented Feb 26, 2023

Hi @brudfors ,

Thanks for this wonderful work! I am working on a project which solves a similar problem to UniRes and uses UniRes as a comparison method. However, I think there is something wrong with my code (in creating a low-resolution image or scaling before computing the SSIM metric) that I cannot achieve a similar result in your paper. I would really appreciate it if you could help me check whether anything I did was wrong.

I use the following code to generate a low-resolution image (4mm thick axial sliced) from a high-resolution one ($1\times1\times1 mm^3$):

import nibabel as nib
from nibabel.affines import rescale_affine
from nilearn.image import resample_img

img = nib.load("HR_mri.nii.gz")
new_zooms = np.array(img.header.get_zooms()) * [1, 1, 4]
new_shape = np.array(img.shape) // [1, 1, 4]
new_affine = rescale_affine(img.affine, img.shape, new_zooms, new_shape)
new_img = resample_img(
    img,
    target_affine=new_affine,
    target_shape=new_shape,
    interpolation="nearest",
)
near_new_img = resample_img(
    new_img,
    target_affine=img.affine,
    target_shape=img.affine,
    interpolation="nearest",
)
new_nib = nib.Nifti1Image(near_new_img.get_fdata(), img.affine)
nib.save(
    new_nib,
    "LR_mri.nii.gz",
)

Then I let UniRes run on the LR_mri.nii.gz to generate a high-resolution one. However, this is the result I get: (Input, UniRes)
image.
To draw this image, I cropped out an area ($160\times224\times160$) around the brain. I compute the SSIM value on this area after scaling both volumes into [0, 1]. The SSIM I computed is only around 0.48, which is lower than the value reported in the paper.

It also would be really helpful if you could show me the code for how you create low-resolution images.

Thank you for this wonderful project again!

Jueqi

@brudfors
Copy link
Owner

brudfors commented Apr 27, 2023

Hello @wendy-xiaozong ,

Appologies it took me some time to get back to you on this.

I have now added a demo notebook that shows how to apply the forward model of UniRes to generate a degrated, low-res image and perform reconstructions (i.e., the generation of high-res images):

https://github.com/brudfors/UniRes/blob/master/demos/demo_forward_model.ipynb

The notebook visualises results along the way and computes the SSIM between two types of reconstruction: trilinear resampling and super-resolution with the UniRes algorithm. In terms of SSIM, UniRes performs better than trilinear resampling.

I would look at the demo script for generating your low-res images, as this is the model that UniRes assumes for how a low-res image is generated (its 'generative model'). Keep in mind that you might want to set eo_scl = 0 and std_noise = 0 if you simply want to create low-res scans, without additional degradations.

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

2 participants