void ColorHistogramLab<Mesh>::extract(const Mesh&m,arma::vec&hist) { hist = arma::vec( (NL_+ 1)*(Na_+1)*(Nb_+1) ,arma::fill::ones); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat Lab_mat; ColorArray::RGB2Lab(rgb_mat,Lab_mat); for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index ) { arma::fvec Lab = Lab_mat.col(index); hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))] += 1.0 ; } hist /= arma::accu(hist); hist *= hist.size(); }
void ColorHistogramLab<Mesh>::extract(const Mesh&m,std::vector<double>&hist) { hist.resize((NL_+ 1)*(Na_+1)*(Nb_+1),1.0); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat Lab_mat; ColorArray::RGB2Lab(rgb_mat,Lab_mat); double sum = 0.0; for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index ) { arma::fvec Lab = Lab_mat.col(index); hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))]+= 1.0 ; sum += 1.0; } #pragma omp parallel for for(int i=0; i<hist.size(); ++i) { hist[i] *= (hist.size()/sum); } }
/** * Find the length of a character string. String is terminated by the * first occurance of a character or by the end of the string. * * @param string * Character string * @param string_s * Length of \p string * @param kchar * Requested termination character * * @return Index of character before the requested character * * @date 920326: Changed parameter char to kchar. * @date 830527: Original version. * */ int indexc(char *string, int string_s, int kchar) { int indexc_v, j; /* - Call general character search routine, searching for the first * occurance of the delimiter searching forward. */ j = indexa( string,string_s, kchar, TRUE, TRUE ); /* - If CHAR was found, return with pointer at previous character. * If CHAR was not found, return with pointer at end of string. */ if( j > 0 ){ indexc_v = j - 1; } else { indexc_v = (string_s - 1); } return( indexc_v ); }