Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/src/grabcut.cpp
16354 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// Intel License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "precomp.hpp"
43
#include "opencv2/imgproc/detail/gcgraph.hpp"
44
#include <limits>
45
46
using namespace cv;
47
using namespace detail;
48
49
/*
50
This is implementation of image segmentation algorithm GrabCut described in
51
"GrabCut - Interactive Foreground Extraction using Iterated Graph Cuts".
52
Carsten Rother, Vladimir Kolmogorov, Andrew Blake.
53
*/
54
55
/*
56
GMM - Gaussian Mixture Model
57
*/
58
class GMM
59
{
60
public:
61
static const int componentsCount = 5;
62
63
GMM( Mat& _model );
64
double operator()( const Vec3d color ) const;
65
double operator()( int ci, const Vec3d color ) const;
66
int whichComponent( const Vec3d color ) const;
67
68
void initLearning();
69
void addSample( int ci, const Vec3d color );
70
void endLearning();
71
72
private:
73
void calcInverseCovAndDeterm(int ci, double singularFix);
74
Mat model;
75
double* coefs;
76
double* mean;
77
double* cov;
78
79
double inverseCovs[componentsCount][3][3];
80
double covDeterms[componentsCount];
81
82
double sums[componentsCount][3];
83
double prods[componentsCount][3][3];
84
int sampleCounts[componentsCount];
85
int totalSampleCount;
86
};
87
88
GMM::GMM( Mat& _model )
89
{
90
const int modelSize = 3/*mean*/ + 9/*covariance*/ + 1/*component weight*/;
91
if( _model.empty() )
92
{
93
_model.create( 1, modelSize*componentsCount, CV_64FC1 );
94
_model.setTo(Scalar(0));
95
}
96
else if( (_model.type() != CV_64FC1) || (_model.rows != 1) || (_model.cols != modelSize*componentsCount) )
97
CV_Error( CV_StsBadArg, "_model must have CV_64FC1 type, rows == 1 and cols == 13*componentsCount" );
98
99
model = _model;
100
101
coefs = model.ptr<double>(0);
102
mean = coefs + componentsCount;
103
cov = mean + 3*componentsCount;
104
105
for( int ci = 0; ci < componentsCount; ci++ )
106
if( coefs[ci] > 0 )
107
calcInverseCovAndDeterm(ci, 0.0);
108
totalSampleCount = 0;
109
}
110
111
double GMM::operator()( const Vec3d color ) const
112
{
113
double res = 0;
114
for( int ci = 0; ci < componentsCount; ci++ )
115
res += coefs[ci] * (*this)(ci, color );
116
return res;
117
}
118
119
double GMM::operator()( int ci, const Vec3d color ) const
120
{
121
double res = 0;
122
if( coefs[ci] > 0 )
123
{
124
CV_Assert( covDeterms[ci] > std::numeric_limits<double>::epsilon() );
125
Vec3d diff = color;
126
double* m = mean + 3*ci;
127
diff[0] -= m[0]; diff[1] -= m[1]; diff[2] -= m[2];
128
double mult = diff[0]*(diff[0]*inverseCovs[ci][0][0] + diff[1]*inverseCovs[ci][1][0] + diff[2]*inverseCovs[ci][2][0])
129
+ diff[1]*(diff[0]*inverseCovs[ci][0][1] + diff[1]*inverseCovs[ci][1][1] + diff[2]*inverseCovs[ci][2][1])
130
+ diff[2]*(diff[0]*inverseCovs[ci][0][2] + diff[1]*inverseCovs[ci][1][2] + diff[2]*inverseCovs[ci][2][2]);
131
res = 1.0f/sqrt(covDeterms[ci]) * exp(-0.5f*mult);
132
}
133
return res;
134
}
135
136
int GMM::whichComponent( const Vec3d color ) const
137
{
138
int k = 0;
139
double max = 0;
140
141
for( int ci = 0; ci < componentsCount; ci++ )
142
{
143
double p = (*this)( ci, color );
144
if( p > max )
145
{
146
k = ci;
147
max = p;
148
}
149
}
150
return k;
151
}
152
153
void GMM::initLearning()
154
{
155
for( int ci = 0; ci < componentsCount; ci++)
156
{
157
sums[ci][0] = sums[ci][1] = sums[ci][2] = 0;
158
prods[ci][0][0] = prods[ci][0][1] = prods[ci][0][2] = 0;
159
prods[ci][1][0] = prods[ci][1][1] = prods[ci][1][2] = 0;
160
prods[ci][2][0] = prods[ci][2][1] = prods[ci][2][2] = 0;
161
sampleCounts[ci] = 0;
162
}
163
totalSampleCount = 0;
164
}
165
166
void GMM::addSample( int ci, const Vec3d color )
167
{
168
sums[ci][0] += color[0]; sums[ci][1] += color[1]; sums[ci][2] += color[2];
169
prods[ci][0][0] += color[0]*color[0]; prods[ci][0][1] += color[0]*color[1]; prods[ci][0][2] += color[0]*color[2];
170
prods[ci][1][0] += color[1]*color[0]; prods[ci][1][1] += color[1]*color[1]; prods[ci][1][2] += color[1]*color[2];
171
prods[ci][2][0] += color[2]*color[0]; prods[ci][2][1] += color[2]*color[1]; prods[ci][2][2] += color[2]*color[2];
172
sampleCounts[ci]++;
173
totalSampleCount++;
174
}
175
176
void GMM::endLearning()
177
{
178
CV_Assert(totalSampleCount > 0);
179
for( int ci = 0; ci < componentsCount; ci++ )
180
{
181
int n = sampleCounts[ci];
182
if( n == 0 )
183
coefs[ci] = 0;
184
else
185
{
186
double inv_n = 1.0 / n;
187
coefs[ci] = (double)n/totalSampleCount;
188
189
double* m = mean + 3*ci;
190
m[0] = sums[ci][0] * inv_n; m[1] = sums[ci][1] * inv_n; m[2] = sums[ci][2] * inv_n;
191
192
double* c = cov + 9*ci;
193
c[0] = prods[ci][0][0] * inv_n - m[0]*m[0]; c[1] = prods[ci][0][1] * inv_n - m[0]*m[1]; c[2] = prods[ci][0][2] * inv_n - m[0]*m[2];
194
c[3] = prods[ci][1][0] * inv_n - m[1]*m[0]; c[4] = prods[ci][1][1] * inv_n - m[1]*m[1]; c[5] = prods[ci][1][2] * inv_n - m[1]*m[2];
195
c[6] = prods[ci][2][0] * inv_n - m[2]*m[0]; c[7] = prods[ci][2][1] * inv_n - m[2]*m[1]; c[8] = prods[ci][2][2] * inv_n - m[2]*m[2];
196
197
calcInverseCovAndDeterm(ci, 0.01);
198
}
199
}
200
}
201
202
void GMM::calcInverseCovAndDeterm(int ci, const double singularFix)
203
{
204
if( coefs[ci] > 0 )
205
{
206
double *c = cov + 9*ci;
207
double dtrm = c[0]*(c[4]*c[8]-c[5]*c[7]) - c[1]*(c[3]*c[8]-c[5]*c[6]) + c[2]*(c[3]*c[7]-c[4]*c[6]);
208
if (dtrm <= 1e-6 && singularFix > 0)
209
{
210
// Adds the white noise to avoid singular covariance matrix.
211
c[0] += singularFix;
212
c[4] += singularFix;
213
c[8] += singularFix;
214
dtrm = c[0] * (c[4] * c[8] - c[5] * c[7]) - c[1] * (c[3] * c[8] - c[5] * c[6]) + c[2] * (c[3] * c[7] - c[4] * c[6]);
215
}
216
covDeterms[ci] = dtrm;
217
218
CV_Assert( dtrm > std::numeric_limits<double>::epsilon() );
219
double inv_dtrm = 1.0 / dtrm;
220
inverseCovs[ci][0][0] = (c[4]*c[8] - c[5]*c[7]) * inv_dtrm;
221
inverseCovs[ci][1][0] = -(c[3]*c[8] - c[5]*c[6]) * inv_dtrm;
222
inverseCovs[ci][2][0] = (c[3]*c[7] - c[4]*c[6]) * inv_dtrm;
223
inverseCovs[ci][0][1] = -(c[1]*c[8] - c[2]*c[7]) * inv_dtrm;
224
inverseCovs[ci][1][1] = (c[0]*c[8] - c[2]*c[6]) * inv_dtrm;
225
inverseCovs[ci][2][1] = -(c[0]*c[7] - c[1]*c[6]) * inv_dtrm;
226
inverseCovs[ci][0][2] = (c[1]*c[5] - c[2]*c[4]) * inv_dtrm;
227
inverseCovs[ci][1][2] = -(c[0]*c[5] - c[2]*c[3]) * inv_dtrm;
228
inverseCovs[ci][2][2] = (c[0]*c[4] - c[1]*c[3]) * inv_dtrm;
229
}
230
}
231
232
/*
233
Calculate beta - parameter of GrabCut algorithm.
234
beta = 1/(2*avg(sqr(||color[i] - color[j]||)))
235
*/
236
static double calcBeta( const Mat& img )
237
{
238
double beta = 0;
239
for( int y = 0; y < img.rows; y++ )
240
{
241
for( int x = 0; x < img.cols; x++ )
242
{
243
Vec3d color = img.at<Vec3b>(y,x);
244
if( x>0 ) // left
245
{
246
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y,x-1);
247
beta += diff.dot(diff);
248
}
249
if( y>0 && x>0 ) // upleft
250
{
251
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x-1);
252
beta += diff.dot(diff);
253
}
254
if( y>0 ) // up
255
{
256
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x);
257
beta += diff.dot(diff);
258
}
259
if( y>0 && x<img.cols-1) // upright
260
{
261
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x+1);
262
beta += diff.dot(diff);
263
}
264
}
265
}
266
if( beta <= std::numeric_limits<double>::epsilon() )
267
beta = 0;
268
else
269
beta = 1.f / (2 * beta/(4*img.cols*img.rows - 3*img.cols - 3*img.rows + 2) );
270
271
return beta;
272
}
273
274
/*
275
Calculate weights of noterminal vertices of graph.
276
beta and gamma - parameters of GrabCut algorithm.
277
*/
278
static void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& uprightW, double beta, double gamma )
279
{
280
const double gammaDivSqrt2 = gamma / std::sqrt(2.0f);
281
leftW.create( img.rows, img.cols, CV_64FC1 );
282
upleftW.create( img.rows, img.cols, CV_64FC1 );
283
upW.create( img.rows, img.cols, CV_64FC1 );
284
uprightW.create( img.rows, img.cols, CV_64FC1 );
285
for( int y = 0; y < img.rows; y++ )
286
{
287
for( int x = 0; x < img.cols; x++ )
288
{
289
Vec3d color = img.at<Vec3b>(y,x);
290
if( x-1>=0 ) // left
291
{
292
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y,x-1);
293
leftW.at<double>(y,x) = gamma * exp(-beta*diff.dot(diff));
294
}
295
else
296
leftW.at<double>(y,x) = 0;
297
if( x-1>=0 && y-1>=0 ) // upleft
298
{
299
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x-1);
300
upleftW.at<double>(y,x) = gammaDivSqrt2 * exp(-beta*diff.dot(diff));
301
}
302
else
303
upleftW.at<double>(y,x) = 0;
304
if( y-1>=0 ) // up
305
{
306
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x);
307
upW.at<double>(y,x) = gamma * exp(-beta*diff.dot(diff));
308
}
309
else
310
upW.at<double>(y,x) = 0;
311
if( x+1<img.cols && y-1>=0 ) // upright
312
{
313
Vec3d diff = color - (Vec3d)img.at<Vec3b>(y-1,x+1);
314
uprightW.at<double>(y,x) = gammaDivSqrt2 * exp(-beta*diff.dot(diff));
315
}
316
else
317
uprightW.at<double>(y,x) = 0;
318
}
319
}
320
}
321
322
/*
323
Check size, type and element values of mask matrix.
324
*/
325
static void checkMask( const Mat& img, const Mat& mask )
326
{
327
if( mask.empty() )
328
CV_Error( CV_StsBadArg, "mask is empty" );
329
if( mask.type() != CV_8UC1 )
330
CV_Error( CV_StsBadArg, "mask must have CV_8UC1 type" );
331
if( mask.cols != img.cols || mask.rows != img.rows )
332
CV_Error( CV_StsBadArg, "mask must have as many rows and cols as img" );
333
for( int y = 0; y < mask.rows; y++ )
334
{
335
for( int x = 0; x < mask.cols; x++ )
336
{
337
uchar val = mask.at<uchar>(y,x);
338
if( val!=GC_BGD && val!=GC_FGD && val!=GC_PR_BGD && val!=GC_PR_FGD )
339
CV_Error( CV_StsBadArg, "mask element value must be equal "
340
"GC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD" );
341
}
342
}
343
}
344
345
/*
346
Initialize mask using rectangular.
347
*/
348
static void initMaskWithRect( Mat& mask, Size imgSize, Rect rect )
349
{
350
mask.create( imgSize, CV_8UC1 );
351
mask.setTo( GC_BGD );
352
353
rect.x = std::max(0, rect.x);
354
rect.y = std::max(0, rect.y);
355
rect.width = std::min(rect.width, imgSize.width-rect.x);
356
rect.height = std::min(rect.height, imgSize.height-rect.y);
357
358
(mask(rect)).setTo( Scalar(GC_PR_FGD) );
359
}
360
361
/*
362
Initialize GMM background and foreground models using kmeans algorithm.
363
*/
364
static void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM )
365
{
366
const int kMeansItCount = 10;
367
const int kMeansType = KMEANS_PP_CENTERS;
368
369
Mat bgdLabels, fgdLabels;
370
std::vector<Vec3f> bgdSamples, fgdSamples;
371
Point p;
372
for( p.y = 0; p.y < img.rows; p.y++ )
373
{
374
for( p.x = 0; p.x < img.cols; p.x++ )
375
{
376
if( mask.at<uchar>(p) == GC_BGD || mask.at<uchar>(p) == GC_PR_BGD )
377
bgdSamples.push_back( (Vec3f)img.at<Vec3b>(p) );
378
else // GC_FGD | GC_PR_FGD
379
fgdSamples.push_back( (Vec3f)img.at<Vec3b>(p) );
380
}
381
}
382
CV_Assert( !bgdSamples.empty() && !fgdSamples.empty() );
383
Mat _bgdSamples( (int)bgdSamples.size(), 3, CV_32FC1, &bgdSamples[0][0] );
384
kmeans( _bgdSamples, GMM::componentsCount, bgdLabels,
385
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
386
Mat _fgdSamples( (int)fgdSamples.size(), 3, CV_32FC1, &fgdSamples[0][0] );
387
kmeans( _fgdSamples, GMM::componentsCount, fgdLabels,
388
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
389
390
bgdGMM.initLearning();
391
for( int i = 0; i < (int)bgdSamples.size(); i++ )
392
bgdGMM.addSample( bgdLabels.at<int>(i,0), bgdSamples[i] );
393
bgdGMM.endLearning();
394
395
fgdGMM.initLearning();
396
for( int i = 0; i < (int)fgdSamples.size(); i++ )
397
fgdGMM.addSample( fgdLabels.at<int>(i,0), fgdSamples[i] );
398
fgdGMM.endLearning();
399
}
400
401
/*
402
Assign GMMs components for each pixel.
403
*/
404
static void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, Mat& compIdxs )
405
{
406
Point p;
407
for( p.y = 0; p.y < img.rows; p.y++ )
408
{
409
for( p.x = 0; p.x < img.cols; p.x++ )
410
{
411
Vec3d color = img.at<Vec3b>(p);
412
compIdxs.at<int>(p) = mask.at<uchar>(p) == GC_BGD || mask.at<uchar>(p) == GC_PR_BGD ?
413
bgdGMM.whichComponent(color) : fgdGMM.whichComponent(color);
414
}
415
}
416
}
417
418
/*
419
Learn GMMs parameters.
420
*/
421
static void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGMM, GMM& fgdGMM )
422
{
423
bgdGMM.initLearning();
424
fgdGMM.initLearning();
425
Point p;
426
for( int ci = 0; ci < GMM::componentsCount; ci++ )
427
{
428
for( p.y = 0; p.y < img.rows; p.y++ )
429
{
430
for( p.x = 0; p.x < img.cols; p.x++ )
431
{
432
if( compIdxs.at<int>(p) == ci )
433
{
434
if( mask.at<uchar>(p) == GC_BGD || mask.at<uchar>(p) == GC_PR_BGD )
435
bgdGMM.addSample( ci, img.at<Vec3b>(p) );
436
else
437
fgdGMM.addSample( ci, img.at<Vec3b>(p) );
438
}
439
}
440
}
441
}
442
bgdGMM.endLearning();
443
fgdGMM.endLearning();
444
}
445
446
/*
447
Construct GCGraph
448
*/
449
static void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, double lambda,
450
const Mat& leftW, const Mat& upleftW, const Mat& upW, const Mat& uprightW,
451
GCGraph<double>& graph )
452
{
453
int vtxCount = img.cols*img.rows,
454
edgeCount = 2*(4*img.cols*img.rows - 3*(img.cols + img.rows) + 2);
455
graph.create(vtxCount, edgeCount);
456
Point p;
457
for( p.y = 0; p.y < img.rows; p.y++ )
458
{
459
for( p.x = 0; p.x < img.cols; p.x++)
460
{
461
// add node
462
int vtxIdx = graph.addVtx();
463
Vec3b color = img.at<Vec3b>(p);
464
465
// set t-weights
466
double fromSource, toSink;
467
if( mask.at<uchar>(p) == GC_PR_BGD || mask.at<uchar>(p) == GC_PR_FGD )
468
{
469
fromSource = -log( bgdGMM(color) );
470
toSink = -log( fgdGMM(color) );
471
}
472
else if( mask.at<uchar>(p) == GC_BGD )
473
{
474
fromSource = 0;
475
toSink = lambda;
476
}
477
else // GC_FGD
478
{
479
fromSource = lambda;
480
toSink = 0;
481
}
482
graph.addTermWeights( vtxIdx, fromSource, toSink );
483
484
// set n-weights
485
if( p.x>0 )
486
{
487
double w = leftW.at<double>(p);
488
graph.addEdges( vtxIdx, vtxIdx-1, w, w );
489
}
490
if( p.x>0 && p.y>0 )
491
{
492
double w = upleftW.at<double>(p);
493
graph.addEdges( vtxIdx, vtxIdx-img.cols-1, w, w );
494
}
495
if( p.y>0 )
496
{
497
double w = upW.at<double>(p);
498
graph.addEdges( vtxIdx, vtxIdx-img.cols, w, w );
499
}
500
if( p.x<img.cols-1 && p.y>0 )
501
{
502
double w = uprightW.at<double>(p);
503
graph.addEdges( vtxIdx, vtxIdx-img.cols+1, w, w );
504
}
505
}
506
}
507
}
508
509
/*
510
Estimate segmentation using MaxFlow algorithm
511
*/
512
static void estimateSegmentation( GCGraph<double>& graph, Mat& mask )
513
{
514
graph.maxFlow();
515
Point p;
516
for( p.y = 0; p.y < mask.rows; p.y++ )
517
{
518
for( p.x = 0; p.x < mask.cols; p.x++ )
519
{
520
if( mask.at<uchar>(p) == GC_PR_BGD || mask.at<uchar>(p) == GC_PR_FGD )
521
{
522
if( graph.inSourceSegment( p.y*mask.cols+p.x /*vertex index*/ ) )
523
mask.at<uchar>(p) = GC_PR_FGD;
524
else
525
mask.at<uchar>(p) = GC_PR_BGD;
526
}
527
}
528
}
529
}
530
531
void cv::grabCut( InputArray _img, InputOutputArray _mask, Rect rect,
532
InputOutputArray _bgdModel, InputOutputArray _fgdModel,
533
int iterCount, int mode )
534
{
535
CV_INSTRUMENT_REGION();
536
537
Mat img = _img.getMat();
538
Mat& mask = _mask.getMatRef();
539
Mat& bgdModel = _bgdModel.getMatRef();
540
Mat& fgdModel = _fgdModel.getMatRef();
541
542
if( img.empty() )
543
CV_Error( CV_StsBadArg, "image is empty" );
544
if( img.type() != CV_8UC3 )
545
CV_Error( CV_StsBadArg, "image must have CV_8UC3 type" );
546
547
GMM bgdGMM( bgdModel ), fgdGMM( fgdModel );
548
Mat compIdxs( img.size(), CV_32SC1 );
549
550
if( mode == GC_INIT_WITH_RECT || mode == GC_INIT_WITH_MASK )
551
{
552
if( mode == GC_INIT_WITH_RECT )
553
initMaskWithRect( mask, img.size(), rect );
554
else // flag == GC_INIT_WITH_MASK
555
checkMask( img, mask );
556
initGMMs( img, mask, bgdGMM, fgdGMM );
557
}
558
559
if( iterCount <= 0)
560
return;
561
562
if( mode == GC_EVAL_FREEZE_MODEL )
563
iterCount = 1;
564
565
if( mode == GC_EVAL || mode == GC_EVAL_FREEZE_MODEL )
566
checkMask( img, mask );
567
568
const double gamma = 50;
569
const double lambda = 9*gamma;
570
const double beta = calcBeta( img );
571
572
Mat leftW, upleftW, upW, uprightW;
573
calcNWeights( img, leftW, upleftW, upW, uprightW, beta, gamma );
574
575
for( int i = 0; i < iterCount; i++ )
576
{
577
GCGraph<double> graph;
578
assignGMMsComponents( img, mask, bgdGMM, fgdGMM, compIdxs );
579
if( mode != GC_EVAL_FREEZE_MODEL )
580
learnGMMs( img, mask, compIdxs, bgdGMM, fgdGMM );
581
constructGCGraph(img, mask, bgdGMM, fgdGMM, lambda, leftW, upleftW, upW, uprightW, graph );
582
estimateSegmentation( graph, mask );
583
}
584
}
585
586