targetfilename = sys.argv[1] outputfilename = sys.argv[2] outputtargetfilename = sys.argv[3] useWhiten = True maskBeforeSmooth = True smoothMask = False greyBackground = True smoothAtlasAgain = True blackVentricles = True multicolorMask = False target = sitk.ReadImage(targetfilename) refImg = sitk.ReadImage(targetfilename) origRefImg = sitk.ReadImage(targetfilename) inflectionpoint = histFunctions.getInflectionPoint(target) mymask = ndreg3D.imgMakeMask(target, threshold=inflectionpoint) mymaskarray = sitk.GetArrayFromImage(mymask) refImg = ndreg3D.imgMask(refImg, mymask) # now go slice by slice to remove the ventricles from the mask mymaskarray = sitk.GetArrayFromImage(mymask) structure = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] #241 - might need to add a zero onto zc1trunc for the case where nothing needs to be cut labelarray = -1 * np.ones(mymaskarray.shape) for i in range(0, origRefImg.GetSize()[1]): if np.unique(sitk.GetArrayFromImage(refImg[:, i, :])).shape[0] < 2: temparray = np.ones((labelarray.shape[0], labelarray.shape[2])) temparray[2:temparray.shape[0] - 2, 2:temparray.shape[1] - 2] = np.zeros(
import SimpleITK as sitk import histFunctions import ndreg3D import sys sys.path.insert( 0, '/sonas-hs/mitra/hpc/home/kram/Marmoset_Pipeline_2019/code/numpy') import numpy as np targetfilename = sys.argv[1] #outputfilename = sys.argv[2] outputslicefilename = sys.argv[2] transformfilename = sys.argv[3] img = sitk.ReadImage(targetfilename) inflectionpoint = histFunctions.getInflectionPoint(img) mymask = ndreg3D.imgMakeMask(img, threshold=inflectionpoint) xmax = np.min((np.where(sitk.GetArrayFromImage(mymask) == 1)[0].max() + 15, img.GetSize()[2])) xmin = np.max((np.where(sitk.GetArrayFromImage(mymask) == 1)[0].min() - 15, 0)) ymax = np.min((np.where(sitk.GetArrayFromImage(mymask) == 1)[2].max() + 15, img.GetSize()[0])) ymin = np.max((np.where(sitk.GetArrayFromImage(mymask) == 1)[2].min() - 15, 0)) #outImg = img[ymin:ymax,:,xmin:xmax] #sitk.WriteImage(outImg, outputfilename) # transform slice by slice registeredimagelist = [None] * img.GetSize()[1]
refImg_us = sitk.Resample(refImg, [ int( np.round( refImg.GetSize()[0] * refImg.GetSpacing()[0] / outputpixelsize)), int( np.round( refImg.GetSize()[1] * refImg.GetSpacing()[1] / outputpixelsize)), int( np.round( refImg.GetSize()[2] * refImg.GetSpacing()[2] / outputpixelsize)) ], identityAffine, sitk.sitkLinear, (0, 0, 0), (outputpixelsize, outputpixelsize, outputpixelsize), (1, 0, 0, 0, 1, 0, 0, 0, 1), 0.0) # crop inflectionpoint = histFunctions.getInflectionPoint(refImg_us) mymask = ndreg3D.imgMakeMask(refImg_us, threshold=inflectionpoint) xmax = np.min((np.where(sitk.GetArrayFromImage(mymask) == 1)[0].max() + 15, refImg_us.GetSize()[2])) xmin = np.max((np.where(sitk.GetArrayFromImage(mymask) == 1)[0].min() - 15, 0)) ymax = np.min((np.where(sitk.GetArrayFromImage(mymask) == 1)[2].max() + 15, refImg_us.GetSize()[0])) ymin = np.max((np.where(sitk.GetArrayFromImage(mymask) == 1)[2].min() - 15, 0)) zmax = np.min((np.where(sitk.GetArrayFromImage(mymask) == 1)[1].max() + 15, refImg_us.GetSize()[1])) zmin = np.max((np.where(sitk.GetArrayFromImage(mymask) == 1)[1].min() - 15, 0)) croptransform = sitk.TranslationTransform(3)