Reputation: 517
I have installed vlfeat on my pc and seem to have got it working on netbeans.
I am currently trying to use vlfeat's quickshift function but I am unable to find any references on how to do the following:
Any help on this would be much appreciated.
Thanks.
Upvotes: 0
Views: 2194
Reputation: 2618
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.
Upvotes: 1
Reputation: 497
In the Usage part of this website Quick shift image segmentation, a simple pipeline is presented.
As explained in the API doc of vl_quickshift_new:
image
is an array of vl_qs_type
values with three dimensions (respectively widht, height, and channels). Typically, a color (e.g, RGB) image has three channels. The linear index of a pixel is computed with: channels * width* height + row + height * col
.vl_qs_type
is double, i.e. typedef double vl_qs_type
.image
is just a double array.I am not sure of your purpose of adopting Vlfeat but I highly recommend using Matlab wrappers of Vlfeat, since there are many tutorials available and many algorithms are simple single matlab function call.
Upvotes: 0