I have extracted LBP Texture features on an image by splitting the image into small cells and then calculating LBP for each sub-image and then latter concatenating spatial histograms of each sub-image following the Philip Code. I push these spatial histograms to a vector<Mat>
. I understand my spatial texture features are now contained in the histograms.
The problem I have is, I want to prepare this texture feature vector for training SVM. I convert the vector<Mat>hists
of histograms to a row Mat
where each row represent a sample. I use the code below to convert to row Mat
.
Mat cv::asRowMatrix(const vector<Mat>& src, int rtype, double alpha, double beta) {
// number of samples
size_t n = src.size();
// return empty matrix if no matrices given
if (n == 0)
return Mat();
// dimensionality of (reshaped) samples
size_t d = src[0].total();
// create data matrix
Mat data(n, d, rtype);
// now copy data
for (int i = 0; i < n; i++) {
// make sure data can be reshaped, throw exception if not!
if (src[i].total() != d) {
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src[i].total());
CV_Error(CV_StsBadArg, error_message);
}
// get a hold of the current row
Mat xi = data.row(i);
// make reshape happy by cloning for non-continuous matrices
if (src[i].isContinuous()) {
src[i].reshape(1, 1).convertTo(xi, rtype, alpha, beta);
}
else {
src[i].clone().reshape(1, 1).convertTo(xi, rtype, alpha, beta);
}
}
return data;}
When I do this as Mat data = asRowMatrix(hists, CV_32F, 1, 0)
the matrix data
comes with same values in each column, showing that all the images are identical. I get the same results if I use LBP image itself instead of its histogram. I would like to prepare LBP texture for training SVM. I have spent weeks figuring out this but am now stuck. Kindly help. Regards