Ejemplo n.º 1
0
int main()
{
    string fileName = "fishMan.ppm";
    printf("loading input image.\n");
    image<rgb> *input = loadPPM(fileName.c_str());

    input->labels = new int[input->width() * input->height()];
    int numLabels(0);
    SLIC slic;

    slic.PerformSLICO_ForGivenK(input->getRGBData(), input->width(), input->height(),input->labels,numLabels, 100,10);

    /*for(int j = 0; j < input->height(); j++)
    {
        for(int i = 0; i < input->width(); i++)
            cout<<input->labels[j * input->width() + i]<< " ";
        cout<<endl;
    }*/


    printf("processing\n");
    int num_ccs;
    image<rgb> *seg = segment_image(input, 0.7, 5, 100, &num_ccs);
    savePPM(seg, "output.ppm");

    printf("got %d components\n", num_ccs);
    printf("done! uff...thats hard work.\n");
}
Ejemplo n.º 2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{   
    int width(0), height(0);
   // unsigned int (32 bits) to hold a pixel in ARGB format as follows:
   // from left to right,
   // the first 8 bits are for the alpha channel (and are ignored)
   // the next 8 bits are for the red channel
   // the next 8 bits are for the green channel
   // the last 8 bits are for the blue channel
    
    int i,j,sz, k;
    unsigned int* pbuff=NULL;
    unsigned int* Isp;
    double m = 20;
    int* Ilabel;
    //----get input parameters ----//
       pbuff=(unsigned int *) mxGetPr(prhs[0]); 
       height=mxGetScalar(prhs[1]); 
       width=mxGetScalar(prhs[2]);
       k=mxGetScalar(prhs[3]);
       m=mxGetScalar(prhs[4]); //Compactness factor. use a value ranging from 10 to 40 depending on your needs. Default is 10
       sz=height*width;
           
   //--------- set out put space -----//
    // important!//
   plhs[0]=mxCreateNumericMatrix(1,sz,mxUINT32_CLASS,mxREAL);  
   Isp= (unsigned int*) mxGetData(plhs[0]);

   plhs[1]=mxCreateNumericMatrix(1,sz,mxINT32_CLASS,mxREAL);  
   Ilabel=(int*) mxGetData(plhs[1]);
       //----------------------------------
       // Initialize parameters
       //----------------------------------
      
       int* klabels = new int[sz];
       int numlabels(0);
       //----------------------------------
       //Perform SLIC on the image buffer
      // ----------------------------------
       SLIC segment;
       segment.PerformSLICO_ForGivenK(pbuff, width, height, klabels, numlabels, k, m);

       //Draw boundaries around segments
      // ----------------------------------
      segment.DrawContoursAroundSegments(pbuff, klabels, width, height, 0xff0000);
      
    
      for(i=0;i<sz;i++)
      {    Isp[i]= pbuff[i];
           Ilabel[i]= klabels[i];
          // mexPrintf("%d\n",klabels[i]);
      }

} 
//===========================================================================
///	OnBnClickedButtonCreatesuperpixels
///
///	The main function
//===========================================================================
void CSLICSuperpixelsDlg::OnBnClickedButtonCreatesuperpixels()
{
	PictureHandler picHand;
	vector<string> picvec(0);
	picvec.resize(0);
	GetPictures(picvec);//user chooses one or more pictures
	string saveLocation = "C:\\rktemp\\";
	BrowseForFolder(saveLocation);

	int numPics( picvec.size() );

	//if(m_spcount < 0 || m_spcount < 20) m_spcount = 20;
	if(m_spcount < 0) m_spcount = 200;

	for( int k = 0; k < numPics; k++ )
	{
		UINT* img = NULL;
		int width(0);
		int height(0);

		picHand.GetPictureBuffer( picvec[k], img, width, height );
		int sz = width*height;
		if(m_spcount > sz) AfxMessageBox(L"Number of superpixels exceeds number of pixels in the image");

		int* labels = new int[sz];
		int numlabels(0);
		SLIC slic;
		slic.PerformSLICO_ForGivenK(img, width, height, labels, numlabels, m_spcount, m_compactness);//for a given number K of superpixels
		//slic.PerformSLICO_ForGivenStepSize(img, width, height, labels, numlabels, m_stepsize, m_compactness);//for a given grid step size
		//slic.DrawContoursAroundSegments(img, labels, width, height, 0);//for black contours around superpixels
		slic.DrawContoursAroundSegmentsTwoColors(img, labels, width, height);//for black-and-white contours around superpixels
		slic.SaveSuperpixelLabels(labels,width,height,picvec[k],saveLocation);
		if(labels) delete [] labels;
		
		picHand.SavePicture(img, width, height, picvec[k], saveLocation, 1, "_SLICO");// 0 is for BMP and 1 for JPEG)

		if(img) delete [] img;
	}
	AfxMessageBox(L"Done!", 0, 0);
}