arrays - Loading Analyze 7.5 format images in python -


i'm doing work whereby have load manipulate ct images in format called analyze 7.5 file format.

part of manipulation - takes absolutely ages large images - loading raw binary data numpy array , reshaping correct dimensions. here example:

headshape = (512,512,245) # shape image should headdata = np.fromfile("analyze_ct_head.img", dtype=np.int16) # loads image flat array, 64225280 long. testing, large array of random numbers  head_shaped = np.zeros(shape=headshape) # array hold reshaped data  # set of loops problem ux in range(0, headshape[0]):     uy in range(0, headshape[1]):         uz in range(0, headshape[2]):             head_shaped[ux][uy][uz] = headdata[ux + headshape[0]*uy + (headshape[0]*headshape[1])*uz] # note weird indexing of flat array - pixel ordering have work 

i know numpy can reshaping of arrays quickly, can't figure out correct combination of transformations needed replicate effect of nested loops.

is there way replicate strange indexing combination of numpy.reshape/numpy.ravel etc?

you use reshape in combination swapaxes

headshape = (2,3,4)  headdata = rand(2*3*4)  head_shaped_short = headdata.reshape(headshape[::-1]).swapaxes(0,2) 

worked fine in case.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -