float SupportVectorMachine::predict(const Feature &feature) const { CShape shape = feature.Shape(); int dim = shape.width * shape.height * shape.nBands; svm_node *svmNode = new svm_node[dim + 1]; svm_node *svmNodeIter = svmNode; for(int y = 0, k = 0; y < shape.height; y++) { float *data = (float *) feature.PixelAddress(0, y, 0); for (int x = 0; x < shape.width * shape.nBands; x++, data++, k++, svmNodeIter++) { svmNodeIter->index = k; svmNodeIter->value = *data; } } svmNodeIter->index = -1; double decisionValue; float label = svm_predict_values(_model, svmNode, &decisionValue); delete [] svmNode; return decisionValue; }
CByteImage FeatureExtractor::render(const Feature& f, bool normalizeFeat) const { if(normalizeFeat) { CShape shape = f.Shape(); Feature fAux(shape); float fMin, fMax; f.getRangeOfValues(fMin, fMax); for(int y = 0; y < shape.height; y++) { float* fIt = (float*) f.PixelAddress(0,y,0); float* fAuxIt = (float*) fAux.PixelAddress(0,y,0); for(int x = 0; x < shape.width * shape.nBands; x++, fAuxIt++, fIt++) { *fAuxIt = (*fIt) / fMax; } } return this->render(fAux); } else { return this->render(f); } }