Zavolokas.ImageProcessing.PatchMatch 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zavolokas.ImageProcessing.PatchMatch --version 1.0.5
NuGet\Install-Package Zavolokas.ImageProcessing.PatchMatch -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zavolokas.ImageProcessing.PatchMatch" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zavolokas.ImageProcessing.PatchMatch --version 1.0.5
#r "nuget: Zavolokas.ImageProcessing.PatchMatch, 1.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Zavolokas.ImageProcessing.PatchMatch as a Cake Addin
#addin nuget:?package=Zavolokas.ImageProcessing.PatchMatch&version=1.0.5

// Install Zavolokas.ImageProcessing.PatchMatch as a Cake Tool
#tool nuget:?package=Zavolokas.ImageProcessing.PatchMatch&version=1.0.5

PatchMatch

license

Implementation of PatchMatch algorithm for .NET.

What is PatchMatch?

This is an algorithm that finds similar patches at given images and builds a nearest neighbor field (NNF).

The main advantage of the algorithm is that it is quite fast. It is based on the observations that some of the good matches can be found randomly and that these results can be propagated to the neighbour areas due to natural coherence of images.

More information can be found in this scientific publication.

What is it for?

It can be used in image processing and image editing tools (inpainting, image reshuffling, content aware image resizing etc).

How to use it?

In a nutshell PatchMatch algorithm consists of:

  • random initialization step of NNF
  • a number of search iterations

PatchMatchNnfBuilder class defines two corresponding methods:

  • RunRandomNnfInitIteration
  • RunBuildNnfIteration

Both these methods take as arguments:

  • An instance of an NNF
  • An image to build NNF for (destination)
  • An image that is a source of patches for the destination image
  • Settings that control algorithm execution

Examples

Simple NNF

var settings = new PatchMatchSettings { PatchSize = 5 };
// Create an NNF
var nnf = new Nnf(destImage.Width, destImage.Height, srcImage.Width, srcImage.Height, settings.PatchSize);

var patchMatchNnfBuilder = new PatchMatchNnfBuilder();

// NNF initialization step
patchMatchNnfBuilder.RunRandomNnfInitIteration(nnf, destImage, srcImage, settings);

// Few iterations of NNF building in altering directions.
patchMatchNnfBuilder.RunBuildNnfIteration(nnf, destImage, srcImage, NeighboursCheckDirection.Forward, settings);
patchMatchNnfBuilder.RunBuildNnfIteration(nnf, destImage, srcImage, NeighboursCheckDirection.Backward, settings);
patchMatchNnfBuilder.RunBuildNnfIteration(nnf, destImage, srcImage, NeighboursCheckDirection.Forward, settings);
patchMatchNnfBuilder.RunBuildNnfIteration(nnf, destImage, srcImage, NeighboursCheckDirection.Backward, settings);
patchMatchNnfBuilder.RunBuildNnfIteration(nnf, destImage, srcImage, NeighboursCheckDirection.Forward, settings);

// Restore dest image from the NNF and source image.
nnf
    .RestoreImage(srcImage, 3, patchSize)
    .FromLabToRgb()
    .FromRgbToBitmap()
    .SaveTo(@"..\..\restored.png", ImageFormat.Png);

// Convert the NNF to an image and save.
nnf
    .ToRgbImage()
    .FromRgbToBitmap()
    .SaveTo(@"..\..\nnf.png", ImageFormat.Png);

Dest image Source image
input1 input2
NNF Restored image
nnf restored

Advanced NNF building

It is also possible to provide a mapping of particular areas on both dest and source images to be used or ignored.

var mappings = new Area2DMapBuilder()
    .InitNewMap(destImageArea, srcImageArea) // define area on the source that is used to get patches for the dest area
    .AddAssociatedAreas(destImageArea1, srcImageArea1)) // defaine exceptional dest area for 
                                                        // which patches should be found in the specified source area
    .AddAssociatedAreas(destImageArea2, srcImageArea2)
    .SetIgnoredSourcedArea(srcImageAreaToIgnore) // this area on the source will be ignored
    .Build();

| Ignored source areas | Result image | | ----------- | ------ | | ignoredSrc | ignoredSrcResult| NOTE: All the yellowish parts are restored using other colors.

| Destination area | NNF | Result image| | ----------- | ------ | ------ | | destArea | destNnf | destAreaResult| NOTE: NNF was built only for the specified dest area.

Dest image with donor areas Source image with donor areas
destDonors srcDonors
NNF Restored image
donorsNnf donorsResult
Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Zavolokas.ImageProcessing.PatchMatch:

Package Downloads
Zavolokas.ImageProcessing.Parallel

Package Description

Zavolokas.ImageProcessing.Inpainting

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Zavolokas.ImageProcessing.PatchMatch:

Repository Stars
zavolokas/Inpainting
Want to remove something(someone) from a photo as it never was there? This is .NET implementation of content-aware fill. It smartly fills in unwanted or missing areas of photographs.
Version Downloads Last updated
2.0.0.3 1,749 11/2/2019
1.0.7 1,945 3/4/2018
1.0.6 868 3/4/2018
1.0.5 826 2/20/2018
1.0.4 803 2/13/2018
1.0.2 778 2/6/2018
1.0.0 1,017 12/18/2017