1 sitk_ seg_ img = sitk . ReadImage( m )
2 bbox =get_ bbox_ from mask(sitk_ seg_ _img)
3
4 def get_bbox_from_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 GetArrayFromImage , 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_from_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 GetArrayFromImage , 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_from_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 GetArrayFromImage , 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.PullVolumeFromSlicer(canalBoneNode)
19 itkImagelabel = sitk.Cast(itkImagelabel, sitk.sitkUInt8)
20 bbox = self.get_bbox_from_mask(itkImagelabel)
21 print("bbox: \n", bbox)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2022-07-13 Qt 路径中常用字符“./”、“../”、“/”、“*”的含义
2022-07-13 MATLAB 函数汉化方法
2022-07-13 Git 入门指南
2022-07-13 ARM、STM32之间的关系以及STM单片机介绍