Пример #1
0
Mat CmSaliencyRC::GetRC(CMat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma)
{
	Mat imgLab3f, regIdx1i;
	cvtColor(img3f, imgLab3f, CV_BGR2Lab);
	int regNum = SegmentImage(imgLab3f, regIdx1i, segSigma, segK, segMinSize);	
	return GetRC(img3f, regIdx1i, regNum, sigmaDist);
}
Mat RegionSaliency::GetRCNoColorConversion(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma)
{
	Mat regIdx1i, colorIdx1i, regSal1v, tmp, _img3f, color3fv;
	if (Quantize(img3f, colorIdx1i, color3fv, tmp) <= 2) // Color quantization
		return Mat::zeros(img3f.size(), CV_32F);
  _img3f = img3f.clone();
// 	cvtColor(img3f, _img3f, CV_BGR2Lab);
// 	cvtColor(color3fv, color3fv, CV_BGR2Lab);
	int regNum = SegmentImage(_img3f, regIdx1i, segSigma, segK, segMinSize);	
	vector<Region> regs(regNum);
	BuildRegions(regIdx1i, regs, colorIdx1i, color3fv.cols);
	RegionContrast(regs, color3fv, regSal1v, sigmaDist);

	Mat sal1f = Mat::zeros(img3f.size(), CV_32F);
	cv::normalize(regSal1v, regSal1v, 0, 1, NORM_MINMAX, CV_32F);
	float* regSal = (float*)regSal1v.data;
	for (int r = 0; r < img3f.rows; r++){
		const int* regIdx = regIdx1i.ptr<int>(r);
		float* sal = sal1f.ptr<float>(r);
		for (int c = 0; c < img3f.cols; c++)
			sal[c] = regSal[regIdx[c]];
	}
	GaussianBlur(sal1f, sal1f, Size(3, 3), 0);
	return sal1f;
}
Mat RegionSaliency::GetRCCB(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma, 
        double centerBiasWeight, double centerBiasHeightSigma, double centerBiasWidthSigma, const CenterBiasCombinationType_t cbct)
{
	Mat regIdx1i, colorIdx1i, regSal1v, tmp, _img3f, color3fv;
	if (Quantize(img3f, colorIdx1i, color3fv, tmp) <= 2) // Color quantization
		return Mat::zeros(img3f.size(), CV_32F);
	cvtColor(img3f, _img3f, CV_BGR2Lab);
	cvtColor(color3fv, color3fv, CV_BGR2Lab);
	int regNum = SegmentImage(_img3f, regIdx1i, segSigma, segK, segMinSize);	
	vector<Region> regs(regNum);
	BuildRegions(regIdx1i, regs, colorIdx1i, color3fv.cols);
	RegionContrast(regs, color3fv, regSal1v, sigmaDist);
  
  float* regsCenterBias = new float[regNum]; // the center-bias for each region
  float w0 = (float)centerBiasWidthSigma;    // std. dev. of the Gaussian (width)
  float h0 = (float)centerBiasHeightSigma;   // std. dev. of the Gaussian (height)
  for (int i = 0; i < regNum; i++)
  {
    const float x0 = 0.5;
    const float y0 = 0.5;

    regsCenterBias[i] = ( exp((-SQR(regs[i].centroid.x-x0))/SQR(w0)) * exp((-SQR(regs[i].centroid.y-y0))/SQR(h0)) );
  }

	Mat sal1f = Mat::zeros(img3f.size(), CV_32F);
	cv::normalize(regSal1v, regSal1v, 0, 1, NORM_MINMAX, CV_32F);
	float* regSal = (float*)regSal1v.data;
	for (int r = 0; r < img3f.rows; r++)
  {
		const int* regIdx = regIdx1i.ptr<int>(r);
		float* sal = sal1f.ptr<float>(r);
		for (int c = 0; c < img3f.cols; c++)
    {
      switch (cbct)
      {
        case CB_LINEAR:
          sal[c] = (1-centerBiasWeight)*regSal[regIdx[c]] + centerBiasWeight*regsCenterBias[regIdx[c]];
          break;
        case CB_PRODUCT:
          sal[c] = regSal[regIdx[c]] * regsCenterBias[regIdx[c]]; // weighting in this case would have no influence
          break;
        case CB_MAX:
          sal[c] = std::max((1-centerBiasWeight)*regSal[regIdx[c]], centerBiasWeight*regsCenterBias[regIdx[c]]);
          break;
        case CB_MIN:
          sal[c] = std::min((1-centerBiasWeight)*regSal[regIdx[c]], centerBiasWeight*regsCenterBias[regIdx[c]]);
          break;
        default:
          assert(false);
          exit(-1);
      }
    }
	}
	GaussianBlur(sal1f, sal1f, Size(3, 3), 0);
  
  delete [] regsCenterBias;
  
	return sal1f;
}
void GraphBasedSegmentor::Run()
{
	cout<<"====="<<m_Name<<" Runing..."<<endl;

	Mat img3u(m_Img);
	Mat img3f;
	img3u.convertTo(img3f, CV_32FC3, 1.0/255);
	cvtColor(img3f, img3f, COLOR_BGR2Lab);
	int regionNum = SegmentImage(img3f, m_Result, m_Sigma, m_Threshold, m_MinSize);

	Segmentor::Run();
}
Пример #5
0
int SegmentImage(CMat &_src3f, Mat &pImgInd, float sigma, float c, int min_size)
{
	CV_Assert(_src3f.type() == CV_32FC3);
	int width(_src3f.cols), height(_src3f.rows);
	pImgInd.create(height, width, CV_32S);
	image<RGB_f> *im = new image<RGB_f>(width, height, _src3f.data);
	image<int> *regIdx = new image<int>(width, height, pImgInd.data);
	int regNum = SegmentImage(im, regIdx, sigma, c, min_size);
	im->data = NULL; regIdx->data = NULL;
	delete im; delete regIdx;
	return regNum;
}
Пример #6
0
void SegmentImageDemo(CStr& inImgW, CStr& outDir, double sigma, double k, int min_size)
{
	vecS names;
	string inDir;
	CmFile::MkDir(outDir);
	int imgNum = CmFile::GetNames(inImgW, names, inDir);
#pragma omp parallel for
	for (int i = 0; i < imgNum; i++)
	{
		printf("%-40s\r", names[i].c_str());
		Mat img3u = imread(inDir + names[i], CV_LOAD_IMAGE_COLOR);
		Mat imgIdx, img3f;
		img3u.convertTo(img3f, CV_32FC3, 1.0/255);
		int regNum = SegmentImage(img3f, imgIdx, sigma, k, min_size);
		CmShow::Label(imgIdx, outDir+names[i], regNum);
	}
	printf("%-40s\r", "");
}
Пример #7
0
void BenchMarkLatex::produceSupperPixels(CStr &rootDir)
{
	for (int d = 0; d < _numDb; d++){
		string imgDir = rootDir + _dbNames[d] + "/Imgs/";
		printf("Processing %s\n", _S(imgDir));
		vecS namesNE;
		int imgNum = CmFile::GetNamesNE(imgDir + "*.jpg", namesNE);
#pragma omp parallel for
		for (int i = 0; i < imgNum; i++) {
			if (CmFile::FileExist(imgDir + namesNE[i] + "_Seg.png"))
				continue;
			Mat img3u = imread(imgDir + namesNE[i] + ".jpg"), img3f, idx1i, color3u;
			img3u.convertTo(img3f, CV_32F, 1.0 / 255);
			cvtColor(img3f, img3f, CV_BGR2Lab);
			SegmentImage(img3f, idx1i, 0.8, 50, 100);
			CmIllu::label2Rgb<int>(idx1i, color3u);
			imwrite(imgDir + namesNE[i] + "_Seg.png", color3u);			
		}
	}

}
Пример #8
0
//----[  obtainD3DTexture  ]---------------------------------------------------
bool D3DXImage::obtainD3DTexture(LPDIRECT3DDEVICE9 pd3dDevice,
                                 LPDIRECT3DTEXTURE9* ppd3dTexture) const {
  
#define D3DTEX_MANAGED      0x01 /* create in managed pool */
#define D3DTEX_MIPMAP       0x02 /* generate a mipmap chain */
#define D3DTEX_SYSTEMMEM    0x04 /* create in system memory; overrides D3DTEX_MANAGED */

  DWORD options = D3DTEX_MIPMAP|D3DTEX_MANAGED;


  // Fail without a device or if something is wrong with the output pointer
  if (APP_WARNING(!pd3dDevice || !ppd3dTexture)("Invalid parameter to obtainD3DTexture")) return false;

  // Obtain options flags
  bool managed = (options & D3DTEX_MANAGED) != 0;
  bool mipmap = (options & D3DTEX_MIPMAP) != 0;
  bool systemmem = (options & D3DTEX_SYSTEMMEM) != 0;
  D3DPOOL pool = systemmem ? D3DPOOL_SYSTEMMEM : (managed ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT);

  // Holds return codes
  HRESULT hr;

  // Save a NULL first (just in case something goes wrong)
  *ppd3dTexture = NULL;

  // Determine the color key to use
  D3DCOLOR d3dColorKey = myColorKey.isEnabled() ? myColorKey.getD3DColor() : 0;

  // The destination for the texture interface
  LPDIRECT3DTEXTURE9 pd3dTexture;

  // Load information about the image
  D3DXIMAGE_INFO imageInfo;
  if (APP_WARNING(hr = D3DXGetImageInfoFromFile(mySourceFile.getValue().c_str(), &imageInfo))
      ("Failed to get image info from D3DXImage source file %s", mySourceFile.getValue().c_str()))
      return false;

  // Get the target image format
  //D3DFORMAT targetFormat = imageInfo.Format;

  //// Add at least 1 bit of alpha to whatever format we're in
  //if (myColorKey.isEnabled())
  //{
  //    switch(imageInfo.Format)
  //    {
  //        // These special formats have lower-BPP alpha formats
  //        case D3DFMT_P8:       targetFormat = D3DFMT_A8P8;     break;
  //        case D3DFMT_R5G6B5:
  //        case D3DFMT_X1R5G5B5: targetFormat = D3DFMT_A1R5G5B5; break;
  //        case D3DFMT_X4R4G4B4: targetFormat = D3DFMT_A4R4G4B4; break;

  //        // Convert all other formats into standard 32-bit color
  //        default: targetFormat = D3DFMT_A8R8G8B8; break;
  //    }
  //}

  // Always load in 32-bit with 8 bit alpha
  D3DFORMAT targetFormat = D3DFMT_A8R8G8B8;

  // Load the texture
  hr = D3DXCreateTextureFromFileEx(pd3dDevice,
                                   mySourceFile.getValue().c_str(),
                                   D3DX_DEFAULT,
                                   D3DX_DEFAULT,
                                   mipmap ? D3DX_DEFAULT : 1,
                                   0,
                                   targetFormat,
                                   pool,
                                   D3DX_DEFAULT,
                                   D3DX_FILTER_POINT,
                                   d3dColorKey,
                                   NULL,
                                   NULL,
                                  &pd3dTexture);

  // If there is a problem, there's not much more we can do
  if (APP_WARNING(FAILED(hr))("Couldn't load D3DXImage source file %s", mySourceFile.getValue().c_str()))
      return false;

  // Check to see if there is a sub-image
  if ((mySubImageRows.getValue() > 1) ||
      (mySubImageColumns.getValue() > 1)) {
    LPDIRECT3DTEXTURE9 segment = NULL;
    if (SegmentImage(pd3dTexture,
                     imageInfo.Width / mySubImageColumns.getValue(),
                     imageInfo.Height / mySubImageRows.getValue(),
                     mySubImageRows.getValue(),
                     mySubImageColumns.getValue(),
                     mySubImage.getValue(),
                    &segment)) {
      SAFE_RELEASE(pd3dTexture);
      pd3dTexture = segment;
    } else {
      DEBUG_INFO("Failed to segment image; using entire texture");
    }
  }

  //// rescale the RGB color channels to be in [0, 128]
  //DWORD number_of_levels = pd3dTexture->GetLevelCount();
  //for (DWORD level = 0; level < number_of_levels; ++level) {
  //  D3DLOCKED_RECT lr;
  //  pd3dTexture->LockRect(level, &lr, NULL, 0);
  //  D3DSURFACE_DESC level_desc;
  //  pd3dTexture->GetLevelDesc(level, &level_desc);
  //  D3DCOLOR* src_bits = (D3DCOLOR*)lr.pBits;
  //  DWORD added_pitch = lr.Pitch / sizeof(D3DCOLOR) - level_desc.Width;
  //  for (int y = 0; y < level_desc.Height; ++y) {
  //    for (int x = 0; x < level_desc.Width; ++x) {
  //      D3DCOLOR c = *src_bits;
  //      c = D3DCOLOR_ARGB((c>>24)&0xFF,
  //                        ((c>>16)&0xFF)>>1,
  //                        ((c>> 8)&0xFF)>>1,
  //                        ((c>> 0)&0xFF)>>1);
  //      *src_bits = c;
  //      ++src_bits;
  //    }
  //    src_bits += added_pitch;
  //  }
  //  pd3dTexture->UnlockRect(level);
  //}

  *ppd3dTexture = pd3dTexture;

  return true;
}
Пример #9
0
// Function to detect and draw any faces that is present in an image
void detect_and_draw( IplImage* img )
{
    potrace_state_t** states;
    potrace_state_t** fstates;
    int tmp, num_ccs, face_ccs, *compcolor, *pixeldistribution;
    int *segmentsize, *facesize, *facecolor, *facelist, *complist, scale = 1;
    universe *u, *fu;  //fu is the face universe, get your mind out of the gutter
    potrace_bitmap_t** VGbmps, **Facebmps;
    static int framenumber = 0;
    CvPoint pt1, pt2;
    
    // Create a new image based on the input image
    IplImage* quantized;
    IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );

    if(framenumber==0)page_svg_open(OutFile, img->width, img->height);

    if(framenumber==37)system("pause");

    cvShowImage( "original", img );
    
    //find all faces
    FindFaces(img, &pt1, &pt2);
    
    // Quantize our input
    quantized = QuantizeImage(img);
    
    /*
    system("pause");
    if(!cvSaveImage("output.bmp",quantized)){ printf("Could not save: %s\n","output.bmp");
    system("pause");}
    return;*/
    // do segmentation
    u = SegmentImage(quantized, pt1, pt2, &num_ccs, false);
    fu = SegmentImage(quantized, pt1, pt2, &face_ccs, true);
    
    complist = (int*) malloc(sizeof(int)*num_ccs);
    compcolor = (int*) malloc(sizeof(int)*num_ccs);
    facelist = (int*) malloc(sizeof(int)*face_ccs);
    facecolor = (int*) malloc(sizeof(int)*face_ccs);

    /*************************************************************************/
    // this is the workforce code, it does all the cool stuff
    
    
    //allocate bitmaps and associated data
    VGbmps = (potrace_bitmap_t**)malloc(sizeof(potrace_bitmap_t*)*num_ccs);
    //figure out distributions for background sutraction
    segmentsize = (int*) malloc(sizeof(int)*num_ccs);
    facesize = (int*) malloc(sizeof(int)*face_ccs);
    pixeldistribution = (int*) malloc(sizeof(int)*num_ccs);
    VGbmps = bmpalloc(num_ccs, img->width, img->height);
    for(int k=0; k<num_ccs; k++)compcolor[k] = complist[k] = segmentsize[k] = pixeldistribution[k] = 0;
    Facebmps = bmpalloc(face_ccs, img->width, img->height);
    for(int k=0; k<face_ccs; k++)facecolor[k] = facelist[k] = facesize[k] = 0;

    
    
    // find the background
    cvUpdatePixelBackgroundGMM(pGMM,(unsigned char*)quantized->imageData,
                                              (unsigned char*)temp->imageData);
    int comp;
    //Find number of pixels in each segment which are foreground
    for(int j = 0; j<img->height; j++){
    for(int i = 0; i<img->width; i++){
            int k = j*img->width+i;
            
            if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){
                comp = u->find(k);
                comp = FindonList(comp,complist,num_ccs);
                //incrament its segment
                segmentsize[comp]++;
                //increase its distribution if its forground
                pixeldistribution[comp] += (temp->imageData[k*3]==0)?0:1;
                //note temp is grayscale so it doesn't matter which color we take
                // just take one for every 3
            }else{
                comp = fu->find(k);                
                comp = FindonList(comp,facelist,face_ccs); 
                facesize[comp]++; 
            }//don't bother with the face pixels they're getting 1's anyway
    }}


    double *R = (double*)malloc(sizeof(double)*num_ccs);
    double *G = (double*)malloc(sizeof(double)*num_ccs);
    double *B = (double*)malloc(sizeof(double)*num_ccs);
    for(int k = 0; k<num_ccs; k++)R[k] = G[k] = B[k] = 0.0;
    
    double *fR = (double*)malloc(sizeof(double)*face_ccs);
    double *fG = (double*)malloc(sizeof(double)*face_ccs);
    double *fB = (double*)malloc(sizeof(double)*face_ccs);
    for(int k = 0; k<face_ccs; k++)fR[k] = fG[k] = fB[k] = 0.0;
    
    
    
    for(int j = 0; j<img->height; j++){
    for(int i = 0; i<img->width; i++){
            int r,g,b;
            int k = j*img->width+i;
            if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){
                 comp = u->find(k);
                 comp = FindonList(comp,complist,num_ccs);
                 r = (quantized->imageData[k*3+2]&0xFF);
                 g = (quantized->imageData[k*3+1]&0xFF);
                 b = (quantized->imageData[k*3+0]&0xFF);
                 R[comp] += r/double(segmentsize[comp]);
                 G[comp] += g/double(segmentsize[comp]);
                 B[comp] += b/double(segmentsize[comp]);
                 compcolor[comp] = (r&0xFF)<<16 | (g&0xFF)<<8 | b&0xFF;
                 PlacePoPixel(VGbmps[comp],i,j);
                 
            }else{
                 comp = fu->find(k);
                 comp = FindonList(comp,facelist,face_ccs);
                 r = (quantized->imageData[k*3+2]&0xFF);
                 g = (quantized->imageData[k*3+1]&0xFF);
                 b = (quantized->imageData[k*3+0]&0xFF);
                 fR[comp] += r/double(facesize[comp]);
                 fG[comp] += g/double(facesize[comp]);
                 fB[comp] += b/double(facesize[comp]);
                 facecolor[comp] = (r&0xFF)<<16 | (g&0xFF)<<8 | b&0xFF;
                 PlacePoPixel(Facebmps[comp],i,j); 
            }
    }
    }
    for(int k = 0; k<num_ccs; k++) compcolor[k] =(int(R[k])&0xFF)<<16 | (int(G[k])&0xFF)<<8 | int(B[k])&0xFF;     
    for(int k = 0; k<face_ccs; k++) facecolor[k] =(int(fR[k])&0xFF)<<16 | (int(fG[k])&0xFF)<<8 | int(fB[k])&0xFF;     

    //for(int k = 0; k<num_ccs; k++) compcolor[k] =(int(rand()%255)&0xFF)<<16 | (int(rand()%255)&0xFF)<<8 | int(rand()%255)&0xFF;     
    //for(int k = 0; k<face_ccs; k++) facecolor[k] =(int(rand()%255)&0xFF)<<16 | (int(rand()%255)&0xFF)<<8 | int(rand()%255)&0xFF;     

    
    /*************************************************************************/


    float percentage;
    //generalize segement color
    for(int j = 0; j<img->height; j++){
    for(int i = 0; i<img->width; i++){
            int k = j*img->width+i;
            if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){
                 comp = u->find(k);
                 comp = FindonList(comp,complist,num_ccs);
                 percentage = ((float)pixeldistribution[comp])/((float)segmentsize[comp]);
                 if(percentage > -1.f){
                       quantized->imageData[k*3+2] = (compcolor[comp]>>16)&0xFF;
                       quantized->imageData[k*3+1] = (compcolor[comp]>>8)&0xFF;
                       quantized->imageData[k*3+0] = (compcolor[comp])&0xFF;
                 }else{
                       quantized->imageData[k*3+2] = (0>>16)&0xFF;
                       quantized->imageData[k*3+1] = (0>>8)&0xFF;
                       quantized->imageData[k*3+0] = (0)&0xFF;
                       
                 }      
            }else{
Пример #10
0
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	//the index of the variables from the left image are 0~numLabels-1 ; right:numLabels~2*numLabels-1
	double *r,*c, *Colors_L, *FLabels_L, *BLabels_L, *FDist_L, *BDist_L,
		          *Colors_R, *FLabels_R, *BLabels_R, *FDist_R, *BDist_R, 
		   *disp , *RelateParam_p , *RelateParam_c ;	
	// Input Arguments

	double *SegImage_L , *SegImage_R ;	// Output Arguments
	int numRows, numCols, numLabels, numFLabels_L, numBLabels_L, numFLabels_R, numBLabels_R ;
	int numCorrs ;
	int i;
	  
	if(nrhs!=15) 
	{
		mexErrMsgTxt("Incorrect No. of inputs");
	} 
	else if(nlhs!=2) 
	{
		mexErrMsgTxt("Incorrect No. of outputs");
	}
	  
	r          = mxGetPr(prhs[0]);
	c          = mxGetPr(prhs[1]);
	Colors_L   = mxGetPr(prhs[2]);
	FLabels_L  = mxGetPr(prhs[3]);
	BLabels_L  = mxGetPr(prhs[4]);	
	FDist_L    = mxGetPr(prhs[5]);
	BDist_L	   = mxGetPr(prhs[6]);	
	Colors_R   = mxGetPr(prhs[7]);
	FLabels_R  = mxGetPr(prhs[8]);
	BLabels_R  = mxGetPr(prhs[9]);	
	FDist_R    = mxGetPr(prhs[10]);
	BDist_R	   = mxGetPr(prhs[11]);	
	disp	   = mxGetPr(prhs[12]);	
	RelateParam_p  = mxGetPr(prhs[13]);  
 	RelateParam_c  = mxGetPr(prhs[14]);     

    double lambda_p = (*RelateParam_p);
    double lambda_c = (*RelateParam_c);
    
	numCols = (int)(*c);		// Image Size
	numRows = (int)(*r);
	numLabels = numRows*numCols;	// Number of labels
	numFLabels_L = mxGetM(prhs[3]);	// Number of ForeGround Labels in l image
	numBLabels_L = mxGetM(prhs[4]);	// Number of BackGround Labels in l image
	numFLabels_R = mxGetM(prhs[8]);	// Number of ForeGround Labels in r image
	numBLabels_R = mxGetM(prhs[9]);	// Number of BackGround Labels in r image

	plhs[0] = mxCreateDoubleMatrix(numRows,numCols, mxREAL);	// Memory Allocated for output SegImage
	plhs[1] = mxCreateDoubleMatrix(numRows,numCols, mxREAL);	// Memory Allocated for output SegImage

	SegImage_L = mxGetPr(plhs[0]);	// variable assigned to the output SegImage
	SegImage_R = mxGetPr(plhs[1]);	// variable assigned to the output SegImage

	printf("Starting MEX Code \n");

	/**** Cast these data structures into correct types 
	and convert into STL Data Structures ****/

	printf("Vectorization 1: colors of pixels \n");
	vector< vector<double> > ColorsVec_L;
	ColorsVec_L.clear();
    for( i=0 ; i<numLabels ; i++ )
	{
		vector<double> tmp;
		tmp.clear();
		tmp.push_back( Colors_L[0*numLabels + i] );
		tmp.push_back( Colors_L[1*numLabels + i] );
		tmp.push_back( Colors_L[2*numLabels + i] );

		ColorsVec_L.push_back(tmp);
	}
	vector< vector<double> > ColorsVec_R;
	ColorsVec_R.clear();
    for( i=0 ; i<numLabels ; i++ )
	{
		vector<double> tmp;
		tmp.clear();
		tmp.push_back( Colors_R[0*numLabels + i] );
		tmp.push_back( Colors_R[1*numLabels + i] );
		tmp.push_back( Colors_R[2*numLabels + i] );

		ColorsVec_R.push_back(tmp);
	}


	printf("Vectorization 2 and 3: distance from foreground and background GMM \n");
	vector<double> FDistVec_L;
	FDistVec_L.clear();
    for(i=0;i<numLabels;i++)
		FDistVec_L.push_back(FDist_L[i]);

	vector<double> BDistVec_L;
	BDistVec_L.clear();
    for(i=0;i<numLabels;i++)
		BDistVec_L.push_back(BDist_L[i]);

	vector<double> FDistVec_R;
	FDistVec_R.clear();
    for(i=0;i<numLabels;i++)
		FDistVec_R.push_back(FDist_R[i]);

	vector<double> BDistVec_R;
	BDistVec_R.clear();
    for(i=0;i<numLabels;i++)
		BDistVec_R.push_back(BDist_R[i]);
	

	printf("Vectorization 4 and 5: no's of superpixels which belong to FG and BG \n");
	vector<int> FGLabelsVec_L;
	FGLabelsVec_L.clear();
	for(i=0;i<numFLabels_L;i++)
		FGLabelsVec_L.push_back((int) FLabels_L[i]);

	vector<int> BGLabelsVec_L;
	BGLabelsVec_L.clear();
	for(i=0;i<numBLabels_L;i++)
		BGLabelsVec_L.push_back((int) BLabels_L[i]);

	vector<int> FGLabelsVec_R;
	FGLabelsVec_R.clear();
	for(i=0;i<numFLabels_R;i++)
		FGLabelsVec_R.push_back((int) FLabels_R[i]);

	vector<int> BGLabelsVec_R;
	BGLabelsVec_R.clear();
	for(i=0;i<numBLabels_R;i++)
		BGLabelsVec_R.push_back((int) BLabels_R[i]);


	printf("Vectorization 6: disparity map \n");
	vector<int> Disparity;
	Disparity.clear();
    for( int c=0 ; c<numCols ; c++ )
        for( int h=0 ; h<numRows ; h++ )
	    {
	    	Disparity.push_back( (int)disp[c*numRows+h] );
	    }


	/**************************************************************/
	/********** Data Structures Converted into Vector Form*********/
	/**************************************************************/


	/**** Actual Image Segmentation Code *********/
	// Adjacency list declaration
	vector< set<int> > neighbors;			

	MakeAdjacencyList( numLabels, numCols, numRows , neighbors );	// Adjacency list made

	printf("Adjacency lists made \n");
	
	//Calculate how many high-order cliques
	int num_high= 0 ;  
	num_high = get_num_corres( Disparity , numRows , numCols ) ;

	Energy<float,float,float> *e = new Energy<float,float,float>( 2*numLabels+4*num_high*5 , (2*numLabels+4*num_high*5)*3 ) ;
	int *vars = new int[2*numLabels+4*num_high*5];   

	MakeGraph( e , vars , neighbors, Disparity ,
		       ColorsVec_L, FGLabelsVec_L, BGLabelsVec_L, FDistVec_L, BDistVec_L,
			   ColorsVec_R, FGLabelsVec_R, BGLabelsVec_R, FDistVec_R, BDistVec_R,
			   numLabels,  num_high , numRows , numCols , lambda_p , lambda_c );
	printf("Graph constructed \n");
	
	SegmentImage( e , vars , numLabels , numRows, numCols,  SegImage_L , SegImage_R );
	printf("Image Segmented \n");
}