Commit 408559d6 authored by Bellaktris's avatar Bellaktris

pre-merge

parent 286d6ffe
**********************************
xphoto. Addon to basic photo modul
**********************************
*****************************
xphoto. Extended photo module
*****************************
.. toctree::
:maxdepth: 2
......
......@@ -95,11 +95,12 @@ public:
};
template <typename Tp, int cn> int KDTree <Tp, cn>::
getMaxSpreadN(const int _left, const int _right) const
getMaxSpreadN(const int left, const int right) const
{
cv::Vec<Tp, cn> maxValue = data[ idx[_left] ],
minValue = data[ idx[_left] ];
for (int i = _left + 1; i < _right; i += cn)
cv::Vec<Tp, cn> maxValue = data[ idx[left] ],
minValue = data[ idx[left] ];
for (int i = left + 1; i < right; ++i)
for (int j = 0; j < cn; ++j)
{
minValue[j] = std::min( minValue[j], data[idx[i]][j] );
......@@ -143,6 +144,7 @@ KDTree(const cv::Mat &img, const int _leafNumber, const int _zeroThresh)
}
int nth = _left + (_right - _left)/2;
int dimIdx = getMaxSpreadN(_left, _right);
KDTreeComparator comp( this, dimIdx );
......@@ -169,7 +171,7 @@ updateDist(const int leaf, const int &idx0, int &bestIdx, double &dist)
abs(nx - x) < zeroThresh)
continue;
if (nx > width - 1 || nx < 1 ||
ny > height - 1 || ny > 1 )
ny > height - 1 || ny < 1 )
continue;
double ndist = norm2(data[idx0], data[idx[k]]);
......@@ -187,6 +189,9 @@ updateDist(const int leaf, const int &idx0, int &bestIdx, double &dist)
static void dominantTransforms(const cv::Mat &img, std::vector <cv::Matx33f> &transforms,
const int nTransform, const int psize)
{
const int zeroThresh = 2*psize;
const int leafNum = 63;
/** Walsh-Hadamard Transformation **/
std::vector <cv::Mat> channels;
......@@ -204,7 +209,7 @@ static void dominantTransforms(const cv::Mat &img, std::vector <cv::Matx33f> &tr
cv::Mat whs; // Walsh-Hadamard series
cv::merge(channels, whs);
KDTree <float, 24> kdTree(whs, 16, 32);
KDTree <float, 24> kdTree(whs, leafNum, zeroThresh);
std::vector <int> annf( whs.total(), 0 );
/** Propagation-assisted kd-tree search **/
......@@ -220,8 +225,8 @@ static void dominantTransforms(const cv::Mat &img, std::vector <cv::Matx33f> &tr
if (i - dy[k] >= 0 && j - dx[k] >= 0)
{
int neighbor = (i - dy[k])*whs.cols + (j - dx[k]);
int leafIdx = k == 0 ? neighbor :
annf[neighbor] + dy[k]*whs.cols + dx[k];
int leafIdx = (dx[k] == 0 && dy[k] == 0)
? neighbor : annf[neighbor] + dy[k]*whs.cols + dx[k];
kdTree.updateDist(leafIdx, current,
annf[i*whs.cols + j], dist);
}
......@@ -232,8 +237,8 @@ static void dominantTransforms(const cv::Mat &img, std::vector <cv::Matx33f> &tr
cv::Mat_<double> annfHist(2*whs.rows - 1, 2*whs.cols - 1, 0.0),
_annfHist(2*whs.rows - 1, 2*whs.cols - 1, 0.0);
for (size_t i = 0; i < annf.size(); ++i)
++annfHist( (annf[i] - int(i))/whs.cols + whs.rows - 1,
(annf[i] - int(i))%whs.cols + whs.cols - 1 );
++annfHist( annf[i]/whs.cols - int(i)/whs.cols + whs.rows - 1,
annf[i]%whs.cols - int(i)%whs.cols + whs.cols - 1 );
cv::GaussianBlur( annfHist, annfHist,
cv::Size(0, 0), std::sqrt(2.0), 0.0, cv::BORDER_CONSTANT);
......@@ -260,13 +265,15 @@ static void dominantTransforms(const cv::Mat &img, std::vector <cv::Matx33f> &tr
std::partial_sort( amount.begin(), amount.begin() + nTransform,
amount.end(), std::greater< std::pair<double, int> >() );
std::ofstream out("C:/Users/Yury/Projects/inpaint/output/log.log");
transforms.resize(nTransform);
for (int i = 0; i < nTransform; ++i)
{
int idx = amount[i].second;
transforms[i] = cv::Matx33f(1, 0, float(shiftM[idx].x),
0, 1, float(shiftM[idx].y),
0, 0, 1 );
0, 0, 1 );
out << int(shiftM[idx].x) << "," << int(shiftM[idx].y) << std::endl;
}
}
......
......@@ -43,6 +43,7 @@
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <time.h>
#include <functional>
......@@ -98,6 +99,7 @@ namespace cv
warpPerspective( masks[0], masks[i + 1], transforms[i],
masks[0].size(), INTER_NEAREST);
cv::imwrite(cv::format("C:/Users/Yury/Projects/inpaint/output/%d.png", i), images[i]);
masks[i + 1] &= invMask;
}
......
......@@ -137,8 +137,11 @@ static void rgb2whs(const cv::Mat &src, cv::Mat &dst, const int nProjections, co
nextProjection(projections, snake_idx[i - 1],
snake_idx[i], npsize);
int pad = 0;
cv::merge(projections, img);
img(cv::Rect(npsize, npsize, src.cols, src.rows)).copyTo(dst);
img(cv::Rect(npsize + pad, npsize + pad, src.cols - pad,
src.rows - pad)).copyTo(dst);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment