void DeteccionAut::pasoCoordGovocitosPointList(PointList **nsd) { int numCelulas; vector<int> cx, cy; numCelulas = vectorPol->getNumCelulas(); nsd = (PointList **)calloc(numCelulas, sizeof(PointList *)); for(int i = 0; i < numCelulas; i++) { int numCoords; PointList *cellI; cx = *vectorPol->getCelula(i)->getBordeCellX(); cy = *vectorPol->getCelula(i)->getBordeCellY(); numCoords = cx.size(); cellI = (PointList *)calloc(numCelulas, sizeof(PointList)); cellI->point = (Point **)calloc(numCoords, sizeof(Point *)); cellI->num_pts = numCoords; for(int j = 0; j < numCoords; j++) { cellI->point[j] = alloc_point(cx[j],cy[j]); } nsd[i] = cellI; } }
/** Carga los ficheros de clasificacion automatica de estados y clases y clasifica las celulas de la imagen cuya ruta corresponde con la pasada por parametro. @param ruta, string de la ruta de la imagen a analizar. @param listCell, objeto ListadoCeulas que contiene todas las celulas de la imagen a analizar. */ void Clasificador::clasificarCelulas(string ruta, ListadoCelulas &listCell) { struct svm_model *svmEst, *svmCl; float media_est[N_ENTRADAS], desv_est[N_ENTRADAS]; float media_cl[N_ENTRADAS], desv_cl[N_ENTRADAS]; int y1, y2; int numCelulas, numPuntos; vector <int> *cx, *cy; Image *img, *img_grey, *img_bin; img = read_img ( ruta.c_str() ); img_grey = rgb_to_gray (img); numCelulas = listCell.getNumCelulas(); //Obtenemos path de los ficheros de clasificacion const char *f_svm_Est = fichClasificEst.c_str(); const char *f_med_desv_Est = fichMediaDesviaEst.c_str(); const char *f_svm_Cl = fichClasificCl.c_str(); const char *f_med_desv_Cl = fichMediaDesviaCl.c_str(); //Creamos los svm svmEst = crea_svm(f_svm_Est, f_med_desv_Est, media_est, desv_est); svmCl = crea_svm(f_svm_Cl, f_med_desv_Cl, media_cl, desv_cl); for(int i = 0; i < numCelulas; i++) { PointList *puntos; if(listCell.getCelula(i)->getEstadoCelula() != "outimage" && listCell.getCelula(i)->getClaseCelula() != "outimage") { cx = listCell.getCelula(i)->getBordeCellX(); cy = listCell.getCelula(i)->getBordeCellY(); numPuntos = cx->size(); puntos = alloc_point_list(numPuntos); //Convertimos puntos for(int j = 0; j < numPuntos; j++) { puntos->point[j] = alloc_point((*cy)[j], (*cx)[j]); } puntos->type = GEN_VALID; img_bin=computeBinImage ( puntos, get_num_rows ( img_grey ) , get_num_cols (img_grey)); // double* resul = texture_features_haralick(img, puntos, 1, 1); double * resul = texture_features_glrls_grey ( img_grey, img_bin, puntos, 1000, 0); float resul2[N_ENTRADAS], resul3[N_ENTRADAS]; for(unsigned int z = 0; z < N_ENTRADAS; z++) { resul2[z] = (float)resul[z]; resul3[z] = (float)resul[z]; } //Salida clasificador clases y1 = saida_svm(svmCl, resul2, media_cl, desv_cl); switch(y1) { case 0: listCell.getCelula(i)->setClaseCelula("cn"); break; case 1: listCell.getCelula(i)->setClaseCelula("sn"); break; } //Salida clasificador estados y2 = saida_svm(svmEst, resul3, media_est, desv_est); switch (y2) { case 0: listCell.getCelula(i)->setEstadoCelula("ac"); break; case 1: listCell.getCelula(i)->setEstadoCelula("hid"); break; case 2: listCell.getCelula(i)->setEstadoCelula("vit");// vitelinas o atresicas break; } free_point_list ( puntos ); free ( puntos->point ); free ( puntos ); // delete puntos; free ( resul ); } } destrue_svm(svmCl); destrue_svm(svmEst); free_img ( img ); free ( img ); free_img ( img_grey ); free ( img_grey ); }