SimpleITK 获取二值图像bbox
1 sitk_ seg_ img = sitk . ReadImage( m ) 2 bbox =get_ bbox_ fr mask(sitk_ seg_ _img) 3 4 def get_bbox_fr_mask(bin_mask): 5 # One is : sitk.LabelShapeStatisticsImageFilter() 6 # Input: bin_mask 7 # Output: bbox<x,y,z, length, width, height> 8 # here, x y z > (R, A, S) when direction=(1,1,1) 9 # Note: for GetArrayFrImage , it is <z, y, x> 10 # Front idx = 1, background idx = 0 11 label_filter = sitk.LabelShapeStatisticsImageFilter() 12 label_filter.Execute(bin_mask) 13 bbox = label_filter.GetBoundingBox(1) 14 return bbox 15 16 17 def get_bbox_fr_volme_and_mask(sitk_seg_img): 18 # Another is : sitk.LabelStatisticsImageFilter() 19 # Input: <raw_img ,bin_mask> 20 # Output: bbox = <x_min, x_max, y_min, y_max, z_min, z_max> 21 # Note: for GetArrayFrImage , it is <z, y, x> 22 # Front idx = 1, background idx = 0 23 label_filter = sitk.LabelStatisticsImageFilter() 24 label_filter.Execute(sitk_seg_img, sitk_seg_img) 25 bbox = label_filter.GetBoundingBox(1) 26 return bbox
1 def get_bbox_fr_mask(self, bin_mask): 2 # One is : sitk.LabelShapeStatisticsImageFilter() 3 # Input: bin_mask 4 # Output: bbox<x,y,z, length, width, height> 5 # here, x y z > (R, A, S) when direction=(1,1,1) 6 # Note: for GetArrayFrImage , it is <z, y, x> 7 # Front idx = 1, background idx = 0 8 label_filter = sitk.LabelShapeStatisticsImageFilter() 9 label_filter.Execute(bin_mask) 10 bbox = label_filter.GetBoundingBox(1) 11 return bbox 12 13 def landmarkCanal(self): 14 canalBoneNode = slicer.util.getFirstNodeByClassByName("vtkMRMLLabelMapVolumeNode", self._canal_seg) 15 segbounds = np.zeros([6]) 16 canalBoneNode.GetBounds(segbounds) 17 print("segbounds \n", segbounds) 18 itkImagelabel = sitkUtils.PullVolumeFrSlicer(canalBoneNode) 19 itkImagelabel = sitkast(itkImagelabel, sitk.sitkUInt8) 20 bbox = self.get_bbox_fr_mask(itkImagelabel) 21 print("bbox: \n", bbox)
下一篇:ITK 连通域分析
ITK
spc文件怎么看,spc文件用什么打开?
0文件怎么看,0文件用什么打开?
sparseimage文件怎么看,sparseimage文件用什么打开?
sp文件怎么看,sp文件用什么打开?
dv文件怎么看,dv文件用什么打开?
soundpack文件怎么看,soundpack文件用什么打开?
dus文件怎么看,dus文件用什么打开?
dtw文件怎么看,dtw文件用什么打开?
spdf文件怎么看,spdf文件用什么打开?
0文件怎么看,0文件用什么打开?