Friday 15 February 2013

python - Iterating through a multidimensional array -


I have a 3D oval array, I want to iterate. If this is important, this is the .nii file type (the file used to store MRI brain data) and I use the nip module to load these images, which can be used to image processing again to numpy Can be handled as arrays. I want to take and go through Voxal and can only include Wooclal, whose values ​​are

  Import import neipe numpy img = nipy.load_image ('image.nii.gz') img_manip = img.get_data () Results = numpy.zeros (size = Img_manip .shape, dtype = img_manip.dtype): For the row in the matrix: For items in the row: If the item is   

This celebration is meant to work, but it is very slow, as it is still going on. I'm just thinking, is this the right way to do it? Should I use np.empty instead? I am not sure that I am beautiful Nobul on the dragon right now. Edit: Just a FYI, the size of img_manip is something like (368, 170, 32) and data type float64

(Sorry, I do not know how to create See the code "Pythonic"!)

I found a solution to my problem again! Haha, okay so this can not be right, but it works if someone has another great way to do this, please share! BTW It is not my solution, I actually asked the nip mail list and they gladly helped anyone to help me, they suggested that I took advantage of indexing system of Nambi. Then you will say:

  img_manip [img_manip> 2] = 0 result = 15000 * img_manip # This is optional, it just builds it in a good range for my purposes   

Now for those people, if you want to go back. Nii format, you can use the nifty package, see, you just

  new_img = nifti.NiftiImage (result)   

and your output Will save!

Edit: You can also use Nibel (and perhaps you should support / develop it since):

  new_img = nib.NiftiImage (Results )    

No comments:

Post a Comment