Example #1
0
destDir = sys.argv[1] + "/"

# helper function to create the directories like mkdir -p
def mkdir( path ):
	p = ""
	for d in path.split("/") :
		p += d + "/"
		if not os.path.exists( p ):
			os.mkdir( p )
			
def log( s ):
	print s,
	sys.stdout.flush()

# the pipeline used to convert the lsm files to the a serie of tif used in freed
reader = itk.lsm()
writer = itk.ImageSeriesWriter.IUC3IUC2.New(reader, UseCompression=True)

# the names must be generated with a NumericSeriesFileNames object, because the 
# vector of strings are not usable yet from python
names = itk.NumericSeriesFileNames.New()
# make the slice number start at 0 instead of 1
names.SetStartIndex( 0 )

# the descriptor file contain a header...
descriptorHeaderTpl = """STACK "%(channelName)s";
IMAGESPATH "%(imagePath)s";
PIXWIDTH %(pixelWidth)s;
PIXHEIGHT %(pixelHeight)s;
RELPOSITION %(sliceSpacing)s;
"""
Example #2
0
  i.UpdateLargestPossibleRegion()
  i =  itk.image(i)
  return i.GetNumberOfLabelObjects()


def copyImage( f ):
  """Copy an itk.Image object.
  """
  f.UpdateLargestPossibleRegion()
  i = f.GetOutput()
  imgDuplicator = itk.ImageDuplicator[i].New(i)
  imgDuplicator.Update()
  return imgDuplicator.GetOutput()


readerNuclei = itk.lsm(channel=0, fileName=inputImageName)

medianNuclei = itk.MedianImageFilter.IUC3IUC3.New(readerNuclei)
gaussianNuclei = itk.SmoothingRecursiveGaussianImageFilter.IUC3IUC3.New(medianNuclei, Sigma=0.2)
fillNuclei = itk.SliceBySliceImageFilter.IUC3IUC3.New(gaussianNuclei, Filter=fill.GetPointer())
sizeNuclei = itk.PhysicalSizeOpeningImageFilter.IUC3IUC3.New(fillNuclei, Lambda=200)
gradientNuclei = itk.GradientMagnitudeRecursiveGaussianImageFilter.IUC3IUC3.New(sizeNuclei, Sigma=0.36)
ratsNuclei = itk.RobustAutomaticThresholdImageFilter.IUC3IUC3IUC3.New(sizeNuclei, gradientNuclei)
# enlarge the nuclei to be sure to found the spots on the border
dilateNuclei = itk.BinaryDilateImageFilter.IUC3IUC3SE3.New(ratsNuclei, Kernel=itk.strel(3, [5,5,3]))
# split and labelize the nuclei
maurerNuclei = itk.SignedMaurerDistanceMapImageFilter.IUC3IF3.New(dilateNuclei, UseImageSpacing=True)
watershedNuclei = itk.MorphologicalWatershedImageFilter.IF3IUC3.New(maurerNuclei, Level=5.0, MarkWatershedLine=False) #, FullyConnected=True)
maskWatershedNuclei = itk.MaskImageFilter.IUC3IUC3IUC3.New(watershedNuclei, dilateNuclei)
lmNuclei = itk.LabelImageToLabelMapFilter.IUC3LM3.New(maskWatershedNuclei)
# the same with the real mask (not the enlarged one), and also compute shape attributes for that one
Example #3
0
itk.MultiThreader.SetGlobalDefaultNumberOfThreads(1)


def med(numbers):
    "Return the median of the list of numbers."
    # Sort the list and take the middle element.
    n = len(numbers)
    copy = numbers[:]  # So that "numbers" keeps its original order
    copy.sort()
    if n & 1:  # There is an odd number of elements
        return copy[n // 2]
    else:
        return (copy[n // 2 - 1] + copy[n // 2]) / 2


reader = itk.lsm(ImageType=itk.Image.US3)

# use a median to remove some noise
median = itk.MedianImageFilter.IUS3IUS3.New(reader)

# first find the beads, to process them one by one
# That's done by projecting the image on the z axis, splitting the 2D image in several
# regions (one per bead) and unprojecting the regions in the original 3d image
projz = itk.MaximumProjectionImageFilter.IUS3IUS2.New(median)
invert = itk.InvertIntensityImageFilter.IUS2IUS2.New(projz)
watershed = itk.MorphologicalWatershedImageFilter.IUS2IUS2.New(invert, MarkWatershedLine=False)
wrelabel = itk.RelabelComponentImageFilter.IUS2IUS2.New(watershed)
upperdim = itk.UpperDimensionImageFilter.IUS2IUS3.New(wrelabel, NewDimension=2)

# mask the image to select only one bead
selectedLabel = itk.BinaryThresholdImageFilter.IUS3IUS3.New(upperdim)
Example #4
0
  genesFile = sys.stdout
else:
  genesFile = file( opts.genes, "a" )
  if os.path.getsize( opts.genes ) == 0:
    genesFile.write( '"stimulation" "img" "nucleus" "gene" "x" "y" "z" "px" "py" "pz" "dist" "ci" "mean" "max" "median" "nMean" "nMinimum" "nMaximum" "nMedian" "nSigma" "nKurtosis" "nSkewness"\n' )



# itk.auto_not_in_place()


##########################
# nuclei
##########################

readerNuclei = itk.lsm(channel=1)
# fill the holes - nucleoles etc - in the nuclei
fillHoles2D = itk.GrayscaleFillholeImageFilter.IUC2IUC2.New(auto_progress=False)
fillHolesNuclei = itk.SliceBySliceImageFilter.IUC3IUC3.New(readerNuclei, Filter=fillHoles2D.GetPointer())
# remove some noise and smooth the image
medianNuclei = itk.MedianImageFilter.IUC3IUC3.New(readerNuclei)
gaussianNuclei = itk.SmoothingRecursiveGaussianImageFilter.IUC3IUC3.New(medianNuclei, Sigma=0.2)
inputNuclei = gaussianNuclei

# to compare with different thresholding methods
otsuNuclei = itk.OtsuThresholdImageCalculator.IUC3.New(gaussianNuclei)

# now we have 2 things: a large shape used to find the spots, and a smaller one used to precisely find the
# border of the nucleus.

# use the rats algorithm to find the nucleus with precision