Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e342d2f

Browse filesBrowse files
committed
Local decolor pipeline optimization.
1 parent e813326 commit e342d2f
Copy full SHA for e342d2f

File tree

Expand file treeCollapse file tree

1 file changed

+20
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-10
lines changed

‎modules/photo/src/contrast_preserve.hpp

Copy file name to clipboardExpand all lines: modules/photo/src/contrast_preserve.hpp
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,16 @@ Decolor::Decolor()
113113
sigma = 0.02f;
114114
}
115115

116-
vector<double> Decolor::product(const vector <Vec3i> &comb, const double initRGB[3])
116+
vector<double> Decolor::product(const vector<Vec3i> &comb, const double initRGB[3])
117117
{
118118
vector <double> res(comb.size());
119119
for (size_t i=0;i<comb.size();i++)
120120
{
121121
double dp = 0.0;
122122
for(int j=0;j<3;j++)
123+
{
123124
dp = dp + (comb[i][j] * initRGB[j]);
125+
}
124126
res[i] = dp;
125127
}
126128
return res;
@@ -149,22 +151,20 @@ void Decolor::gradvector(const Mat &img, vector <double> &grad) const
149151
singleChannelGradx(img,dest);
150152
singleChannelGrady(img,dest1);
151153

152-
Mat d_trans=dest.t();
153-
Mat d1_trans=dest1.t();
154-
155-
const int height = d_trans.size().height;
156-
const int width = d_trans.size().width;
154+
// the function uses transposed dest and dest1 here and bellow
155+
const int height = dest.size().width;
156+
const int width = dest.size().height;
157157

158158
grad.resize(width * height * 2);
159159

160160
for(int i=0;i<height;i++)
161161
for(int j=0;j<width;j++)
162-
grad[i*width + j] = d_trans.at<float>(i, j);
162+
grad[i*width + j] = dest.at<float>(j, i);
163163

164164
const int offset = width * height;
165165
for(int i=0;i<height;i++)
166166
for(int j=0;j<width;j++)
167-
grad[offset + i * width + j] = d1_trans.at<float>(i, j);
167+
grad[offset + i * width + j] = dest1.at<float>(j, i);
168168
}
169169

170170
void Decolor::colorGrad(const Mat &img, vector <double> &Cg) const
@@ -277,7 +277,9 @@ void Decolor::grad_system(const Mat &im, vector < vector < double > > &polyGrad,
277277

278278
int idx = 0, idx1 = 0;
279279
for(int r=0 ;r <=order; r++)
280+
{
280281
for(int g=0; g<=order;g++)
282+
{
281283
for(int b =0; b <=order;b++)
282284
{
283285
if((r+g+b)<=order && (r+g+b) > 0)
@@ -293,6 +295,8 @@ void Decolor::grad_system(const Mat &im, vector < vector < double > > &polyGrad,
293295
add_to_vector_poly(polyGrad,curGrad,idx1);
294296
}
295297
}
298+
}
299+
}
296300
}
297301

298302
void Decolor::wei_update_matrix(const vector < vector <double> > &poly, const vector <double> &Cg, Mat &X)
@@ -305,15 +309,15 @@ void Decolor::wei_update_matrix(const vector < vector <double> > &poly, const ve
305309
for (int j = 0; j < size0;j++)
306310
P.at<float>(i,j) = static_cast<float>(poly[i][j]);
307311

308-
const Mat P_trans = P.t();
309312
Mat B = Mat(size, size0, CV_32FC1);
310313
for(int i =0;i < size;i++)
311314
{
312315
for(int j = 0, end = int(Cg.size()); j < end;j++)
313316
B.at<float>(i,j) = static_cast<float>(poly[i][j] * Cg[j]);
314317
}
315318

316-
Mat A = P*P_trans;
319+
Mat A;
320+
mulTransposed(P, A, false);
317321
solve(A, B, X, DECOMP_NORMAL);
318322

319323
}
@@ -352,8 +356,11 @@ void Decolor::grayImContruct(vector <double> &wei, const Mat &img, Mat &Gray) co
352356
int kk =0;
353357

354358
for(int r =0;r<=order;r++)
359+
{
355360
for(int g=0;g<=order;g++)
361+
{
356362
for(int b=0;b<=order;b++)
363+
{
357364
if((r + g + b) <=order && (r+g+b) > 0)
358365
{
359366
for(int i = 0;i<h;i++)
@@ -364,6 +371,9 @@ void Decolor::grayImContruct(vector <double> &wei, const Mat &img, Mat &Gray) co
364371

365372
kk=kk+1;
366373
}
374+
}
375+
}
376+
}
367377

368378
double minval, maxval;
369379
minMaxLoc(Gray, &minval, &maxval);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.