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

Function maxflow3d_inference

maxflow_python/util.cpp:188–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void maxflow3d_inference(unsigned char * label, const float* img, const float * prob, const unsigned char * seed,
189 int D, int H, int W, int chns, int cls, float lambda, float sigma)
190{
191 // currently, only cls == 2 is supported
192 typedef Graph<float, float, float> GraphType;
193 /*estimated # of nodes*/ /*estimated # of edges*/
194 GraphType * g = new GraphType(D*H*W, 2*D*H*W);
195 g->add_node(D*H*W);
196 float max_weight = -100000;
197 for(int x=0; x<D; x++)
198 {
199 for(int y=0; y<H; y++)
200 {
201 for(int z=0; z<W; z++)
202 {
203 std::vector<float> pValue = get_pixel_vector(img, D, H, W, chns, x, y, z);
204 std::vector<float> qValue;
205 float l2dis, n_weight;
206 int pIndex = x*H*W + y*W + z;
207 int qIndex;
208 int xn, yn, zn;
209 int Xoff[3] = {-1, 0, 0};
210 int Yoff[3] = {0, -1, 0};
211 int Zoff[3] = {0, 0, -1};
212 for(int i=0; i<3; i++){
213 xn = x + Xoff[i];
214 yn = y + Yoff[i];
215 zn = z + Zoff[i];
216 if(xn < 0 || yn < 0 || zn < 0) continue;
217 qValue = get_pixel_vector(img, D, H, W, chns, xn, yn, zn);
218 l2dis = get_l2_distance(pValue, qValue);
219 n_weight = lambda*exp(-l2dis * l2dis/(2*sigma*sigma));
220 qIndex = xn*H*W + yn*W + zn;
221 g->add_edge(qIndex,pIndex,n_weight,n_weight);
222 if(n_weight > max_weight) max_weight = n_weight;
223 }
224 }
225 }
226 }
227
228 max_weight = 1000 * max_weight;
229 for(int x=0; x<D; x++)
230 {
231 for(int y=0; y<H; y++)
232 {
233 for(int z=0; z<W; z++)
234 {
235 bool seed_exist = false;
236 float s_weight = 1e-3;
237 float t_weight = 1e-3;
238 if(seed != NULL)
239 {
240 std::vector<unsigned char> label = get_pixel_vector(seed, D, H, W, 2, x, y, z);
241 if(label[0] > 0){
242 t_weight = max_weight;
243 seed_exist = true;
244 }
245 else if(label[1] > 0){

Callers 2

maxflow3d_wrapperFunction · 0.85

Calls 9

get_pixel_vectorFunction · 0.85
get_l2_distanceFunction · 0.85
add_nodeMethod · 0.80
add_edgeMethod · 0.80
add_tweightsMethod · 0.80
maxflowMethod · 0.80
what_segmentMethod · 0.80
expFunction · 0.50
logFunction · 0.50

Tested by

no test coverage detected