MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / main

Function main

dependency/densecrf/examples/dense_inference.cpp:54–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54int main( int argc, char* argv[]){
55 if (argc<4){
56 printf("Usage: %s image annotations output\n", argv[0] );
57 return 1;
58 }
59 // Number of labels
60 const int M = 21;
61 // Load the color image and some crude annotations (which are used in a simple classifier)
62 int W, H, GW, GH;
63 unsigned char * im = readPPM( argv[1], W, H );
64 if (!im){
65 printf("Failed to load image!\n");
66 return 1;
67 }
68 unsigned char * anno = readPPM( argv[2], GW, GH );
69 if (!anno){
70 printf("Failed to load annotations!\n");
71 return 1;
72 }
73 if (W!=GW || H!=GH){
74 printf("Annotation size doesn't match image!\n");
75 return 1;
76 }
77
78 /////////// Put your own unary classifier here! ///////////
79 MatrixXf unary = computeUnary( getLabeling( anno, W*H, M ), M );
80 ///////////////////////////////////////////////////////////
81
82 // Setup the CRF model
83 DenseCRF2D crf(W, H, M);
84 // Specify the unary potential as an array of size W*H*(#classes)
85 // packing order: x0y0l0 x0y0l1 x0y0l2 .. x1y0l0 x1y0l1 ...
86 crf.setUnaryEnergy( unary );
87 // add a color independent term (feature = pixel location 0..W-1, 0..H-1)
88 // x_stddev = 3
89 // y_stddev = 3
90 // weight = 3
91 crf.addPairwiseGaussian( 3, 3, new PottsCompatibility( 3 ) );
92 // add a color dependent term (feature = xyrgb)
93 // x_stddev = 60
94 // y_stddev = 60
95 // r_stddev = g_stddev = b_stddev = 20
96 // weight = 10
97 crf.addPairwiseBilateral( 80, 80, 13, 13, 13, im, new PottsCompatibility( 10 ) );
98
99 // Do map inference
100// MatrixXf Q = crf.startInference(), t1, t2;
101// printf("kl = %f\n", crf.klDivergence(Q) );
102// for( int it=0; it<5; it++ ) {
103// crf.stepInference( Q, t1, t2 );
104// printf("kl = %f\n", crf.klDivergence(Q) );
105// }
106// VectorXs map = crf.currentMap(Q);
107 VectorXs map = crf.map(5);
108 // Store the result
109 unsigned char *res = colorize( map, W, H );
110 writePPM( argv[3], W, H, res );
111

Callers

nothing calls this directly

Calls 9

readPPMFunction · 0.85
getLabelingFunction · 0.85
colorizeFunction · 0.85
writePPMFunction · 0.85
computeUnaryFunction · 0.70
setUnaryEnergyMethod · 0.45
addPairwiseGaussianMethod · 0.45
addPairwiseBilateralMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected