Beispiel #1
0
#     OUTPUTS: {ThresholdSegmentationLevelSetImageFilterWhiteMatter.png}
#     60 116 5 150 180

#     INPUTS: {BrainProtonDensitySlice.png}
#     OUTPUTS: {ThresholdSegmentationLevelSetImageFilterVentricle.png}
#     81 112 5 210 250

#     INPUTS: {BrainProtonDensitySlice.png}
#     OUTPUTS: {ThresholdSegmentationLevelSetImageFilterGrayMatter.png}
#     107 69 5 180  210

import itk
from sys import argv, stderr, exit
import os

itk.auto_progress(2)

# itk.auto_progress(1)

if len(argv) < 8:
    print(
        ("Missing Parameters \n Usage: "
         "ThresholdSegmentationLevelSetImageFilter.py inputImage outputImage "
         "seedX seedY InitialDistance LowerThreshold UpperThreshold "
         "[CurvatureScaling == 1.0]"),
        file=stderr,
    )
    exit(1)

InternalPixelType = itk.F
Dimension = 2
Beispiel #2
0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
#==========================================================================*/

#
#  Example on the use of the SigmoidImageFilter
#

import itk
from sys import argv
itk.auto_progress(2)

dim = 2
IType = itk.Image[itk.US, dim]
OIType = itk.Image[itk.UC, dim]

reader = itk.ImageFileReader[IType].New( FileName=argv[1] )
filter  = itk.SigmoidImageFilter[IType, IType].New( reader,
                  OutputMinimum=eval( argv[3] ),
                  OutputMaximum=eval( argv[4] ),
                  Alpha=eval( argv[5] ),
                  Beta=eval( argv[6] ),
                  )
cast = itk.CastImageFilter[IType, OIType].New(filter)
writer = itk.ImageFileWriter[OIType].New( cast, FileName=argv[2] )
Beispiel #3
0
  image: the input image''')

parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="display infos about progress")
parser.add_option("-t", "--threads", type="int", dest="threads", default=0, help="number of threads to use. Defaults to the number of procs")

opts, args = parser.parse_args()

# check the arguments
if len(args) != 1:
  parser.error("incorrect number of arguments")
inputFileName = args[0]
inputFile = open( inputFileName )


if opts.verbose:
  itk.auto_progress()

if opts.threads > 0:
  itk.MultiThreader.SetGlobalDefaultNumberOfThreads( opts.threads )




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

labelRobustNuclei = itk.ImageFileReader.IUC3.New()

# select a single nucleus - see the loop at the end
singleMaskRobustNuclei = itk.BinaryThresholdImageFilter.IUC3IUC3.New(labelRobustNuclei, UpperThreshold=1, LowerThreshold=1)
import itk, sys
itk.auto_progress()

Dimension = 2
PixelType = itk.UC
ImageType = itk.Image[PixelType, Dimension]

DistancePixelType = itk.F
DistanceImageType = itk.Image[DistancePixelType, Dimension]

RGBPixelType = itk.RGBPixel[PixelType]
RGBImageType = itk.Image[RGBPixelType, Dimension]

LabelObjectType = itk.StatisticsLabelObject[itk.UL, Dimension]
LabelMapType = itk.LabelMap[LabelObjectType]

# read the image of the nucleus
nuclei = itk.ImageFileReader[ImageType].New(FileName="images/noyaux.png")
# perform a simple binarization. Note that the Otsu filter does not use the same convention as usual : the white part is outside.
otsu = itk.OtsuThresholdImageFilter[ImageType, ImageType].New(nuclei,
                                                              OutsideValue=255,
                                                              InsideValue=0)
# split the nuclei
maurer = itk.SignedMaurerDistanceMapImageFilter[ImageType,
                                                DistanceImageType].New(otsu)
watershed = itk.MorphologicalWatershedImageFilter[DistanceImageType,
                                                  ImageType].New(
                                                      maurer,
                                                      Level=60,
                                                      MarkWatershedLine=False)
mask = itk.MaskImageFilter[ImageType, ImageType,
Beispiel #5
0
import itk; itk.auto_progress()
itk.auto_not_in_place()

import sys

def mean(s):
  res = float(sum(s))
  return res / len(s)

def median(s):
  res = sorted(s)
  l = len(res)/2
  if len(res)%2:
    return res[l]
  else:
    return mean(res[l-1:l+1])


class ClosestLabelDilateImageFilter(itk.pipeline):
  def __init__(self, *args, **kargs):
    # call the constructor of the superclass but without args and kargs, because the attributes
    # are not all already there!
    # Set/GetRadius() is created in the constructor for example, with the expose() method
    itk.pipeline.__init__(self)
    
    # get the template parameters
    template_parameters = kargs["template_parameters"]
    
    # and store them in an easier way
    ImageType, DistanceMapType = template_parameters
Beispiel #6
0
import itk, math, csv

itk.auto_progress(True)

toAnalyze = range(1,26)
imgDir = 'images/apotome/'
csvFile = 'data/nucleus_stats.csv'

## Define pipeline
reader = itk.ImageFileReader.IUC3.New()
labmap = itk.LabelImageToShapeLabelMapFilter.IUC3LM3.New(reader,ComputePerimeter=True)
## End of pipeline definition

toAnalyze = [str(nb) for nb in toAnalyze]
dataFile = open(csvFile,'w')
dataWriter = csv.writer(dataFile)
dataWriter.writerow(['img.nb','label','x','y','z','volume','diameter','surface','shape','elongation','height','a.x','a.y','a.z'])
for nb in toAnalyze:
   filename = imgDir+'gml16_dapi_'+nb+'_nuclei.nrrd'
   print 'Image filename',filename
   reader.SetFileName(filename)
   labmap.UpdateLargestPossibleRegion()
   lmo = labmap.GetOutput()
   n = lmo.GetNumberOfLabelObjects()
   print '\t',n,'nuclei'
   for i in range(n):
       row = [nb,i+1]
       nucleus = lmo.GetNthLabelObject(i)
       centroid = nucleus.GetCentroid()
       for j in range(3):
           row.append(centroid[j])