00001 /* 00002 * Copyright (c) 2011, Mårten Björkman (celle@csc.kth.se) 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are 00007 * met: 00008 * 00009 * 1.Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2.Redistributions in binary form must reproduce the above 00012 * copyright notice, this list of conditions and the following 00013 * disclaimer in the documentation and/or other materials provided 00014 * with the distribution. 00015 * 3.The name of Mårten Björkman may not be used to endorse or 00016 * promote products derived from this software without specific 00017 * prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00023 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #ifndef BELIEF_H 00033 #define BELIEF_H 00034 00037 00038 00041 template<int dim = 3> 00042 class BeliefProp { 00044 float *msgl[dim]; 00046 float *msgr[dim]; 00048 float *msgu[dim]; 00050 float *msgd[dim]; 00052 float *prior[dim]; 00054 float *belief[dim]; 00056 float *costh; 00058 float *costv; 00060 int width; 00062 int height; 00063 private: 00065 void InitMessages(); 00067 void ComputeBeliefs(); 00069 void UpdateMessages(); 00070 public: 00072 00075 BeliefProp(int w, int h); 00076 ~BeliefProp(); 00078 00080 float **GetPriors(); 00082 00084 float **GetBeliefs(); 00086 00090 void SetGradientCosts(Image<unsigned char> &img, float gamma); 00092 00095 void Execute(int loops); 00097 00101 void Execute(int loops, int depth); 00103 00106 void ComputeMAP(Image<unsigned char> &mask); 00107 }; 00108 00109 #include "belief.cpp" 00110 00111 #endif // BELIEF_H 00112