Skip to content

Instantly share code, notes, and snippets.

@ericspod
Last active January 16, 2018 12:55
Show Gist options
  • Save ericspod/e5dd6bde055f0bf589a82230d687e00e to your computer and use it in GitHub Desktop.
Save ericspod/e5dd6bde055f0bf589a82230d687e00e to your computer and use it in GitHub Desktop.
Cropping an Image in Z and T dimensions
# Copy this function into the Eidolon console then you can call it as described below.
def cropImage(img,minz,maxz,mint,maxt):
'''Crop image `img' in the Z (minz to maxz) and T dimensions (mint to maxt).'''
arr=img.plugin.getImageObjectArray(img) # break the image down into spatial components and numpy array
arr['array']=arr['array'][:,:,minz:maxz,mint:maxt] # crop the numpy array
arr['pos']=img.images[img.getVolumeStacks()[0][minz]].position # set the position to the bottom of the new stack
newimg=img.plugin.createObjectFromArray(img.getName()+'Crop',**arr) # create new image object
mgr.addSceneObject(newimg) # add image to scene
return newimg # return image
# Use like this to crop first loaded image (which is stored in mgr.objs[0]):
newimg=cropImage(mgr.objs[0],2,5,0,10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment