fuzzy_inpainting.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Sample - Inpainting
  2. * Target is to apply inpainting using F-transform
  3. * on the image "input.png". The image is damaged
  4. * by various types of corruption:
  5. *
  6. * input1 = image & mask1
  7. * input2 = image & mask2
  8. * input3 = image & mask3
  9. *
  10. * Three algorithms "ft::ONE_STEP", "ft::MULTI_STEP"
  11. * and "ft::ITERATIVE" are demonstrated on the
  12. * appropriate type of damage.
  13. *
  14. * ft::ONE_STEP
  15. * "output1_inpaint.png": input1, mask1
  16. *
  17. * ft::MULTI_STEP
  18. * "output2_inpaint.png": input2, mask2
  19. * "output3_inpaint.png": input3, mask3
  20. *
  21. * ft::ITERATIVE
  22. * "output4_inpaint.png": input3, mask3
  23. *
  24. * Linear kernel with radius 2 is used for all
  25. * samples.
  26. */
  27. #include "opencv2/core.hpp"
  28. #include "opencv2/highgui.hpp"
  29. #include "opencv2/fuzzy.hpp"
  30. using namespace std;
  31. using namespace cv;
  32. int main(void)
  33. {
  34. // Input image
  35. Mat I = imread("input.png");
  36. // Various masks
  37. Mat mask1 = imread("mask1.png", IMREAD_GRAYSCALE);
  38. Mat mask2 = imread("mask2.png", IMREAD_GRAYSCALE);
  39. Mat mask3 = imread("mask3.png", IMREAD_GRAYSCALE);
  40. // Apply the damage
  41. Mat input1, input2, input3;
  42. I.copyTo(input1, mask1);
  43. I.copyTo(input2, mask2);
  44. I.copyTo(input3, mask3);
  45. // Inpaint with various algorithm
  46. Mat output1, output2, output3, output4;
  47. ft::inpaint(input1, mask1, output1, 2, ft::LINEAR, ft::ONE_STEP);
  48. ft::inpaint(input2, mask2, output2, 2, ft::LINEAR, ft::MULTI_STEP);
  49. ft::inpaint(input3, mask3, output3, 2, ft::LINEAR, ft::MULTI_STEP);
  50. ft::inpaint(input3, mask3, output4, 2, ft::LINEAR, ft::ITERATIVE);
  51. // Save output
  52. imwrite("output1_inpaint.png", output1);
  53. imwrite("output2_inpaint.png", output2);
  54. imwrite("output3_inpaint.png", output3);
  55. imwrite("output4_inpaint.png", output4);
  56. // Save damaged input for comparison
  57. imwrite("input1.png", input1);
  58. imwrite("input2.png", input2);
  59. imwrite("input3.png", input3);
  60. return 0;
  61. }