extern "C" DLL_EXPORT int extractMICanny(const char* imagenamefile, double* feature) { CImg m_img(MODE_RGB); int re = 0; if (m_img.read_JPEG_file(imagenamefile)) { CFeatureBase* ft = new CShapeFeature(&m_img); if (ft->get_feature()) { for (int i=0; i<ft->m_dimension; ++i) { feature[i] = ft->m_feature[i]; } re = 1; } delete ft; } // no need, deallocate is called in the destructor. //m_img.deallocate(m_img.m_mode); return re; }
Colour TextureMaterial::get_colour(Point2D tex_coords) const { // int x = tex_coords[0] * m_img.width(); // int y = (1 - tex_coords[1]) * m_img.height(); // return Colour(m_img(x, y, 0), m_img(x, y, 1), m_img(x, y, 2)); /////////correct? double u=tex_coords[0]; double v=tex_coords[1]; double di = u * (double)(m_img.width()-1); double dj = v * (double)(m_img.height()-1); int i = di; int j = dj; // Wrap around if the coordinates are out of bounds int i1 = ((i+1) >= m_img.width()) ? 0 : i+1; int j1 = ((j+1) >= m_img.height()) ? 0 : j+1; // Get the barycentric coordinates between pixels double up = di - i; double vp = dj - j; // Bilinear interpolation between pixel values, basically a weighted average of the sourrounding pixels // using the barycentric coordinates up, vp return (1-up)*(1-vp)*Colour(m_img(i, j, 0), m_img(i, j, 1), m_img(i, j, 2)) + (1-up)*(vp)*Colour(m_img(i, j1, 0), m_img(i, j1, 1), m_img(i, j1, 2)) + (up)*(1-vp)*Colour(m_img(i1, j, 0), m_img(i1, j, 1), m_img(i1, j, 2)) + (up)*(vp)*Colour(m_img(i1, j1, 0), m_img(i1, j1, 1), m_img(i1, j1, 2)); }