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 nib
img_path=r"C:\\Users\\Umit Kilic\\Komodomyfiles\\umit\\myfile.nii"
nii_obj=nib.load(img_path)
img=nii_obj.get_fdata()
slice1=(img[60,:,:])
slice2=(img[:,80,:])
slice3=(img[:,:,60])
Then I select a slice and want to see in the figure.
figure()
imshow(slice2)
show()
The output of the above code snippet is this:
After that, I want to apply some operation such as:
slice2[:, :, 0] -= 123.68
slice2[:, :, 1] -= 116.779
slice2[:, :, 2] -= 103.939
But I can not. Cause when I run that code:
print(slice2.shape)
The output is
(121,121)
Normally there should be a third parameter that says the number of channels. There are two parameters. So, is my slice2 grayscale or RGB? How can I apply the operation that I mentioned above?