def _fetchTransformStack( self ): # connect to the database connectString = r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + self._config.databaseFile + ";" try: connection = adodbapi.connect( connectString ) except adodbapi.Error: raise IOError, "Could not open database." # try to figure out reconstruction ID from recontruction name print "NAME: " + self._config.reconstructionName cursor = connection.cursor() cursor.execute( "SELECT id FROM reconstruction WHERE name=?", [ self._config.reconstructionName ] ) row = cursor.fetchone() if row == None: raise IOError, "Reconstruction not found." print "reconstructionID: %i" % row[ 0 ] # build transformStack cursor.execute( "SELECT angle, centerx, centery, tx, ty FROM centeredRigid2DTransform WHERE reconstruction_id=? ORDER BY seq_nr", [ row[ 0 ] ] ) for row in cursor.fetchall(): trfm = itk.itkCenteredRigid2DTransform_New() params = trfm.GetParameters() for i in range(0,5): params.SetElement( i, row[ i ] ) trfm.SetParameters( params ) self._transformStack.append( trfm ) cursor.close() connection.close()
def _fetchTransformStack(self): # connect to the database connectString = r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + self._config.databaseFile + ";" try: connection = adodbapi.connect(connectString) except adodbapi.Error: raise IOError, "Could not open database." # try to figure out reconstruction ID from recontruction name print "NAME: " + self._config.reconstructionName cursor = connection.cursor() cursor.execute("SELECT id FROM reconstruction WHERE name=?", [self._config.reconstructionName]) row = cursor.fetchone() if row == None: raise IOError, "Reconstruction not found." print "reconstructionID: %i" % row[0] # build transformStack cursor.execute( "SELECT angle, centerx, centery, tx, ty FROM centeredRigid2DTransform WHERE reconstruction_id=? ORDER BY seq_nr", [row[0]], ) for row in cursor.fetchall(): trfm = itk.itkCenteredRigid2DTransform_New() params = trfm.GetParameters() for i in range(0, 5): params.SetElement(i, row[i]) trfm.SetParameters(params) self._transformStack.append(trfm) cursor.close() connection.close()
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
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