static mitk::Image::Pointer GenerateMaskImage(unsigned int dimX,
                                              unsigned int dimY,
                                              unsigned int dimZ,
                                              float spacingX = 1,
                                              float spacingY = 1,
                                              float spacingZ = 1)
{
  typedef itk::Image< TPixelType, 3 > ImageType;
  typename ImageType::RegionType imageRegion;
  imageRegion.SetSize(0, dimX);
  imageRegion.SetSize(1, dimY);
  imageRegion.SetSize(2, dimZ);
  typename ImageType::SpacingType spacing;
  spacing[0] = spacingX;
  spacing[1] = spacingY;
  spacing[2] = spacingZ;

  mitk::Point3D                       origin; origin.Fill(0.0);
  itk::Matrix<double, 3, 3>           directionMatrix; directionMatrix.SetIdentity();

  typename ImageType::Pointer image = ImageType::New();
  image->SetSpacing( spacing );
  image->SetOrigin( origin );
  image->SetDirection( directionMatrix );
  image->SetLargestPossibleRegion( imageRegion );
  image->SetBufferedRegion( imageRegion );
  image->SetRequestedRegion( imageRegion );
  image->Allocate();
  image->FillBuffer(1);

  mitk::Image::Pointer mitkImage = mitk::Image::New();
  mitkImage->InitializeByItk( image.GetPointer() );
  mitkImage->SetVolume( image->GetBufferPointer() );
  return mitkImage;
}
typename PatchExtractor<PValue>::ImageType::Pointer 
PatchExtractor<PValue>::ExtractPatch()
{
	ContIndexType startIndex;
	for(unsigned int i = 0; i < 2; i++)
	{
		startIndex[i] = m_Center[i] - (m_Size[i] / 2.0);
	}
	startIndex[2] = 0;

	PointType newOrigin;
	m_Image->TransformContinuousIndexToPhysicalPoint(startIndex, newOrigin);


	typename ImageType::Pointer patch = ImageType::New();
	patch->SetDirection(m_Image->GetDirection());
	patch->SetOrigin(newOrigin);
	patch->SetSpacing(m_Image->GetSpacing());
	
	typename ImageType::RegionType region;
	m_Size[2] = 1;
	region.SetSize(m_Size);
	
	patch->SetRegions(region);
	patch->Allocate();

	
	typedef itk::NearestNeighborInterpolateImageFunction<ImageType, double> InterpolatorType;
	typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
	interpolator->SetInputImage(m_Image);


	itk::ImageRegionIterator<ImageType> imageIt(patch, region);
	while(!imageIt.IsAtEnd())
	{
		typename ImageType::IndexType index = imageIt.GetIndex();
		PointType point;
		patch->TransformIndexToPhysicalPoint(index, point);

		if(interpolator->IsInsideBuffer(point))
			imageIt.Set(interpolator->Evaluate(point));
		else
			imageIt.Set(0);
		++imageIt;
	}

	return patch;
	
}
static mitk::Image::Pointer GenerateGradientWithDimXImage(unsigned int dimX,
                                                          unsigned int dimY,
                                                          unsigned int dimZ,
                                                          float spacingX = 1,
                                                          float spacingY = 1,
                                                          float spacingZ = 1)
{
  typedef itk::Image< TPixelType, 3 > ImageType;
  typename ImageType::RegionType imageRegion;
  imageRegion.SetSize(0, dimX);
  imageRegion.SetSize(1, dimY);
  imageRegion.SetSize(2, dimZ);
  typename ImageType::SpacingType spacing;
  spacing[0] = spacingX;
  spacing[1] = spacingY;
  spacing[2] = spacingZ;

  mitk::Point3D                       origin; origin.Fill(0.0);
  itk::Matrix<double, 3, 3>           directionMatrix; directionMatrix.SetIdentity();

  typename ImageType::Pointer image = ImageType::New();
  image->SetSpacing( spacing );
  image->SetOrigin( origin );
  image->SetDirection( directionMatrix );
  image->SetLargestPossibleRegion( imageRegion );
  image->SetBufferedRegion( imageRegion );
  image->SetRequestedRegion( imageRegion );
  image->Allocate();
  image->FillBuffer(0.0);

  typedef itk::ImageRegionIterator<ImageType>      IteratorOutputType;
  IteratorOutputType it(image, imageRegion);
  it.GoToBegin();

  TPixelType val = 0;
  while(!it.IsAtEnd())
  {
    it.Set(val % dimX);
    val++;
    ++it;
  }

  mitk::Image::Pointer mitkImage = mitk::Image::New();
  mitkImage->InitializeByItk( image.GetPointer() );
  mitkImage->SetVolume( image->GetBufferPointer() );
  return mitkImage;
}