@@ -247,14 +247,14 @@ void SuperpixelSLICImpl::initialize()
247
247
// intitialize label storage
248
248
m_klabels = Mat ( m_height, m_width, CV_32S, Scalar::all (0 ) );
249
249
250
- // storage for edge magnitudes
251
- Mat edgemag = Mat ( m_height, m_width, CV_32F, Scalar::all (0 ) );
252
-
253
250
// perturb seeds is not absolutely necessary,
254
251
// one can set this flag to false
255
252
bool perturbseeds = true ;
256
253
257
- if ( perturbseeds ) DetectChEdges ( edgemag );
254
+ // storage for edge magnitudes
255
+ Mat edgemag;
256
+ if (perturbseeds)
257
+ DetectChEdges (edgemag);
258
258
259
259
if ( m_algorithm == SLICO )
260
260
GetChSeedsK ();
@@ -268,7 +268,8 @@ void SuperpixelSLICImpl::initialize()
268
268
m_numlabels = (int )m_kseeds[0 ].size ();
269
269
270
270
// perturb seeds given edges
271
- if ( perturbseeds ) PerturbSeeds ( edgemag );
271
+ if (perturbseeds)
272
+ PerturbSeeds (edgemag);
272
273
273
274
if ( m_algorithm == MSLIC )
274
275
{
@@ -569,12 +570,21 @@ inline void SuperpixelSLICImpl::DetectChEdges( Mat &edgemag )
569
570
Sobel ( m_chvec[c], dy, CV_32F, 0 , 1 , 1 , 1 .0f , 0 .0f , BORDER_DEFAULT );
570
571
571
572
// acumulate ^2 derivate
572
- S_dx = S_dx + dx.mul (dx);
573
- S_dy = S_dy + dy.mul (dy);
574
-
573
+ MatExpr dx2 = dx.mul (dx);
574
+ MatExpr dy2 = dy.mul (dy);
575
+ if (S_dx.empty ())
576
+ {
577
+ S_dx = dx2;
578
+ S_dy = dy2;
579
+ }
580
+ else
581
+ {
582
+ S_dx += dx2;
583
+ S_dy += dy2;
584
+ }
575
585
}
576
586
// total magnitude
577
- edgemag + = S_dx + S_dy;
587
+ edgemag = S_dx + S_dy;
578
588
}
579
589
580
590
/*
0 commit comments