예제 #1
0
typename PatchExtractor<PValue>::MaskType::Pointer PatchExtractor<PValue>::ExtractMask()
{
	ContIndexType startIndex;
	for(unsigned int i = 0; i < 2; i++)
	{
		startIndex[i] = m_Center[i] - (m_Size[i] / 2.0);
	}
	startIndex[2] = 0;


	typename ImageType::IndexType properIndex;
	for(unsigned int i = 0; i < 3; i++)
	{
		properIndex[i] = round(startIndex[i]);
	}

	for(unsigned int i = 0; i < 2; i++)
	{
		if(properIndex[i] < 0) properIndex[i] = 0;
		if((m_Size[i] + properIndex[i]) > (m_Image->GetLargestPossibleRegion().GetSize()[i]-1))
		{
			m_Size[i] = m_Image->GetLargestPossibleRegion().GetSize()[i]-1-properIndex[i];
		}
	}
	
	MaskType::RegionType region;
	region.SetIndex(properIndex);
	m_Size[2] = 1;
	region.SetSize(m_Size);

	MaskType::Pointer mask = MaskType::New();
	mask->SetDirection(m_Image->GetDirection());
	mask->SetSpacing(m_Image->GetSpacing());
	mask->SetOrigin(m_Image->GetOrigin());
	mask->SetRegions(m_Image->GetLargestPossibleRegion());
	mask->Allocate();
	mask->FillBuffer(0);

	itk::ImageRegionIterator<MaskType> imageIt(mask, region);
	while(!imageIt.IsAtEnd())
	{
		imageIt.Set(m_MaskValue);
		++imageIt;
	}

	return mask;
}
예제 #2
0
itk::Image<unsigned char, 3>::Pointer pdp::EMClassification::classify(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{
	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MaskType::Pointer correctImage = MaskType::New();
	correctImage->CopyInformation(mask);
	MaskType::RegionType outputRegion = mask->GetLargestPossibleRegion();
	correctImage->SetRegions( outputRegion );
	correctImage->Allocate();
	typedef itk::ImageRegionIterator<MaskType> IteratorType;
	IteratorType outputIt( correctImage, outputRegion);

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(), outputIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt, ++outputIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			if (genLabel(mv) == 3)
			{
				outputIt.Set(255);
			}
		}
	}

	return correctImage;
}