Creating a nifti file from a numpy array

I have a numpy array that I would like to covert into a nifti file. Through the documentation it seems PyNIfTI used to do this with: image=NiftiImage(Array) However, PyNIfTI...

What is dimension order of numpy shape for image data?

I am using nibabel lib to load data from nii file. I read the document of the lib at http://nipy.org/nibabel/gettingstarted.html, and found that This information is available without the need to...

Change data type in Numpy and Nibabel

I'm trying to convert numpy arrays into Nifti file format using Nibabel. Some of my Numpy arrays have dtype('<i8') when it should be dtype('uint8') when Nibabel calls for the data...

How to convert Nifti file to Numpy array?

I have 3D array in Nifti file (.ii.gz) and I want to save it as a 3D numpy array. I used Nibabel to convert Numpy to Nifti1. Can I do the opposite?

How to get images intensity matrix from Nifti images with Nibabel?

i'm new with NiBabel. I want to know how to get intensity matrix from a Nifti images with this library. I use the following script to get voxels: import nibabel as ni example_img =...

OSError: [Errno 24] Too many open files using Nibabel

I have a python3.6 program, using nibabel package to analyze medical images in NIFTI format. import glob import nibabel as nib health = [nib.load(pt) for pt in glob.glob(healthdir+'*.nii')] # len...

Install python package in docker file

In my docker file, I want to install med2image python package (https://github.com/FNNDSC/med2image). I use the following code: FROM ubuntu:16.04 RUN apt-get update && apt-get install -y...

How can I figure out channel number of a Nifti file in python?

I work on deep learning with medical images and use nibabel package for reading .nii files in python. My code is shown below. import numpy as np from pylab import * import nibabel as...

How to modify orientation of mgh/dicom/nifti file using nibabel

I have a hard time, figuring out a proper affine transformation for 3 different views i.e. coronal, axial and saggital, each having separate issues like below: 1: Axial color map get overlapped...

ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced

I have two 3D float arrays in numpy that represent two MR images of the same shape loaded with nibabel. I want to compute a mask that represents the region of the images where there is no zeros in...

ImageFileError: Cannot work out file type of ".nii"

When I try to load my .NII file as a 4D Niimg-like object (I've tried both nilearn and nibabel), I get the below error Error: ImageFileError: Cannot work out file type...

Loading a Nifti through Nibabel and using the shape function

I have a nifti file 1.nii.gz Now, i never dealt with nifti files. So, just opening it using this software i realized that a nii.gz is a sort of container that contains 3 arrays of 2d pictures. In...

How to extract labelled masks in PNG format correctly from an array?

I have the following file in Nifti format, which contains the masks, I have written the following code to extract the images inside as PNG images, the problem is that: This is a multiclass masks...

How to improve the segmentation of the Lungs without Deep Learning

My objective is to obtain the Logical OR of the ROI of the lungs along slices axis Per Voxel from a Lungs 3D CT-Scans using fast conventional approaches. I have tried to use different approaches,...

How to compute the volume of a single voxel of nifti medical image?

I have loaded a nifti image file using nibabel tool and I have played with some properties. But I don’t have idea how to compute the volume (in mm³) of a single voxel.

Correlation heatmap of many datasets

I am working with niftis (Neuroimaging format) looking at 3D volumes of the brain. I want to compare experiments with brain activity. Therefore I have about 20 experiment files in nifti...

Error while drawing animation of seaborn heatmap for 3D volume

Trying to visualize the cross-correlation between two volumes, img_3D, and mask_3D, using Seaborn heatmap, and animation from Matplotlib to visualize the 3D cross-correlation result as a...

Reorder Nifti file axes

I have some 3D nifti files of dimension (50, 100, 50). I would like to flip the the y and z axes so that the dimension will be (50, 50, 100). What is the best way to go about doing this and how...

Create nifti volume with nifti images that have different voxel size

I have a question about creating nifti volume for biomedical images I usually use nibabel in python to load and create 3D nifti volume, but I recently have a group of images with alter slice...

DICOM to Nifti metadata not transfering

I am trying to take a number of DICOM stacks and convert them to Nifti files. When I do the conversion and open the new Nifti file in a 3D viewer the volume is smashed together in the z direction....

How to get affine information from a DICOM file in python?

I have a folder with DICOM files inside (CT scan for example) and I need to extract affine information of the volume since I will produce a mask and need it later to align the volume and...

python: rayleigh fit (histogram)

I’m still approaching programming in python. For the first time i'm trying working with histograms and fit! In particular, i have a dataset and i made a histogram of it. At this point i should...

.nii.gz file to properly oriented grayscale image

I have been doing some deep learning, usually with normal image dataset like jpeg or png. Recently, I came across a dataset where I have been provided with test images as png/jpeg with ground...

How to resize a nifti (nii.gz medical image) file

I have some medical images of nii.gz format which are of different shapes. I want to resize all to the same shape inorder to feed to a deep learnig model, I tried using resample_img() of nibabel,...

Load 3D Niftii images and save all slices for axial, coronal, saggital?

I have some 3D Niftii datasets of brain MRI scans (FLAIR, T1, T2,..). The FLAIR scans for example are 144x512x512 with Voxel Size of 1.1, 0.5, 0.5 and I want to have 2D-slices from axial, coronal...

change voxel values in nifti image and save it

I am going to read a nifti image and change the values of the voxels and save the new nifti image similar to the main image but only different voxel values. In other words I want my labels in...

how to convert a nift folder to png images?

*library there is a mostly known library imported from NumPy and imageio import NumPy as np import os import nibabel as nib import imageio // method where I have I write code to convert a...

How to use tf.keras.utils.Sequence with model.fit() in Tensorflow 2?

I want to train a model with a custom generator class but model.fit() gives me this error: Traceback (most recent call last): File "C:/Users/benja/PycharmProjects/mri/modelTrainer.py",...

Sudden Tensorflow / Keras Google Colab dependency problems `AttributeError: module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__'`

I have running a machine learning model (Matterport's Mask R-CNN) in google colab for a couple of weeks. All of a sudden today I am unable to run any of my notebooks due to I think some kind of...

ImportError: Image transformations require SciPy. Install SciPy

I am using transfer learning for feature extraction of medical images through imagedatagenerator. I am using pillow version 2.8.0, images are one-channeled and of jpeg format. SciPy version 1.5.4...