I need to use VLFeat's implementation of Quick Shift, as well. The following snippets illustrate how to use the implementation from C++. As I am using OpenCV to read image, first include OpenCV together with the VLFeat header files:
#include <opencv2/opencv.hpp>
extern "C" {
#include "generic.h"
#include "quickshift.h"
}
After downloading VLFeat (in my case the archive contains the folder vlfeat-0.9.18
), I use CMake to add vlfeat-0.9.18/vl
as include directory. Otherwise you have to adjust the above code. Then, the following code reads an image, converts the image to the required format and runs Quick Shift.
Note: The following snippet is only an extract of my original code and, thus, is not tested as it is presented below.
// Read an image using OpenCV, I assume a color image to be given;
// the image will be loaded in BGR color space.
cv::Mat mat = cv::imread("Lenna.png", CV_LOAD_IMAGE_COLOR);
// Convert image to one-dimensional array.
double* image = new double[mat.rows*mat.cols*mat.channels()];
for (int i = 0; i < mat.rows; ++i) {
for (int j = 0; j < mat.cols; ++j) {
image[j + mat.cols*i + mat.cols*mat.rows*0] = mat.at<cv::Vec3b>(i, j)[0];
image[j + mat.cols*i + mat.cols*mat.rows*1] = mat.at<cv::Vec3b>(i, j)[1];
image[j + mat.cols*i + mat.cols*mat.rows*2] = mat.at<cv::Vec3b>(i, j)[2];
}
}
// Create a new quickshift instance using the image, the height and width of the
// image as well as the number of channels.
VlQS* quickShift = vl_quickshift_new(image, mat.rows, mat.cols, mat.channels());
vl_quickshift_set_kernel_size(quickShift, 5);
// Run Quick Shift.
vl_quickshift_process(quickShift);
However, I could not figure out how to interpret and use the output of the implementation, yet.