Thread: SLIC C++ segmentation labels

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    1

    SLIC C++ segmentation labels

    Hello I am trying to use SLIC segmentation in c++ using OpenCV and VLFeat.I was able to segment a photo of 1024*1024 pixels using vl_slic_segment function. Anyway, now i have another problem. I want to assign labels to these segments. For example:


    Segments 0,27 and 100: Label 1 (water for example) Segments 15, 126, 5, and 89: Label 2 (land)


    but i want to do that automatically depending on the characteristics of the photo which were used to segment it, because later i will use SVM training to test photos to determine which part of these tested photos is water and which part is land and so on..


    Here is the code i used for importing the training photo and segmenting it:
    Code:
    extern "C" {
      #include </home/me/Downloads/vlfeat-0.9.17/vl/slic.h>
    }
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include <opencv2/opencv.hpp>
    #include<opencv/highgui.h>
    
    
    using namespace std;
    using namespace cv;
    
    
    int main () {
    
    
        IplImage* colored = cvLoadImage("train.tif", CV_LOAD_IMAGE_UNCHANGED);
        if (!colored)
        {
            printf("cvLoadImage failed!\n");
            return 0;
        }
    
    
    //  Allocate a new IPL_DEPTH_32F image with the same dimensions as the original
        IplImage* img_32f = cvCreateImage(cvGetSize(colored),IPL_DEPTH_32F,3);
        if (!img_32f)
        {
            printf("cvCreateImage failed!\n");
            return 0;
        }
    
    
        cvConvertScale(colored, img_32f);
    //  quantization for 32bit. Without it, this img would not be displayed properly
        cvScale(img_32f, img_32f, 1.0/255);
    
    
        Mat floatimg(img_32f);
    
    
        Mat labels(floatimg.size(), CV_32SC1); // Mat doesn't support 32-bit unsigned directly, but this should work fine just to hold data.
    
    
        vl_slic_segment(labels.ptr<vl_uint32>(),(const float *)(floatimg.data),floatimg.cols,floatimg.rows,floatimg.channels(),15,0.1,1);
        waitKey(0);
    }
    Thanks in advance !!
    Last edited by triple13; 08-29-2013 at 05:30 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing labels in a list?
    By arcaine01 in forum C# Programming
    Replies: 2
    Last Post: 05-10-2008, 11:10 PM
  2. Dynamic Labels again!!
    By SuperNewbie in forum C# Programming
    Replies: 3
    Last Post: 07-11-2002, 12:36 AM
  3. Dynamic labels??
    By SuperNewbie in forum C# Programming
    Replies: 2
    Last Post: 07-09-2002, 01:31 AM
  4. GOTO and Labels
    By moemen ahmed in forum C++ Programming
    Replies: 13
    Last Post: 07-01-2002, 06:41 PM
  5. Labels in C++?!!?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2001, 04:27 AM