26 #include "drwnVision.h"
49 cv::Mat drwnBasicPatchMatch(
const cv::Mat& imgA,
const cv::Mat& imgB,
50 const cv::Size& patchRadius, cv::Mat& nnfA,
unsigned maxIterations = 2);
56 cv::Mat drwnSelfPatchMatch(
const cv::Mat& imgA,
const cv::Size& patchRadius,
57 cv::Mat& nnfA,
double illegalOverlap = 0.0,
unsigned maxIterations = 2);
70 cv::Mat drwnNNFRepaint(
const cv::Mat& img,
const cv::Mat& nnf);
142 const cv::Mat& maskB,
unsigned patchRadius);
145 const cv::Mat& maskB,
const cv::Size& patchRadius);
158 cv::Size
getPatchSize()
const {
return cv::Size(2 * _patchRadius.width + 1, 2 * _patchRadius.height + 1); }
163 std::pair<cv::Rect, cv::Rect> getMatchingPatches(
const cv::Point& ptA)
const;
168 void initialize(
const cv::Size& patchRadius);
170 void initialize(
const cv::Mat& nnf);
174 const cv::Mat&
search(
unsigned maxIterations = 1) {
175 return search(cv::Rect(0, 0, _nnfA.cols, _nnfA.rows), maxIterations);
180 const cv::Mat& search(cv::Rect roiToUpdate,
unsigned maxIterations = 1);
183 const cv::Mat&
nnf()
const {
return _nnfA; }
185 const cv::Mat&
costs()
const {
return _costsA; }
187 double energy()
const {
return cv::norm(_costsA, cv::NORM_L1, _maskA); }
191 void modifySourceImage(
const cv::Rect& roi,
const cv::Mat& img,
double alpha = 0.0);
194 void modifySourceImage(
const cv::Rect& roiA,
const cv::Rect& roiB,
double alpha = 0.0);
197 void modifyTargetImage(
const cv::Rect& roi,
const cv::Mat& img,
double alpha = 0.0);
200 void modifyTargetImage(
const cv::Rect& roiA,
const cv::Rect& roiB,
double alpha = 0.0);
204 void expandTargetMask(
unsigned radius = 1);
209 cv::Mat visualize()
const;
213 bool update(
const cv::Point& ptA,
const cv::Point& ptB);
215 float score(
const cv::Point& ptA,
const cv::Point& ptB)
const;
219 const int y1 = std::max(modified.y - _patchRadius.height, _patchRadius.height);
220 const int x1 = std::max(modified.x - _patchRadius.width, _patchRadius.width);
221 const int y2 = std::min(modified.y + modified.height + _patchRadius.height, _nnfA.rows - _patchRadius.height);
222 const int x2 = std::min(modified.x + modified.width + _patchRadius.width, _nnfA.cols - _patchRadius.width);
223 return cv::Rect(x1, y1, x2 - x1, y2 - y1);
230 void rescore(
const cv::Rect& roi);
233 void cacheValidPixels();
237 void updateValidPixels(
const cv::Rect& roi);
cv::Mat _lastChanged
last iteration that given patch was changed
Definition: drwnMaskedPatchMatch.h:133
int _iterationCount
total number of iterations since initialization
Definition: drwnMaskedPatchMatch.h:132
Implements the basic PatchMatch algorithm of Barnes et al., SIGGRAPH 2009 on masked images...
Definition: drwnMaskedPatchMatch.h:111
double energy() const
return the current match energy
Definition: drwnMaskedPatchMatch.h:187
cv::Mat _invmaskA
CV_8UC1 inverse of _maskA.
Definition: drwnMaskedPatchMatch.h:122
static int DISTANCE_MEASURE
norm type for comparing patches (cv::NORM_L1 or cv::NORM_L2)
Definition: drwnMaskedPatchMatch.h:114
cv::Size _patchRadius
size of patch is 2 * _patchRadius + 1
Definition: drwnMaskedPatchMatch.h:128
const cv::Mat & nnf() const
return the current nearest neighbour field
Definition: drwnMaskedPatchMatch.h:183
cv::Size getPatchSize() const
return the patch size
Definition: drwnMaskedPatchMatch.h:158
cv::Mat _maskB
CV_8UC1 mask for valid target pixels.
Definition: drwnMaskedPatchMatch.h:121
const cv::Mat & getSourceMask() const
return the source mask
Definition: drwnMaskedPatchMatch.h:154
cv::Mat _nnfA
CV_16S2 nearest neighbour field (size _imgA)
Definition: drwnMaskedPatchMatch.h:129
cv::Mat _overlapA
pixels in _imgA whose patch overlaps with _invmaskA
Definition: drwnMaskedPatchMatch.h:125
void rescore()
update scores on whole image
Definition: drwnMaskedPatchMatch.h:227
cv::Size getFieldSize() const
return the size of the nearest neighbour field
Definition: drwnMaskedPatchMatch.h:160
const cv::Mat & costs() const
return (matching) costs (CV_32FC1) associated with the current nearest neighbour field ...
Definition: drwnMaskedPatchMatch.h:185
const cv::Mat & getSourceImage() const
return the source image
Definition: drwnMaskedPatchMatch.h:150
virtual ~drwnMaskedPatchMatch()
destructor
Definition: drwnMaskedPatchMatch.h:147
const cv::Mat & getTargetImage() const
return the target image
Definition: drwnMaskedPatchMatch.h:152
cv::Mat _imgB
CV_8U multi-channel image (target)
Definition: drwnMaskedPatchMatch.h:119
const cv::Mat & getTargetMask() const
return the target mask
Definition: drwnMaskedPatchMatch.h:156
static bool TRY_IDENTITY_INIT
attempt identity match during initialization (default: true)
Definition: drwnMaskedPatchMatch.h:113
void initialize()
initialize the matches with default patch size
Definition: drwnMaskedPatchMatch.h:166
cv::Mat _imgA
CV_8U multi-channel image (source)
Definition: drwnMaskedPatchMatch.h:118
cv::Mat _invmaskB
CV_8UC1 inverse of _maskB.
Definition: drwnMaskedPatchMatch.h:123
cv::Mat _costsA
CV_32FC1 field of match costs (same size as _nnfA)
Definition: drwnMaskedPatchMatch.h:130
cv::Rect affectedRegion(const cv::Rect &modified) const
calculate nnf pixels affected by a mask or image modification
Definition: drwnMaskedPatchMatch.h:218
cv::Mat _maskA
CV_8UC1 mask for valid source pixels.
Definition: drwnMaskedPatchMatch.h:120
cv::Mat _validB
pixels in _imgB whose patch doesn't overlap with _maskB
Definition: drwnMaskedPatchMatch.h:126
static float HEIGHT_PENALTY
bias term added for row/height difference
Definition: drwnMaskedPatchMatch.h:115
const cv::Mat & search(unsigned maxIterations=1)
Search for better matches and return updated nearest neighbour field. The nearest neighbour field map...
Definition: drwnMaskedPatchMatch.h:174