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 !!