1

after convertig a NIfTI-file to an array using NiBabel, the array has three dimensions and the numbers look like this:

[-9.35506855e-42 -1.78675141e-35  1.18329136e-30 -1.58892995e-24
5.25227377e-24  1.11677966e-23 -2.41237451e-24 -1.51333104e-25
6.79829196e-30 -9.84047188e-36  1.23314265e-43 -0.00000000e+00]

How can I preprocess this array for machine-learning? When choosing only the exponent, most of the information gets lost when plotting the image, so maybe the base is also important?

Any help is appreciated.

MedLearn
  • 11
  • 1

1 Answers1

0

This will help you to convert a niftiimage to access as numpy array:

img = nib.load(example_filename)
data = img.get_fdata()
divinediu
  • 423
  • 1
  • 9
  • 33
  • Thank you. I already did that, but the numpy array looks like the one I mentioned above. Do you have any idea how to preprocess the array so I can use a machine learning algorithm (e.g. Keras)? – MedLearn Mar 06 '19 at 15:18
  • I'm learning too. I just figured the array thing out a couple of hours before you asked the question.. Do let me know if you do.. Is there chat here on stackoverflow? – divinediu Mar 07 '19 at 04:14
  • Here is what I came up with so far: – MedLearn Mar 07 '19 at 09:04
  • Here is what I came up with so far: By using np.asarray(data) you can convert the data into a numpy array and with np.uint8(data*255) the numbers in the array are looking way better + you can now view it as an image (from PIL import Image, data = data.transpose(2,0,1).reshape(-1,data.shape[1]), img = Image.fromarray(bildneu, 'L'), img.save('final.png'), img.show()). – MedLearn Mar 07 '19 at 09:11
  • Hello, Can you people help me with this post? https://stackoverflow.com/questions/56698087/how-to-remove-a-modality-from-mri-image-python-nibabel – The Great Jun 21 '19 at 07:10