Click here to Skip to main content
15,890,438 members

Comments by mohamed sabri (Top 4 by date)

mohamed sabri 31-Oct-14 12:16pm View    
i don't understant plz more
mohamed sabri 9-Sep-14 9:39am View    
Collapse | Copy Code
void Foreground_SCGMM_movcam::graphcut_fg_decission(ImageRGB & in, ImageGray & out,
Mat_2D_float64 & Prob_fg, Mat_2D_float64 & Prob_bg, float64 lambda)
{
uint64 WIDTH = in.cols;
uint64 HEIGHT = in.rows;

Graph::node_id *pnodes = new Graph::node_id[WIDTH*HEIGHT];


Graph *g = new Graph();

uint64 x,y;

Graph::node_id var;
Graph::node_id qvar;

Graph::captype E0,E1;

uint64 iPixel = 0;
uint64 qPixel =0;




array<int32,2> p,q;

uint64 k;


uint8 pR;
uint8 pG;
uint8 pB;


float64 var_intensity=0;
float64 distance_pq=0;
float64 expon, V_pq;

uint8 qR, qG, qB;

for(y=0;y< HEIGHT;y++)
{
for(x=0;x<width;x++)>
{


p[0] = x;
p[1] = y;

pR=in.data[in.step*(y) + in.channels()* (x) + 2];
pG=in.data[in.step*(y) + in.channels()* (x) + 1];
pB=in.data[in.step*(y) + in.channels()* (x) + 0];

for (k=0; k<neighbor_num;>
{

q[0] = p[0] + NEIGHBORS[k][0];
q[1] = p[1] + NEIGHBORS[k][1];

if ((q[0] >= 0) && (q[1] >=0) && (q[0] < (int64)WIDTH)
&& (q[1] < (int64)HEIGHT) )
{
qR=in.data[in.step*(q[1]) + in.channels()* (q[0]) + 2];
qG=in.data[in.step*(q[1]) + in.channels()* (q[0]) + 1];
qB=in.data[in.step*(q[1]) + in.channels()* (q[0]) + 0];





distance_pq=(pR-qR)*(pR-qR) + (pG-qG)*(pG-qG) + (pB-qB)*(pB-qB);

}

}

var_intensity += distance_pq/NEIGHBOR_NUM;



}
}

var_intensity= var_intensity/(HEIGHT*WIDTH);
printf("\n var_intensity:%E \n", var_intensity);





distance_pq=0;

for(y=0;y< HEIGHT;y++)
for(x=0;x<width;x++)>
{
pnodes[iPixel]= g -> add_node();
iPixel++;
}

iPixel =0;
for(y=0;y<height;y++)>
{
float64* ptr_Prob_bg = (float64*)Prob_bg.data + Prob_bg.cols*uint32(y);
float64* ptr_Prob_fg = (float64*)Prob_fg.data + Prob_fg.cols*uint32(y);

for(x=0;x<width;x++)>
{
p[0] = x;
p[1] = y;

pR=in.data[in.step*(y) + in.channels()* (x) + 2];
pG=in.data[in.step*(y) + in.channels()* (x) + 1];
pB=in.data[in.step*(y) + in.channels()* (x) + 0];

var = pnodes[iPixel];


if(pR == 0) // IF PIXEL IS BACKGROUND /// NO IF si probabilitats
{
E0=0;
E1=1;
}
else
{
E0=1;
E1=0;
}





E0 = (-1)* log(ptr_Prob_bg[Prob_bg.channels()*x]);
E1 = (-1)* log(ptr_Prob_fg[Prob_fg.channels()*x]);

g->add_tweights(var,E0,E1);


if(_lambda != 0.0){
for (k=0; k<neighbor_num;> {
// q = p + NEIGHBORS[k];
q[0] = p[0]+ NEIGHBORS[k][0];
q[1] = p[1] + NEIGHBORS[k][1];



if ((q[0] >= 0) && (q[1] >=0) && (q[0] < (int64)WIDTH)
&& (q[1] < (int64)HEIGHT) )
{
qPixel = q[0] + (q[1]*WIDTH);
qvar = pnodes[qPixel];

// Calcular V(p,q)

qR=in.data[in.step*(q[1]) + in.channels()* (q[0]) + 2];
qG=in.data[in.step*(q[
mohamed sabri 9-Sep-14 9:33am View    
OK I reply this code without commented lines
mohamed sabri 9-Sep-14 9:08am View    
what's the problem exactly?
is it to erase there commented lines