def __init__(self): self._imageTransform = None self._stencil = None self._voiExtent = None self._voiPolyData = None # create a statistics object self._imageStats = _MicroView.vtkImageStatistics() self._imageStats.SetProgressText("Calculating image stats...") self._imageStats.AddObserver( 'ProgressEvent', self.HandleVTKProgressEvent) # parameters to be calculated self._meanValue = None self._stdDeviation = None self._total = None self._voxelCount = None self._histogram = None self._threshold = None self._binSize = 1
def __init__(self): self._imageTransform = None self._stencil = None self._voiExtent = None self._voiPolyData = None # create a statistics object self._imageStats = _MicroView.vtkImageStatistics() self._imageStats.SetProgressText("Calculating image stats...") self._imageStats.AddObserver('ProgressEvent', self.HandleVTKProgressEvent) # parameters to be calculated self._meanValue = None self._stdDeviation = None self._total = None self._voxelCount = None self._histogram = None self._threshold = None self._binSize = 1
def BMDAnalysis(self): with wx.BusyCursor(): state = self._app_states[self._current_image_index] imageStats2 = _MicroView.vtkImageStatistics() imageStats2.SetInputConnection( component.getUtility(ICurrentImage).GetOutputPort()) # VTK-6 if vtk.vtkVersion().GetVTKMajorVersion() > 5: imageStats2.SetStencilData(self.__stencil_data) else: imageStats2.SetStencil(self.__stencil_data) imageStats2.SetWaterValue(float(state.WaterADU)) imageStats2.SetBoneValue(int(state.BoneADU)) imageStats2.SetLowerExclusionValue(int(state.LowerExclusion)) imageStats2.SetUpperExclusionValue(int(state.UpperExclusion)) imageStats2.SetBVFThreshold(float(state.threshold)) imageStats2.SetProgressText('BMD Analysis...') imageStats2.AddObserver('ProgressEvent', self.HandleVTKProgressEvent) imageStats2.Update() # Mean and Standard Deviation self.Mean = imageStats2.GetMean()[0] self.StdDev = imageStats2.GetStandardDeviation()[0] # self.MeanResultLabel.configure(text="%0.2f" % self.Mean) # self.StdDevResultLabel.configure(text="%0.2f" % self.StdDev) # BMD self.BMD = imageStats2.GetBMD() self.BMC = imageStats2.GetBoneMass() self.Volume = imageStats2.GetVolume() * 1000.0 # we use mm^3 here self.Voxels = imageStats2.GetVoxelCount() self.ThresholdedBMD = imageStats2.GetThresholdedBMD() self.ThresholdedBMC = imageStats2.GetThresholdedBoneMass() # BVF self.BVF = 0.0 try: self.BVF = imageStats2.GetBoneVoxelCount() / float( imageStats2.GetVoxelCount()) except: pass del imageStats2 out = StringIO.StringIO() out.write("\n==============\n") out.write("= BMD Analysis\n") out.write("==============\n") out.write(" Mean: %10.4f\n" % (self.Mean, )) out.write(" Standard Deviation: %10.4f\n" % (self.StdDev, )) out.write(" Total Volume: %10.4f (mm^3)\n" % (self.Volume, )) out.write(" Bone Volume: %10.4f (mm^3)\n" % (self.Volume * self.BVF, )) out.write(" Voxel: %d\n" % self.Voxels) if int(state.BoneADU) == 0: out.write( " Bone mineral content (mg): Error, No BoneHU for image.\n" ) out.write(" BMD (mg/cc): Error, No BoneHU for image.\n") out.write( " Tissue mineral density (mg/cc): Error, No BoneHU for image.\n" ) else: out.write(" Bone mineral content (mg): %10.4f\n" % (self.BMC)) out.write(" BMD (mg/cc): %10.4f\n" % (self.BMD)) out.write(" Tissue mineral content (mg): %10.4f\n" % (self.ThresholdedBMC)) out.write(" Tissue mineral density (mg/cc): %10.4f\n" % (self.ThresholdedBMD)) out.write(" BVF: %10.4f\n" % self.BVF) out.write('\n') self._BMDOutStr = out.getvalue() out.close() self._ResultsDict['BMDMean'] = self.Mean self._ResultsDict['BMDStdDev'] = self.StdDev self._ResultsDict['BMDVolume'] = self.Volume self._ResultsDict['BMDBoneVolume'] = self.Volume * self.BVF self._ResultsDict['BMDVoxels'] = self.Voxels self._ResultsDict['BMDBVF'] = self.BVF if int(state.BoneADU) > 0: self._ResultsDict['BMDBMC'] = self.BMC self._ResultsDict['BMDBMD'] = self.BMD self._ResultsDict['BMDTMC'] = self.ThresholdedBMC self._ResultsDict['BMDTMD'] = self.ThresholdedBMD event.notify(ProgressEvent("BMD Analysis... Done.", 1.0)) # return status return 0
def BMDAnalysis(self): with wx.BusyCursor(): state = self._app_states[self._current_image_index] imageStats2 = _MicroView.vtkImageStatistics() imageStats2.SetInputConnection(component.getUtility( ICurrentImage).GetOutputPort()) # VTK-6 if vtk.vtkVersion().GetVTKMajorVersion() > 5: imageStats2.SetStencilData(self.__stencil_data) else: imageStats2.SetStencil(self.__stencil_data) imageStats2.SetWaterValue(float(state.WaterADU)) imageStats2.SetBoneValue(int(state.BoneADU)) imageStats2.SetLowerExclusionValue(int(state.LowerExclusion)) imageStats2.SetUpperExclusionValue(int(state.UpperExclusion)) imageStats2.SetBVFThreshold(float(state.threshold)) imageStats2.SetProgressText('BMD Analysis...') imageStats2.AddObserver( 'ProgressEvent', self.HandleVTKProgressEvent) imageStats2.Update() # Mean and Standard Deviation self.Mean = imageStats2.GetMean()[0] self.StdDev = imageStats2.GetStandardDeviation()[0] # self.MeanResultLabel.configure(text="%0.2f" % self.Mean) # self.StdDevResultLabel.configure(text="%0.2f" % self.StdDev) # BMD self.BMD = imageStats2.GetBMD() self.BMC = imageStats2.GetBoneMass() self.Volume = imageStats2.GetVolume() * 1000.0 # we use mm^3 here self.Voxels = imageStats2.GetVoxelCount() self.ThresholdedBMD = imageStats2.GetThresholdedBMD() self.ThresholdedBMC = imageStats2.GetThresholdedBoneMass() # BVF self.BVF = 0.0 try: self.BVF = imageStats2.GetBoneVoxelCount() / float( imageStats2.GetVoxelCount()) except: pass del imageStats2 out = StringIO.StringIO() out.write("\n==============\n") out.write("= BMD Analysis\n") out.write("==============\n") out.write(" Mean: %10.4f\n" % (self.Mean,)) out.write(" Standard Deviation: %10.4f\n" % (self.StdDev,)) out.write(" Total Volume: %10.4f (mm^3)\n" % (self.Volume,)) out.write(" Bone Volume: %10.4f (mm^3)\n" % ( self.Volume * self.BVF,)) out.write(" Voxel: %d\n" % self.Voxels) if int(state.BoneADU) == 0: out.write( " Bone mineral content (mg): Error, No BoneHU for image.\n") out.write(" BMD (mg/cc): Error, No BoneHU for image.\n") out.write( " Tissue mineral density (mg/cc): Error, No BoneHU for image.\n") else: out.write(" Bone mineral content (mg): %10.4f\n" % ( self.BMC)) out.write(" BMD (mg/cc): %10.4f\n" % (self.BMD)) out.write(" Tissue mineral content (mg): %10.4f\n" % ( self.ThresholdedBMC)) out.write(" Tissue mineral density (mg/cc): %10.4f\n" % ( self.ThresholdedBMD)) out.write(" BVF: %10.4f\n" % self.BVF) out.write('\n') self._BMDOutStr = out.getvalue() out.close() self._ResultsDict['BMDMean'] = self.Mean self._ResultsDict['BMDStdDev'] = self.StdDev self._ResultsDict['BMDVolume'] = self.Volume self._ResultsDict['BMDBoneVolume'] = self.Volume * self.BVF self._ResultsDict['BMDVoxels'] = self.Voxels self._ResultsDict['BMDBVF'] = self.BVF if int(state.BoneADU) > 0: self._ResultsDict['BMDBMC'] = self.BMC self._ResultsDict['BMDBMD'] = self.BMD self._ResultsDict['BMDTMC'] = self.ThresholdedBMC self._ResultsDict['BMDTMD'] = self.ThresholdedBMD event.notify(ProgressEvent("BMD Analysis... Done.", 1.0)) # return status return 0