code: def GetLargestConnectedCompont(binarysitk_image):
      # 最大连通域提取,binarysitk_image 是掩膜
      cc = sitk.ConnectedComponent(binarysitk_image)
      stats = sitk.LabelIntensityStatisticsImageFilter()
      stats.SetGlobalDefaultNumberOfThreads(8)
      stats.Execute(cc, binarysitk_image)  # 根据掩膜计算统计量
      # stats.
      maxlabel = 0
      maxsize = 0
      for l in stats.GetLabels():  # 掩膜中存在的标签类别
          size = stats.GetPhysicalSize(l)
          if maxsize < size:  # 只保留最大的标签类别
              maxlabel = l
              maxsize = size
      labelmaskimage = sitk.GetArrayFromImage(cc)
      outmask = labelmaskimage.copy()
      if len(stats.GetLabels()):
          outmask[labelmaskimage == maxlabel] = 255
          outmask[labelmaskimage != maxlabel] = 0
      return outmask
  
imports: import numpy
  import SimpleITK
label_desc: Use image node_id 3 for calling a global function with example usage: GetLargestConnectedCompont(binarysitk_image) and returns: outmask