Example #1
0
    def _showImagePair(self, pairNumber):
        """Set everything up to have the user interact with image pair
        pairNumber.

        pairNumber is 1 based, i.e. pairNumber 1 implies the registration
        between image 1 and image 0.
        """

        # FIXME: do sanity checking on pairNumber
        self._pairNumber = pairNumber

        # connect up ITK pipelines with the correct images and transforms
        fixedImage = self._imageStack[pairNumber - 1]
        self._rescaler1.SetInput(fixedImage)
        self._rescaler1.Update() # give ITK a chance to complain...

        self._resampler2 = itk.itkResampleImageFilterF2F2_New()

        self._resampler2.SetTransform(
            self._transformStack[pairNumber].GetPointer())
        self._resampler2.SetInput(self._imageStack[pairNumber])
        region = fixedImage.GetLargestPossibleRegion()
        self._resampler2.SetSize(region.GetSize())
        self._resampler2.SetOutputSpacing(fixedImage.GetSpacing())
        self._resampler2.SetOutputOrigin(fixedImage.GetOrigin())
        self._resampler2.SetDefaultPixelValue(0)
        
        self._rescaler2.SetInput(self._resampler2.GetOutput())
        self._rescaler2.Update() # give ITK a chance to complain...


        self._syncGUIToCurrentPair()
        
        # we're going to create new ones, so take care of the old ones
        self._destroyIPWs()
        
        self._createIPWs()

        self._resetCamera()
Example #2
0
    def _showImagePair(self, pairNumber):
        """Set everything up to have the user interact with image pair
        pairNumber.

        pairNumber is 1 based, i.e. pairNumber 1 implies the registration
        between image 1 and image 0.
        """

        # FIXME: do sanity checking on pairNumber
        self._pairNumber = pairNumber

        # connect up ITK pipelines with the correct images and transforms
        fixedImage = self._imageStack[pairNumber - 1]
        self._rescaler1.SetInput(fixedImage)
        self._rescaler1.Update()  # give ITK a chance to complain...

        self._resampler2 = itk.itkResampleImageFilterF2F2_New()

        self._resampler2.SetTransform(
            self._transformStack[pairNumber].GetPointer())
        self._resampler2.SetInput(self._imageStack[pairNumber])
        region = fixedImage.GetLargestPossibleRegion()
        self._resampler2.SetSize(region.GetSize())
        self._resampler2.SetOutputSpacing(fixedImage.GetSpacing())
        self._resampler2.SetOutputOrigin(fixedImage.GetOrigin())
        self._resampler2.SetDefaultPixelValue(0)

        self._rescaler2.SetInput(self._resampler2.GetOutput())
        self._rescaler2.Update()  # give ITK a chance to complain...

        self._syncGUIToCurrentPair()

        # we're going to create new ones, so take care of the old ones
        self._destroyIPWs()

        self._createIPWs()

        self._resetCamera()
Example #3
0
    def _createPipelines(self):
        """Setup all necessary logic to transform, combine and convert all
        input images.

        Call this ONLY if things have changed, i.e. when
        your change observer is called or if the transform2D input ports
        are changed.
        """

        if not self._imageStack or not self._transformStack:
            self._destroyPipelines()
            # in this case, we should break down the pipeline
            return

        # take care of all inputs
        self._imageAppend.RemoveAllInputs()

        #totalTrfm = itk.itkEuler2DTransform_New()
        totalTrfm = itk.itkCenteredRigid2DTransform_New()
        totalTrfm.SetIdentity()
        
        prevImage = self._imageStack[0]
        for trfm, img, i in zip(self._transformStack,
                                self._imageStack,
                                range(len(self._imageStack))):
            # accumulate with our totalTransform
            totalTrfm.Compose(trfm.GetPointer(), 0)
            # make a copy of the totalTransform that we can use on
            # THIS image

	    # copyTotalTrfm = itk.itkEuler2DTransform_New()
	    copyTotalTrfm = itk.itkCenteredRigid2DTransform_New()
	    
            # this is a really kludge way to copy the total transform,
            # as concatenation doesn't update the Parameters member, so
            # getting and setting parameters is not the way to go
            copyTotalTrfm.SetIdentity()
            copyTotalTrfm.Compose(totalTrfm.GetPointer(),0)

            # this SHOULD have worked
            #pda = totalTrfm.GetParameters()
            #copyTotalTrfm.SetParameters(pda)
            
            # this actually increases the ref count of the transform!
            # resampler
            resampler = itk.itkResampleImageFilterF2F2_New()
            resampler.SetTransform(copyTotalTrfm.GetPointer())
            resampler.SetInput(img)

            region = prevImage.GetLargestPossibleRegion()
            resampler.SetSize(region.GetSize())
            resampler.SetOutputSpacing(prevImage.GetSpacing())
            resampler.SetOutputOrigin(prevImage.GetOrigin())
            resampler.SetDefaultPixelValue(0)
            
            # set up all the 
            rescaler = itk.itkRescaleIntensityImageFilterF2US2_New()
            rescaler.SetOutputMinimum(0)
            rescaler.SetOutputMaximum(65535)
            rescaler.SetInput(resampler.GetOutput())
            print "Resampling image %d" % (i,)
            rescaler.Update() # give ITK a chance to complain

            itkExporter = itk.itkVTKImageExportUS2_New()
            itkExporter.SetInput(rescaler.GetOutput())
            # this is so the ref keeps hanging around
            self._itkExporterStack.append(itkExporter)

            vtkImporter = vtk.vtkImageImport()
            CVIPy.ConnectITKUS2ToVTK(itkExporter.GetPointer(),
                                     vtkImporter)

            # FIXME KLUDGE: we ignore image 0 (this is for joris)
            # if i > 0:
            #    self._imageAppend.AddInput(vtkImporter.GetOutput())

            # setup the previous Image for the next loop
            prevImage = img
Example #4
0
    def _createPipelines(self):
        """Setup all necessary logic to transform, combine and convert all
        input images.

        Call this ONLY if things have changed, i.e. when
        your change observer is called or if the transform2D input ports
        are changed.
        """

        if not self._imageStack or not self._transformStack:
            self._destroyPipelines()
            # in this case, we should break down the pipeline
            return

        # take care of all inputs
        self._imageAppend.RemoveAllInputs()

        #totalTrfm = itk.itkEuler2DTransform_New()
        totalTrfm = itk.itkCenteredRigid2DTransform_New()
        totalTrfm.SetIdentity()

        prevImage = self._imageStack[0]
        for trfm, img, i in zip(self._transformStack, self._imageStack,
                                range(len(self._imageStack))):
            # accumulate with our totalTransform
            totalTrfm.Compose(trfm.GetPointer(), 0)
            # make a copy of the totalTransform that we can use on
            # THIS image

            # copyTotalTrfm = itk.itkEuler2DTransform_New()
            copyTotalTrfm = itk.itkCenteredRigid2DTransform_New()

            # this is a really kludge way to copy the total transform,
            # as concatenation doesn't update the Parameters member, so
            # getting and setting parameters is not the way to go
            copyTotalTrfm.SetIdentity()
            copyTotalTrfm.Compose(totalTrfm.GetPointer(), 0)

            # this SHOULD have worked
            #pda = totalTrfm.GetParameters()
            #copyTotalTrfm.SetParameters(pda)

            # this actually increases the ref count of the transform!
            # resampler
            resampler = itk.itkResampleImageFilterF2F2_New()
            resampler.SetTransform(copyTotalTrfm.GetPointer())
            resampler.SetInput(img)

            region = prevImage.GetLargestPossibleRegion()
            resampler.SetSize(region.GetSize())
            resampler.SetOutputSpacing(prevImage.GetSpacing())
            resampler.SetOutputOrigin(prevImage.GetOrigin())
            resampler.SetDefaultPixelValue(0)

            # set up all the
            rescaler = itk.itkRescaleIntensityImageFilterF2US2_New()
            rescaler.SetOutputMinimum(0)
            rescaler.SetOutputMaximum(65535)
            rescaler.SetInput(resampler.GetOutput())
            print "Resampling image %d" % (i, )
            rescaler.Update()  # give ITK a chance to complain

            itkExporter = itk.itkVTKImageExportUS2_New()
            itkExporter.SetInput(rescaler.GetOutput())
            # this is so the ref keeps hanging around
            self._itkExporterStack.append(itkExporter)

            vtkImporter = vtk.vtkImageImport()
            CVIPy.ConnectITKUS2ToVTK(itkExporter.GetPointer(), vtkImporter)

            # FIXME KLUDGE: we ignore image 0 (this is for joris)
            # if i > 0:
            #    self._imageAppend.AddInput(vtkImporter.GetOutput())

            # setup the previous Image for the next loop
            prevImage = img