void MainWindow::gaussian() { double sigma = QInputDialog::getInt(this,"Sigma value","Sigma value"); image = gaussianFilter(image,sigma); setImages(); }
int main(int argc, char *argv[]) { if(argc < 2) { printhelp(); return 0; } try { if(strcmp(argv[1], "copyU8") == 0 && argc > 3) copy(argv[2], argv[3], 8); else if(strcmp(argv[1], "copyS8") == 0 && argc > 3) copy(argv[2], argv[3], 9); else if(strcmp(argv[1], "copyS16") == 0 && argc > 3) copy(argv[2], argv[3], 17); else if(strcmp(argv[1], "copyU16") == 0 && argc > 3) copy(argv[2], argv[3], 16); else if(strcmp(argv[1], "copyF32") == 0 && argc > 3) copy(argv[2], argv[3], 32); else if(strcmp(argv[1], "copyF64") == 0 && argc > 3) copy(argv[2], argv[3], 64); else if(strcmp(argv[1], "rescaleIntensity") == 0 && argc > 5) rescaleIntensity(argv[2], argv[3], atof(argv[4]), atof(argv[5])); else if(strcmp(argv[1], "gaussianFilter") == 0 && argc > 4) gaussianFilter(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "hessianFilter") == 0 && argc > 4) hessianFilter(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "tensorHessianFilter") == 0 && argc > 4) hessianFilter(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "floodFill") == 0 && argc > 8) floodFill(argv[2], argv[3], atof(argv[4]), atof(argv[5]), atoi(argv[6]), atoi(argv[7]), atoi(argv[8])); else if(strcmp(argv[1], "threshold") == 0 && argc > 5) threshold(argv[2], argv[3], atof(argv[4]), atof(argv[5])); else if(strcmp(argv[1], "multiscaleHessian") == 0 && argc > 6) multiscaleHessian(argv[2], argv[3], atof(argv[4]), atof(argv[5]), atoi(argv[6])); else if(strcmp(argv[1], "minIntensity") == 0 && argc > 2) minIntensity(argv[2]); else if(strcmp(argv[1], "maxIntensity") == 0 && argc > 2) maxIntensity(argv[2]); else if(strcmp(argv[1], "upscaleForCenteredSkeleton") == 0 && argc > 3) upscaleForCenteredSkeleton(argv[2], argv[3]); else if(strcmp(argv[1], "skeletonFromBinary") == 0 && argc > 3) skeletonFromBinary(argv[2], argv[3]); else if(strcmp(argv[1], "centeredSkeleton") == 0 && argc > 3) centeredSkeleton(argv[2], argv[3]); else if(strcmp(argv[1], "whiteForegroundHoleFill") == 0 && argc > 3) whiteForegroundHoleFill(argv[2], argv[3]); else if(strcmp(argv[1], "blackForegroundHoleFill") == 0 && argc > 3) blackForegroundHoleFill(argv[2], argv[3]); else if(strcmp(argv[1], "whiteTopHat") == 0 && argc > 4) whiteTopHat(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "blackTopHat") == 0 && argc > 4) blackTopHat(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "dilate") == 0 && argc > 4) dilate(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "erode") == 0 && argc > 4) erode(argv[2], argv[3], atof(argv[4])); else if(strcmp(argv[1], "skeletonToTreeIntSpace") == 0 && argc > 4) skeletonToTreeIntSpace(argv[2], argv[3], atoi(argv[4])); else if(strcmp(argv[1], "skeletonToTree") == 0 && argc > 4) skeletonToTree(argv[2], argv[3], atoi(argv[4])); else if(strcmp(argv[1], "estimateDiameters") == 0 && argc > 5) estimateDiameters(argv[2], argv[3], argv[4], atoi(argv[5])); else if(strcmp(argv[1], "skeletonToTreeIntSpace") == 0 && argc > 3) skeletonToTreeIntSpace(argv[2], argv[3], 0); else if(strcmp(argv[1], "skeletonToTree") == 0 && argc > 3) skeletonToTree(argv[2], argv[3], 0); else if(strcmp(argv[1], "estimateDiameters") == 0 && argc > 4) estimateDiameters(argv[2], argv[3], argv[4], 0); else if(strcmp(argv[1], "info") == 0 && argc > 1) info(argv[0]); else std::cout << "Unknown command " << argv[1] << " or invalid arguments" << std::endl; } catch( itk::ExceptionObject & err ) { std::cerr << "ITK exception" << std::endl; std::cerr << err << std::endl; return -2; } catch(...) { std::cerr << "Unknown exception" << std::endl; return -1; } return 0; }
void Histogram::normalize () { // flatten the first and the last bucket val[n-1] = val[n-2]; val[0] = val[1]; // apply a gaussian filter gaussianFilter(); }
int main (int argc, const char* const argv[]) { char garbage[2]; int command; double sigma; if (4 > argc || 5 < argc) { fprintf (stderr, "syntax: %s <input file> <output file> <command #> ...\n", argv[0]); return 2; } if (1 != sscanf (argv[3], "%d%1s", &command, garbage) || 1 > command || 3 < command) { fprintf (stderr, "Command must be from 1 to 3.\n"); fprintf (stderr, " 1 -- gaussian filter <sigma>\n"); fprintf (stderr, " 2 -- greyscale\n"); fprintf (stderr, " 3 -- invert colors\n"); return 2; } if (1 == command && (5 != argc || 1 != sscanf (argv[4], "%lf%1s", &sigma, garbage) || 0 >= sigma || 100 <= sigma)) { fprintf (stderr, "Sigma must be greater than 0 and less than 100.\n"); return 2; } Image* inputImage = decode (argv[1]); printf ("Width: %d, height: %d\n", inputImage->width, inputImage->height); Image* outputImage = generateOutput (inputImage); int height = inputImage->height; int width = inputImage->width; uint8_t* inRed = inputImage->redChannel; uint8_t* inBlue = inputImage->blueChannel; uint8_t* inGreen = inputImage->greenChannel; uint8_t* inAlpha = inputImage->alphaChannel; uint8_t* outRed = outputImage->redChannel; uint8_t* outBlue = outputImage->blueChannel; uint8_t* outGreen = outputImage->greenChannel; uint8_t* outAlpha = outputImage->alphaChannel; switch (command) { case 1: { int radius = ceil (3 * sigma); int fSize = 1 + 2 * radius; double* gauss = malloc (sizeof (gauss[0]) * fSize * fSize); gaussianFilter (gauss, sigma); convolveImage (width, height, inRed, inGreen, inBlue, inAlpha, radius, gauss, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; } case 2: greyscale (width, height, inRed, inGreen, inBlue, inAlpha, gMonoMult, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; case 3: invertColors (width, height, inRed, inGreen, inBlue, inAlpha, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; } freeImage (inputImage); freeImage (outputImage); return 0; }
int main(int argc, char *argv[]) { // Début compteur clock_t d_start, d_stop; d_start = clock(); ImageGS *car = NULL; if(argc > 2) { string arg(argv[1]); if(arg.compare("-pgm") == 0) car = new ImageGS(argv[2]); else if(arg.compare("-ppm") == 0) car = new ImageGS(ImageRGB(argv[2])); else std::cout << "Usage: " << argv[0] << " [-ppm|-pgm] FILE\n"; } else { car = new ImageGS("../data/991211-001"); //car = new ImageGS(ImageRGB("../data/0003")); //car = new ImageGS("../data/99122-2"); } // mesure de la variance (indicatif) #ifdef _DEBUG_ std::cout << "Variance de l'image : " << car->computeVariance() << std::endl; #endif #ifdef GAUSS_PRE_FILTER // filtrage gaussien ImageGS in(*car); in.gaussianFilter(0.5f); in.writePGM("0_gauss_filter"); #else ImageGS in = *car; #endif /* Calcule du gradient en x */ ImageGS *grad = in.computeHorizontalGradient(); grad->recal(); #ifdef _DEBUG_ grad->writePGM("0_grad"); #endif /* Projection horizontal */ float* vect; vect = grad->computeHorizontalProjection(); #ifdef _DEBUG_ writeVect(vect, grad->getHeight(), "data_h_brut.dat"); #endif // Filtre gaussien sur le vecteur de projection gaussianFilter(vect, grad->getHeight(), 6, 0.05f, 1); #ifdef _DEBUG_ writeVect(vect, grad->getHeight(), "data_h_filter.dat"); #endif /* Seuillage 'vertical' on ne garde que les ligne qui on une projection supérieur a un seuil */ // averaging float avg = 0.f; for (unsigned i = 0; i < grad->getHeight(); ++i) avg += vect[i]; avg /= grad->getHeight(); // seuillage vertical for (unsigned i = 0; i < grad->getHeight(); ++i) { // si la projection de cette ligne est sous le seuil on la supprime if( vect[i] < PROJ_HORIZONTAL*avg ) { for (unsigned j = 0; j < grad->getWidth(); ++j) { (*grad)(i, j) = 0.f; } } } delete[] vect; // free #ifdef _DEBUG_ grad->writePGM("1_vertical_filter"); #endif #if 0 /* Projection verticale */ vect = grad->computeVerticalProjection(); #ifdef _DEBUG_ writeVect(vect, grad->getWidth(), "data_v_brut.dat"); #endif // Filtrage gaussien gaussianFilter(vect, grad->getWidth(), 6, 0.05f, 0); #ifdef _DEBUG_ writeVect(vect, grad->getWidth(), "data_v_filter.dat"); #endif /* Seuillage 'vertical' on ne garde que les ligne qui on une projection supérieur a T */ // averaging avg = 0.f; for (unsigned i = 0; i < grad->getWidth(); ++i) avg += vect[i]; avg /= grad->getWidth(); // seuillage horizontal for (unsigned j = 0; j < grad->getWidth(); ++j) { // si la projection de cette ligne est sous le seuil on la supprime if( vect[j] < PROJ_VERTICAL*avg ) { for (unsigned i = 0; i < grad->getHeight(); ++i) { (*grad)(i, j) = 0.f; } } } delete[] vect; // free #ifdef _DEBUG_ grad->writePGM("1_horizontal_filter"); #endif #endif /* binarisation par seuillage global */ grad->thresholdingSmart(T_BIN); #ifdef _DEBUG_ grad->writePGM("2_bin_filter"); #endif /* Opération morphologique pour éliminer le bruit, etc..*/ int width, height; float** mask; #if 1 // Fermeture width=20; height=3; mask = new float*[height]; for (int i = 0; i < height; ++i) { mask[i] = new float[width]; for (int j = 0; j < width; ++j) mask[i][j] = 255.f; } grad->closing(mask, width, height); #ifdef _DEBUG_ grad->writePGM("3_2_close_grad"); #endif #endif #if 1 // Ouverture width=1; height=5; mask = new float*[height]; for (int i = 0; i < height; ++i) { mask[i] = new float[width]; for (int j = 0; j < width; ++j) mask[i][j] = 255.f; } grad->opening(mask, width, height); #ifdef _DEBUG_ grad->writePGM("4_open_grad"); #endif #endif // On applique les rectangle sur l'image de base pour visualiser // les zone detectées comme potentiellement des plaques d'immatriculation ImageRGB *car_detect = new ImageRGB(*car); std::vector<int*> *listPlate = foundConnectedComponents(*grad, car_detect, RATIO_MIN, RATIO_MAX, WIDTH_MIN, WIDTH_MAX, HEIGHT_MIN, HEIGHT_MAX); #ifdef _DEBUG_ car_detect->writePPM("5_plate_detect"); #endif delete grad; // free // On construit la liste des (potentiels) plaque extraites de l'image std::cout << "\n>> Analyse des zone retenues\n"; std::vector<ImageGS*> *listImgPlate = new std::vector<ImageGS*>(); char filename[100]; // Chaine de caractère pour la sauvergarde des images for (unsigned n = 0; n < listPlate->size(); ++n) { // on fixe si possible une marge de quelques pixel (pour eviter le crop) int x1 = max((*listPlate)[n][0]-MARGIN_W, 0), y1 = max((*listPlate)[n][1]-MARGIN_H, 0), x2 = min((*listPlate)[n][2]+MARGIN_W, (int)car->getWidth()), y2 = min((*listPlate)[n][3]+MARGIN_H, (int)car->getHeight()); delete[] (*listPlate)[n]; // free unsigned w = x2-x1, h = y2-y1; // On crée la miniature ImageGS *img = new ImageGS(w, h); for (unsigned i = 0; i < h; ++i) for (unsigned j = 0; j < w; ++j) (*img)(i, j) = (*car)(i+y1, j+x1); // On effectué un derniere verification basé sur les edge de la plaque ImageGS *plate = new ImageGS(*img); plate->inverse(); #ifdef _DEBUG_ std::cout << "Variacance: " << plate->computeVariance() << std::endl; #endif // Seuillage automatique plate->thresholdingOstu(); #if 0 width=1; height=3; mask = new float*[height]; for (int i = 0; i < height; ++i) { mask[i] = new float[width]; for (int j = 0; j < width; ++j) mask[i][j] = 255.f; } plate->opening(mask, width, height); #endif /* Erostion / Disatation extraire les contours */ ImageGS erode(*plate); #if 1 width=2; height=2; mask = new float*[height]; for (int i = 0; i < height; ++i) { mask[i] = new float[width]; for (int j = 0; j < width; ++j) mask[i][j] = 255.f; } erode.erosion(mask, width, height); #endif #if 1 width=1; height=3; mask = new float*[height]; for (int i = 0; i < height; ++i) { mask[i] = new float[width]; for (int j = 0; j < width; ++j) mask[i][j] = 255.f; } plate->dilatation(mask, width, height); #endif // on soustrait l'érodé au dilaté pour garder que les contours (*plate) -= erode; #ifdef _DEBUG_ // Save sprintf(filename, "t_plate_%d", n); plate->writePGM(filename); #endif float var=0, var_cpt=0; for (unsigned j = 1; j < w; ++j) { // on compte le nombre de variation var_cpt = 0; if((*plate)(h/3, j) != (*plate)(h/3, j-1)) ++var_cpt; if((*plate)(h/2, j) != (*plate)(h/2, j-1)) ++var_cpt; if((*plate)(h-h/3, j) != (*plate)(h-h/3, j-1)) ++var_cpt; // On pondère le résultat suivant le nombre variations simultanées if(var_cpt == 3) var += 2.f; else if(var_cpt == 2) var += 1.f; else if(var_cpt == 1) var += .5f; } float varRatio = var/(float)(plate->getWidth()+plate->getHeight()); #ifdef _DEBUG_ std::cout << "Variations (seuil 1: "<< T_1_PLATE << " - seuil 2: " << T_2_PLATE << ") - Variations: " << var << " Ratio de variation: " << varRatio << "\n" << std::endl; #endif /* * On Compare d'abord les seuils classiques (variation minimal et maximal) * Puis on regarde si le ratio 'var/taille de la zone' est respecté. * * Si le premier teste n'est pas valide on regarde seulement si le ratio * est suppérieur a un autre seuil. C'est une "sorte" de seuillage par hystéresis. */ if(var > T_1_PLATE && var < T_2_PLATE && varRatio > T_R2_PLATE) listImgPlate->push_back(img); else if(varRatio > T_R1_PLATE) listImgPlate->push_back(img); delete plate; // free } delete listPlate; // Sauvegarde des plaques reconnues for (unsigned n = 0; n < listImgPlate->size(); ++n) { sprintf(filename, "plate_%d", n); (*listImgPlate)[n]->writePGM(filename); sprintf(filename, "display plate_%d.pgm&", n); system(filename); delete (*listImgPlate)[n]; // free } std::cout << "\n>> Programme terminé : " << listImgPlate->size() << " plaques ont/a été reconnue(s).\n"; // free if(car != NULL) { delete listImgPlate; delete car; delete car_detect; delete[] mask; } // Fin compteur d_stop = clock(); double duration = d_stop-d_start; std::cout << "Temps d'éxecution total : " << duration / (double)CLOCKS_PER_SEC << "s\n"; return 0; }