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

How to use Nifti data for training and prediction #157

Open
skpathak opened this issue Dec 9, 2024 · 1 comment
Open

How to use Nifti data for training and prediction #157

skpathak opened this issue Dec 9, 2024 · 1 comment

Comments

@skpathak
Copy link

skpathak commented Dec 9, 2024

Thanks for the fantastic library!

I want to denoise micro-CT data of a tissue sample. The data is stored in Nifti format. I can convert it into a TIFF and use the code, but I can also directly read the Nifti file using nibabel and get the 3D array. Do you know how I can use the rest of the steps?

I appreciate any help you can provide.

Sudhir

@jdeschamps
Copy link
Member

Hi Sudhir,

If you use the example notebook, you can skip that step:

imgs = datagen.load_imgs_from_directory(directory = "data/", dims='ZYX')

and then do something along these lines:

your_array = nibabal(...) # or whatever you need to call to load it

# re-order dimensions to SZYXC
# You can use numpy.moveaxis (https://numpy.org/doc/stable/reference/generated/numpy.moveaxis.html)
# to change your dataset into ZYX, then to add the S and C singleton dimensions:
your_array = your_array[np.newaxis, ..., np.newaxis]

# generate patches
patch_shape = (32, 64, 64)
patches = datagen.generate_patches_from_list(your_array, shape=patch_shape) # if you have a list of images
patches = datagen.generate_patches(your_array, shape=patch_shape) # alternatively to the previous line

Please note that we are not maintaining n2v anymore, and are developing CAREamics, which allows you to pass an array directly, along with your axes order. So it is a bit simpler, and we will be happy to help if you open an issue there.

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