I have a 3D array. I want to change some pixel color of this 3D image. I want to change the pixel color for a given condition that is if my mask pixel for a fixed 3D co-ordinate is not equal 0 then I want to change my 3D array pixel to red color. Finally, I want to save this into a nifty format or .nii.gz format. I write some code this way, but this code gives me an error
x, y, z=volume.shape
for i in range (0, x):
for j in range (0, y):
for k in range (0, z):
if(detections[i,j,k] !=0 ):
volume[i ,j, k]=(255, 0, 0)
ni_img = nib.Nifti1Image(output, volume.affine)
nib.save(ni_img, '/content/SpineFinder-master/3d_path/output.nii.gz')
ValueError: setting an array element with a sequence volume[i, j, k]=(255, 0, 0)