本文整理汇总了C++中mask::Pointer::InvertData方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::InvertData方法的具体用法?C++ Pointer::InvertData怎么用?C++ Pointer::InvertData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mask::Pointer
的用法示例。
在下文中一共展示了Pointer::InvertData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char*argv[])
{
// Parse the input
if(argc < 6)
{
std::cerr << "Required arguments: image sourceMask.mask targetMask.mask patchRadius output" << std::endl;
return EXIT_FAILURE;
}
std::stringstream ss;
for(int i = 1; i < argc; ++i)
{
ss << argv[i] << " ";
}
std::string imageFilename;
std::string sourceMaskFilename;
std::string targetMaskFilename;
unsigned int patchRadius;
std::string outputFilename;
ss >> imageFilename >> sourceMaskFilename >> targetMaskFilename >> patchRadius >> outputFilename;
// Output the parsed values
std::cout << "imageFilename: " << imageFilename << std::endl
<< "sourceMaskFilename: " << sourceMaskFilename << std::endl
<< "targetMaskFilename: " << targetMaskFilename << std::endl
<< "patchRadius: " << patchRadius << std::endl
<< "outputFilename: " << outputFilename << std::endl;
typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> ImageType;
// Read the image and the masks
typedef itk::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(imageFilename);
imageReader->Update();
ImageType* image = imageReader->GetOutput();
Mask::Pointer sourceMask = Mask::New();
sourceMask->Read(sourceMaskFilename);
Mask::Pointer targetMask = Mask::New();
targetMask->Read(targetMaskFilename);
//std::cout << "target mask has " << targetMask->CountHolePixels() << " hole pixels." << std::endl;
// Poisson fill the input image
typedef PoissonEditing<typename TypeTraits<ImageType::PixelType>::ComponentType> PoissonEditingType;
typename PoissonEditingType::GuidanceFieldType::Pointer zeroGuidanceField =
PoissonEditingType::GuidanceFieldType::New();
zeroGuidanceField->SetRegions(image->GetLargestPossibleRegion());
zeroGuidanceField->Allocate();
typename PoissonEditingType::GuidanceFieldType::PixelType zeroPixel;
zeroPixel.Fill(0);
ITKHelpers::SetImageToConstant(zeroGuidanceField.GetPointer(), zeroPixel);
PoissonEditingType::FillImage(image, targetMask,
zeroGuidanceField.GetPointer(), image);
ITKHelpers::WriteRGBImage(image, "PoissonFilled.png");
// PatchMatch requires that the target region be specified by valid pixels
targetMask->InvertData();
// Setup the patch distance functor
SSD<ImageType> ssdFunctor;
ssdFunctor.SetImage(image);
// Setup the PatchMatch functor
//PatchMatch<ImageType> patchMatchFunctor;
PatchMatchRings<ImageType> patchMatchFunctor;
patchMatchFunctor.SetPatchRadius(patchRadius);
patchMatchFunctor.SetPatchDistanceFunctor(&ssdFunctor);
patchMatchFunctor.SetIterations(1);
InitializerRandom<ImageType> initializer;
initializer.SetImage(image);
initializer.SetTargetMask(targetMask);
initializer.SetSourceMask(sourceMask);
initializer.SetPatchDistanceFunctor(&ssdFunctor);
initializer.SetPatchRadius(patchRadius);
patchMatchFunctor.SetInitializer(&initializer);
// Test the result of PatchMatch here
patchMatchFunctor.SetRandom(false);
// Here, the source match and target match are the same, specifying the classicial
// "use pixels outside the hole to fill the pixels inside the hole".
// In an interactive algorith, the user could manually specify a source region,
// improving the resulting inpainting.
BDSInpaintingMultiRes<ImageType> bdsInpainting;
bdsInpainting.SetPatchRadius(patchRadius);
bdsInpainting.SetImage(image);
bdsInpainting.SetSourceMask(sourceMask);
bdsInpainting.SetTargetMask(targetMask);
bdsInpainting.SetIterations(1);
//.........这里部分代码省略.........
示例2: main
int main(int argc, char*argv[])
{
// Parse the input
if(argc < 6)
{
std::cerr << "Required arguments: image sourceMask.mask targetMask.mask patchRadius output" << std::endl;
return EXIT_FAILURE;
}
std::stringstream ss;
for(int i = 1; i < argc; ++i)
{
ss << argv[i] << " ";
}
std::string imageFilename;
std::string sourceMaskFilename;
std::string targetMaskFilename;
unsigned int patchRadius;
std::string outputFilename;
ss >> imageFilename >> sourceMaskFilename >> targetMaskFilename >> patchRadius >> outputFilename;
// Output the parsed values
std::cout << "imageFilename: " << imageFilename << std::endl
<< "sourceMaskFilename: " << sourceMaskFilename << std::endl
<< "targetMaskFilename: " << targetMaskFilename << std::endl
<< "patchRadius: " << patchRadius << std::endl
<< "outputFilename: " << outputFilename << std::endl;
typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> ImageType;
// Read the image and the masks
typedef itk::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(imageFilename);
imageReader->Update();
ImageType* image = imageReader->GetOutput();
Mask::Pointer sourceMask = Mask::New();
sourceMask->Read(sourceMaskFilename);
Mask::Pointer targetMask = Mask::New();
targetMask->Read(targetMaskFilename);
// Poisson fill the input image in HSV space
typedef itk::Image<itk::CovariantVector<float, 3>, 2> HSVImageType;
HSVImageType::Pointer hsvImage = HSVImageType::New();
ITKVTKHelpers::ConvertRGBtoHSV(image, hsvImage.GetPointer());
ITKHelpers::WriteImage(image, "HSV.mha");
typedef PoissonEditing<typename TypeTraits<HSVImageType::PixelType>::ComponentType> PoissonEditingType;
typename PoissonEditingType::GuidanceFieldType::Pointer zeroGuidanceField =
PoissonEditingType::GuidanceFieldType::New();
zeroGuidanceField->SetRegions(hsvImage->GetLargestPossibleRegion());
zeroGuidanceField->Allocate();
typename PoissonEditingType::GuidanceFieldType::PixelType zeroPixel;
zeroPixel.Fill(0);
ITKHelpers::SetImageToConstant(zeroGuidanceField.GetPointer(), zeroPixel);
PoissonEditingType::FillImage(hsvImage.GetPointer(), targetMask,
zeroGuidanceField.GetPointer(), hsvImage.GetPointer());
ITKHelpers::WriteImage(image, "PoissonFilled_HSV.mha");
ITKVTKHelpers::ConvertHSVtoRGB(hsvImage.GetPointer(), image);
ITKHelpers::WriteRGBImage(image, "PoissonFilled_HSV.png");
// PatchMatch requires that the target region be specified by valid pixels
targetMask->InvertData();
// Here, the source mask and target mask are the same, specifying the classicial
// "use pixels outside the hole to fill the pixels inside the hole".
// In an interactive algorith, the user could manually specify a source region,
// improving the resulting inpainting.
BDSInpaintingRings<ImageType> bdsInpainting;
bdsInpainting.SetPatchRadius(patchRadius);
bdsInpainting.SetImage(image);
bdsInpainting.SetSourceMask(sourceMask);
bdsInpainting.SetTargetMask(targetMask);
bdsInpainting.SetIterations(1);
//bdsInpainting.SetIterations(4);
Compositor<ImageType, PixelCompositorAverage> compositor;
bdsInpainting.Inpaint();
ITKHelpers::WriteRGBImage(bdsInpainting.GetOutput(), outputFilename);
return EXIT_SUCCESS;
}