X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkMotionMaskGenericFilter.txx;h=fd21b4629d4da99590b741e4fe7fa9ff634cfb50;hb=HEAD;hp=992b6b8b09229ff8008cda620548a00e7724d15f;hpb=e2cb0d78aa87b770f39538fda10b63da93accd91;p=clitk.git diff --git a/segmentation/clitkMotionMaskGenericFilter.txx b/segmentation/clitkMotionMaskGenericFilter.txx index 992b6b8..fd21b46 100644 --- a/segmentation/clitkMotionMaskGenericFilter.txx +++ b/segmentation/clitkMotionMaskGenericFilter.txx @@ -520,6 +520,12 @@ MotionMaskGenericFilter::InitializeEllips( typename itk::VectorGetLargestPossibleRegion(); + typename InternalImageType::SizeType size = region_before.GetSize(); + size[2] /= 2; + region.SetSize(size); + lungs_low->SetRegions(region); + // compute statistics of the (mirroed) lung region in order to guess the params of the ellipse typedef itk::LabelImageToShapeLabelMapFilter LabelImageToShapeLabelMapFilter; typename LabelImageToShapeLabelMapFilter::Pointer label_filter = LabelImageToShapeLabelMapFilter::New(); @@ -529,21 +535,28 @@ MotionMaskGenericFilter::InitializeEllips( typename itk::VectorGetSpacing(); typedef typename LabelImageToShapeLabelMapFilter::OutputImageType::LabelObjectType LabelType; const LabelType* label = dynamic_cast(label_filter->GetOutput()->GetNthLabelObject(0)); - - // try to guess ideal ellipse axes from the lungs' bounding box - typename LabelType::RegionType lung_bbox = label->GetRegion(); + // lungs' barycenter + typename LabelType::CentroidType lung_centroid = label->GetCentroid(); + + // try to guess ideal ellipse axes from the lungs' bounding box and centroid + // with some hard-coded "magic" constants... + typename LabelType::RegionType lung_bbox = label->GetBoundingBox(); + axes[0] = 0.95*lung_bbox.GetSize()[0]*spacing[0]/2; axes[1] = 0.3*lung_bbox.GetSize()[1]*spacing[1]/2; - axes[2] = 0.95*lung_bbox.GetSize()[2]*spacing[2]/2; + axes[2] = 1.25*fabs(lung_centroid[2] - center[2]); - // ellipse's center is the center of the lungs' bounding box + // ellipse's center in XY is the center of the lungs' bounding box typename InternalImageType::PointType origin = lungs_low->GetOrigin(); centerEllips[0] = origin[0] + (lung_bbox.GetIndex()[0] + lung_bbox.GetSize()[0]/2)*spacing[0]; centerEllips[1] = origin[1] + (lung_bbox.GetIndex()[1] + lung_bbox.GetSize()[1]/2)*spacing[1]; - centerEllips[2] = origin[2] + (lung_bbox.GetIndex()[2] + lung_bbox.GetSize()[2]/2)*spacing[2]; + centerEllips[2] = center[2]; + + lungs_low->SetRegions(region_before); if(m_Verbose) { + std::cout << "Lungs'centroid at " << lung_centroid << std::endl; std::cout << "Ellipse center at " << centerEllips << std::endl; std::cout << "Ellipse axes as " << axes << std::endl; std::cout << "Lung's bounding box (index,size) " << lung_bbox.GetIndex() << lung_bbox.GetSize() << std::endl;