一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万
复制代码
 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)
复制代码

 

posted on   一杯清酒邀明月  阅读(88)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!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单片机介绍
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示