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)



上一篇:VTK 9.2 Qt 5.14 安装及错误处理

下一篇:ITK 连通域分析


ITK
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图