fuzzy_inpainting.cpp 1.88 KB
Newer Older
tucna's avatar
tucna committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/* Sample - Inpainting
 * Target is to apply inpainting using F-transform
 * on the image "input.png". The image is damaged
 * by various types of corruption:
 *
 * input1 = image & mask1
 * input2 = image & mask2
 * input3 = image & mask3
 *
 * Three algorithms "ft::ONE_STEP", "ft::MULTI_STEP"
 * and "ft::ITERATIVE" are demonstrated on the
 * appropriate type of damage.
 *
 * ft::ONE_STEP
 * "output1_inpaint.png": input1, mask1
 *
 * ft::MULTI_STEP
 * "output2_inpaint.png": input2, mask2
 * "output3_inpaint.png": input3, mask3
 *
 * ft::ITERATIVE
 * "output4_inpaint.png": input3, mask3
 *
 * Linear kernel with radius 2 is used for all
 * samples.
 */

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/fuzzy.hpp"

using namespace std;
using namespace cv;

int main(void)
{
    // Input image
    Mat I = imread("input.png");

    // Various masks
41 42 43
    Mat mask1 = imread("mask1.png", IMREAD_GRAYSCALE);
    Mat mask2 = imread("mask2.png", IMREAD_GRAYSCALE);
    Mat mask3 = imread("mask3.png", IMREAD_GRAYSCALE);
tucna's avatar
tucna committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

    // Apply the damage
    Mat input1, input2, input3;

    I.copyTo(input1, mask1);
    I.copyTo(input2, mask2);
    I.copyTo(input3, mask3);

    // Inpaint with various algorithm
    Mat output1, output2, output3, output4;

    ft::inpaint(input1, mask1, output1, 2, ft::LINEAR, ft::ONE_STEP);
    ft::inpaint(input2, mask2, output2, 2, ft::LINEAR, ft::MULTI_STEP);
    ft::inpaint(input3, mask3, output3, 2, ft::LINEAR, ft::MULTI_STEP);
    ft::inpaint(input3, mask3, output4, 2, ft::LINEAR, ft::ITERATIVE);

    // Save output
    imwrite("output1_inpaint.png", output1);
    imwrite("output2_inpaint.png", output2);
    imwrite("output3_inpaint.png", output3);
    imwrite("output4_inpaint.png", output4);

    // Save damaged input for comparison
    imwrite("input1.png", input1);
    imwrite("input2.png", input2);
    imwrite("input3.png", input3);

    return 0;
}