Skip to content

Commit e67653e

Browse files
si40wigaalalek
authored andcommitted
Merge pull request #2296 from si40wiga:fsr-inpaint
* new algorithm Rapid Frequency Selective Reconstruction (FSR) added * fix compiler warning * applied changes suggested in alalek's review * fix trailing whitespace * xphoto: update inpaint() test * fix pre-processing of error mask * xphoto: move inpainting FSR algorithm into a separate file * xphoto: cleanup inpaining documentation * xphoto: inpainting fsr - avoid uninitialized values
1 parent 7d7312a commit e67653e

File tree

5 files changed

+1022
-23
lines changed

5 files changed

+1022
-23
lines changed

modules/xphoto/doc/xphoto.bib

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,49 @@ @inproceedings{DD02
2929
publisher = {ACM},
3030
url = {https://www.researchgate.net/profile/Julie_Dorsey/publication/220184746_Fast_Bilateral_Filtering_for_the_Display_of_High_-_dynamic_-_range_Images/links/54566b000cf26d5090a95f96/Fast-Bilateral-Filtering-for-the-Display-of-High-dynamic-range-Images.pdf}
3131
}
32+
33+
@INPROCEEDINGS{GenserPCS2018,
34+
author={N. {Genser} and J. {Seiler} and F. {Schilling} and A. {Kaup}},
35+
booktitle={Proc. Picture Coding Symposium (PCS)},
36+
title={Signal and Loss Geometry Aware Frequency Selective Extrapolation for Error Concealment},
37+
year={2018},
38+
pages={159-163},
39+
keywords={extrapolation;image reconstruction;video coding;loss geometry aware frequency selective extrapolation;error concealment;complex models;moderate computational complexity;Full HD image;error pattern;adjacent samples;undistorted samples;reconstruction parameters;processing order;High Efficiency Video Coding;content based partitioning;signal characteristics;block based frequency selective extrapolation;Image reconstruction;Extrapolation;Geometry;Partitioning algorithms;Task analysis;Computational modeling;Standards},
40+
doi={10.1109/PCS.2018.8456259},
41+
month={June},
42+
}
43+
44+
@ARTICLE{SeilerTIP2015,
45+
author={J. {Seiler} and M. {Jonscher} and M. {Schöberl} and A. {Kaup}},
46+
journal={IEEE Transactions on Image Processing},
47+
title={Resampling Images to a Regular Grid From a Non-Regular Subset of Pixel Positions Using Frequency Selective Reconstruction},
48+
year={2015},
49+
volume={24},
50+
number={11},
51+
pages={4540-4555},
52+
keywords={Fourier transforms;image reconstruction;resampling images;regular grid;nonregular subset;pixel positions;frequency selective reconstruction;displaying image signals;image signal reconstruction algorithm;Fourier domain;optical transfer function;visual quality;peak signal-to-noise ratio;Image reconstruction;Signal processing algorithms;Reconstruction algorithms;Signal processing;Spatial resolution;;Image reconstruction;non-regular sampling;interpolation},
53+
doi={10.1109/TIP.2015.2463084},
54+
month={Nov},
55+
}
56+
57+
@INPROCEEDINGS{GroscheICIP2018,
58+
author={S. {Grosche} and J. {Seiler} and A. {Kaup}},
59+
booktitle={Proc. 25th IEEE International Conference on Image Processing (ICIP)},
60+
title={Iterative Optimization of Quarter Sampling Masks for Non-Regular Sampling Sensors},
61+
year={2018},
62+
pages={26-30},
63+
keywords={extrapolation;image enhancement;image reconstruction;image resolution;image sampling;image sensors;interpolation;iterative methods;optimisation;regression analysis;iterative optimization;nonregular sampling sensors;iterative algorithm;arbitrary quarter sampling mask;reconstruction algorithms;random quarter sampling mask;optimized mask;frequency selective extrapolation;steering kernel regression;nearest neighbor interpolation;linear interpolation;regular imaging sensor;reconstruction quality;noise figure 0.31 dB to 0.68 dB;Image resolution;Image reconstruction;Sensors;Optimization;Energy resolution;Reconstruction algorithms;Image sensors;Non-Regular Sampling;Image reconstruction},
64+
doi={10.1109/ICIP.2018.8451658},
65+
month={Oct},
66+
}
67+
68+
@INPROCEEDINGS{GroscheIST2018,
69+
author={S. {Grosche} and J. {Seiler} and A. {Kaup}},
70+
booktitle={Proc. IEEE International Conference on Imaging Systems and Techniques (IST)},
71+
title={Design Techniques for Incremental Non-Regular Image Sampling Patterns},
72+
year={2018},
73+
pages={1-6},
74+
keywords={image reconstruction;image resolution;image sampling;design techniques;incremental nonregular image sampling patterns;image signals;regular two dimensional grid;nonregular sampling patterns;sampling positions;random patterns;regular patterns;arbitrary sampling densities;incremental sampling patterns;sampling density;Image reconstruction;Scanning electron microscopy;Probability distribution;Atomic force microscopy;Reconstruction algorithms;Measurement by laser beam;Image Reconstruction;non-Regular Sampling},
75+
doi={10.1109/IST.2018.8577090},
76+
month={Oct},
77+
}

modules/xphoto/include/opencv2/xphoto/inpainting.hpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
//
1010
// License Agreement
1111
// For Open Source Computer Vision Library
12+
// (3-clause BSD License)
1213
//
13-
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14+
// Copyright (C) 2000-2019, Intel Corporation, all rights reserved.
1415
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
16+
// Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
17+
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
18+
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
19+
// Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
1520
// Third party copyrights are property of their respective owners.
1621
//
1722
// Redistribution and use in source and binary forms, with or without modification,
@@ -24,8 +29,9 @@
2429
// this list of conditions and the following disclaimer in the documentation
2530
// and/or other materials provided with the distribution.
2631
//
27-
// * The name of the copyright holders may not be used to endorse or promote products
28-
// derived from this software without specific prior written permission.
32+
// * Neither the names of the copyright holders nor the names of the contributors
33+
// may be used to endorse or promote products derived from this software
34+
// without specific prior written permission.
2935
//
3036
// This software is provided by the copyright holders and contributors "as is" and
3137
// any express or implied warranties, including, but not limited to, the implied
@@ -58,24 +64,48 @@ namespace xphoto
5864
//! @addtogroup xphoto
5965
//! @{
6066

61-
//! various inpainting algorithms
67+
//! @brief Various inpainting algorithms
68+
//! @sa inpaint
6269
enum InpaintTypes
6370
{
6471
/** This algorithm searches for dominant correspondences (transformations) of
6572
image patches and tries to seamlessly fill-in the area to be inpainted using this
6673
transformations */
67-
INPAINT_SHIFTMAP = 0
74+
INPAINT_SHIFTMAP = 0,
75+
/** Performs Frequency Selective Reconstruction (FSR).
76+
One of the two quality profiles BEST and FAST can be chosen, depending on the time available for reconstruction.
77+
See @cite GenserPCS2018 and @cite SeilerTIP2015 for details.
78+
79+
The algorithm may be utilized for the following areas of application:
80+
1. %Error Concealment (Inpainting).
81+
The sampling mask indicates the missing pixels of the distorted input
82+
image to be reconstructed.
83+
2. Non-Regular Sampling.
84+
For more information on how to choose a good sampling mask, please review
85+
@cite GroscheICIP2018 and @cite GroscheIST2018.
86+
87+
1-channel grayscale or 3-channel BGR image are accepted.
88+
89+
Conventional accepted ranges:
90+
- 0-255 for CV_8U
91+
- 0-65535 for CV_16U
92+
- 0-1 for CV_32F/CV_64F.
93+
*/
94+
INPAINT_FSR_BEST = 1,
95+
INPAINT_FSR_FAST = 2 //!< See #INPAINT_FSR_BEST
6896
};
6997

7098
/** @brief The function implements different single-image inpainting algorithms.
7199
72-
See the original paper @cite He2012 for details.
100+
See the original papers @cite He2012 (Shiftmap) or @cite GenserPCS2018 and @cite SeilerTIP2015 (FSR) for details.
73101
74-
@param src source image, it could be of any type and any number of channels from 1 to 4. In case of
102+
@param src source image
103+
- #INPAINT_SHIFTMAP: it could be of any type and any number of channels from 1 to 4. In case of
75104
3- and 4-channels images the function expect them in CIELab colorspace or similar one, where first
76105
color component shows intensity, while second and third shows colors. Nonetheless you can try any
77106
colorspaces.
78-
@param mask mask (CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels
107+
- #INPAINT_FSR_BEST or #INPAINT_FSR_FAST: 1-channel grayscale or 3-channel BGR image.
108+
@param mask mask (#CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels
79109
indicate area to be inpainted
80110
@param dst destination image
81111
@param algorithmType see xphoto::InpaintTypes

modules/xphoto/src/inpainting.cpp

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@
99
//
1010
// License Agreement
1111
// For Open Source Computer Vision Library
12+
// (3-clause BSD License)
1213
//
13-
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14+
// Copyright (C) 2000-2019, Intel Corporation, all rights reserved.
1415
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
16+
// Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
17+
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
18+
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
19+
// Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
1520
// Third party copyrights are property of their respective owners.
1621
//
22+
// Redistribution and use in source and binary forms, with or without modification,
23+
// are permitted provided that the following conditions are met:
24+
//
1725
// * Redistribution's of source code must retain the above copyright notice,
1826
// this list of conditions and the following disclaimer.
1927
//
2028
// * Redistribution's in binary form must reproduce the above copyright notice,
2129
// this list of conditions and the following disclaimer in the documentation
2230
// and/or other materials provided with the distribution.
2331
//
24-
// * The name of Intel Corporation may not be used to endorse or promote products
25-
// derived from this software without specific prior written permission.
32+
// * Neither the names of the copyright holders nor the names of the contributors
33+
// may be used to endorse or promote products derived from this software
34+
// without specific prior written permission.
2635
//
2736
// This software is provided by the copyright holders and contributors "as is" and
2837
// any express or implied warranties, including, but not limited to, the implied
@@ -46,6 +55,8 @@
4655
#include <fstream>
4756
#include <time.h>
4857
#include <functional>
58+
#include <string>
59+
#include <tuple>
4960

5061
#include "opencv2/xphoto.hpp"
5162

@@ -62,6 +73,8 @@
6273
#include "annf.hpp"
6374
#include "advanced_types.hpp"
6475

76+
#include "inpainting_fsr.impl.hpp"
77+
6578
namespace cv
6679
{
6780
namespace xphoto
@@ -298,17 +311,9 @@ namespace xphoto
298311
}
299312
}
300313

301-
/*! The function reconstructs the selected image area from known area.
302-
* \param src : source image.
303-
* \param mask : inpainting mask, 8-bit 1-channel image. Zero pixels indicate the area that needs to be inpainted.
304-
* \param dst : destination image.
305-
* \param algorithmType : inpainting method.
306-
*/
307-
void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType)
314+
static
315+
void inpaint_shiftmap(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType)
308316
{
309-
CV_Assert( mask.channels() == 1 && mask.depth() == CV_8U );
310-
CV_Assert( src.rows == mask.rows && src.cols == mask.cols );
311-
312317
switch ( src.type() )
313318
{
314319
case CV_8SC1:
@@ -399,8 +404,25 @@ namespace xphoto
399404
CV_Error_( CV_StsNotImplemented,
400405
("Unsupported source image format (=%d)",
401406
src.type()) );
402-
break;
403407
}
404408
}
409+
410+
void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType)
411+
{
412+
CV_Assert(!src.empty());
413+
CV_Assert(!mask.empty());
414+
CV_CheckTypeEQ(mask.type(), CV_8UC1, "");
415+
CV_Assert(src.rows == mask.rows && src.cols == mask.cols);
416+
417+
switch (algorithmType)
418+
{
419+
case xphoto::INPAINT_SHIFTMAP:
420+
return inpaint_shiftmap(src, mask, dst, algorithmType);
421+
case xphoto::INPAINT_FSR_BEST:
422+
case xphoto::INPAINT_FSR_FAST:
423+
return inpaint_fsr(src, mask, dst, algorithmType);
424+
}
425+
CV_Error_(Error::StsNotImplemented, ("Unsupported inpainting algorithm type (=%d)", algorithmType));
405426
}
406-
}
427+
428+
}} // namespace

0 commit comments

Comments
 (0)