Commit 408559d6 authored by Bellaktris's avatar Bellaktris

pre-merge

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