CvPoint get_center(IplImage *img) { int origW = img->width; int origH = img->height; ellipseW = origW / factor; ellipseH = origH / factor; mask = new unsigned char[ellipseH * ellipseW]; init_mask(ellipseW, ellipseH); //num = ellipseH * ellipseW; int half_w = ellipseW / 2; int half_h = ellipseH / 2; int ctrX, ctrY; float maxComplax; for (int y = half_h; y < origH - half_h; y++) { for (int x = half_w; x < origW - half_w; x++) { // cvSetImageROI(img, cvEllipse( float complaxVal = get_complax(img, x, y, ellipseW, ellipseH); // printf("%f %d %d\n", complaxVal, x, y); if (complaxVal > maxComplax) { maxComplax = complaxVal; ctrX = x; ctrY = y; } } } cvCircle(img, cvPoint(ctrX, ctrY), half_h, cvScalar(0, 255, 9)); printf("%d %d\n", ctrX, ctrY); show_image(img, "center"); return cvPoint(ctrX, ctrY); }
void init_bitboard(void) { init_mask(); // init_king(); // init_knight(); init_pawns(); }
/** get the segmentation using active contour with initial mask. Note that the initalization has to be done before calling this function (for an unknown reason) * @param aSrc the source image * @param aInitMask the initial mask for the segementation * @param aMaxIts maximum number of iteration * @param aDisp if intermediate results is shown (1-0) */ cv::Mat GTVideo::segmentByActiveContour(const cv::Mat& aSrc, const cv::Mat& aInitMask, int aMaxIts, bool aDisp) { if (NULL == aSrc.data) { std::cerr << "Could not load the image." << std::endl; return cv::Mat(); } const int rows = aSrc.rows; const int cols = aSrc.cols; // set input parameters to the shared object libseg.so // source image (Note: matlab is column-major while C++ is row-major cv::Mat trImage; cv::transpose(aSrc, trImage); mwArray I(rows, cols, mxUINT8_CLASS); I.SetData(trImage.data, rows*cols); // maximum iteration number int maxits[1] = {aMaxIts}; mwArray max_its(1,1, mxINT32_CLASS);//mxUINT8_CLASS); max_its.SetData(maxits, 1); // initial mask of segmentation cv::Mat initmask = aInitMask.clone(); cv::transpose(initmask, initmask); mwArray init_mask(rows, cols, mxUINT8_CLASS); init_mask.SetData(initmask.data, rows*cols); // parameter alpha to the active contour method double alph[1] = {0.2}; mwArray alpha(1,1, mxDOUBLE_CLASS); alpha.SetData(alph, 1); // display intermediate results or not uchar disp[1] = {aDisp?1:0}; mwArray display(1,1, mxUINT8_CLASS); display.SetData(disp, 1); // return value container mwArray imOutput(rows, cols, mxUINT8_CLASS); region_seg(1, imOutput, I, init_mask, max_its, alpha, display); // retrieve result to cv::Mat format uchar result[rows*cols]; imOutput.GetData(result, rows*cols); cv::Mat retImage(rows, cols, CV_8UC1); for (int j=0; j<cols; j++) { for (int i=0; i<rows; i++) { retImage.at<uchar>(i,j) = result[j*rows+i]; } } return retImage; }
void init_context (ps_context* gc, ps_canvas* cs, unsigned char* buf) { float version = (float)ps_version() / 10000; fprintf(stderr, "picasso version %.2f\n", version); pa = ps_path_create(); pm = ps_matrix_create(); mask_buf = (ps_byte*)calloc(1, 320*240); init_mask(mask_buf, 320, 240); m = ps_mask_create_with_data(mask_buf, 320, 240); ps_canvas_set_mask(cs, m); }
int delay_signaling() { if (init_done == 0) init_mask(); if (delaying == 0) { delaying = 1; if (sigprocmask(SIG_BLOCK, &block_sigmask, &saved_sigmask)<0) { /* syslog(LOG_ERR, "sigprocmask: %m");*/ return (-1); } } return (0); }
// Searches for the biggest plane where all elements have the // value $(id) (or don't care) // In this function itself, there are only initializers to get le mask // The function deals with the memory issues (saves new plane) // The real magic takes place in the recursive get_mask function static char term_plane(plane *p, const char *db, \ const char const *curdb, const int bits, \ const unsigned int count, const int id) { if (!((*curdb & 1) == id)) return 0; // There is going to be a plane, so allocate memory for it p->next = malloc(sizeof(plane)); p = p->next; p->next = NULL; char basemask[bits]; init_mask(basemask, count, bits); // Give us the best mask with ONES, starting at bit 0 p->psingle = get_mask(db, basemask, bits, id, 0); return 1; }
int main(void) { int width = 0; int height = 0; int diagonal = 0; char nom[FILENAME_MAX+1] = ""; int len = 0; Image mask = init_mask(); /** * Demande à l'utilisateur : * - le nom du fichier * - la hauteur de l'image * - la largueur de l'image * - la longueur de la diagonal du losange */ do { printf("Entrez un nomn de fichier : "); fgets(nom, FILENAME_MAX+1, stdin); len = strlen(nom) - 1; if ((len >= 0) && nom[len] == '\n') { nom[len] = '\0'; } else { while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n'); } } while ((len < 1) && !feof(stdin) && !ferror(stdin)); char c_par = ' '; // si c_par != '\n', cela veut dire que l'utilisateur a entré des lettres et des chiffres while(height <= 0 || height > MAX_IMAGE_HEIGHT || c_par != '\n') { printf("Hauteur de l'image (max : %d) : ", MAX_IMAGE_HEIGHT); scanf("%d%c", &height, &c_par); if(c_par != '\n') { fprintf(stderr, "Erreur: entrez seulement des nombres !\n"); while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n'); } } while(width <= 0 || width > MAX_IMAGE_WIDTH || c_par != '\n') { printf("Largeur de l'image (max : %d) : ", MAX_IMAGE_WIDTH); scanf("%d%c", &width, &c_par); if(c_par != '\n') { fprintf(stderr, "Erreur: entrez seulement des nombres !\n"); while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n'); } } if(width % 2 == 0 || height % 2 == 0) { if (width == 100) { // si la dimension = 100, elle sera corrigée vers le bas width = 99; } if(height == 100) { height = 99; } width |= 1; //force les valeurs à être impaires height |= 1; printf("Les dimmensions ont été ajustées à des valeurs impaires. \n"); printf("Hauteur : %d, Largeur : %d\n", height, width); } do { printf("Diagonal du losange : "); scanf("%d%c", &diagonal, &c_par); if(c_par != '\n') { fprintf(stderr, "Erreur: entrez seulement des nombres !\n"); while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n'); } } while(diagonal < 0 || (diagonal > height && diagonal > width) || c_par != '\n'); if(diagonal % 2 == 0 && (diagonal == height + 1 || diagonal == width + 1)) { // si la diagonale est égale à une des dimensions entrées (avant ajustement), elle sera corrigée diagonal = diagonal - 1; } /** * dessin du losange et affichage de l'image */ Image i = diamond(height, width, diagonal); display(stdout, i); /** * écriture de l'image dans un fichier puis lecture du fichier */ write_to_file(nom, i); Image r = read_from_file(nom); display(stdout, r); /** * application du filtre et affichage du résultat */ Image res = filter(i, mask); display(stdout, res); return 0; }
int main(int argc, char **argv) { struct PPM *ppm, *ppm_result; char *mask; float *bounds; struct E2D *e_field; float *pot_list; int obj_num; int iter_max; int i; if (argc <= 1) { printf("useage:\n\t%s <PPM-File>\n", argv[0]); return 0; } printf("Loading Image\n"); ppm = PPM_read(argv[1]); if (!ppm) { printf("PPM_read() failed\n"); return 1; } mask = init_mask(ppm->h, ppm->w); bounds = init_bounds(ppm->h, ppm->w); /* Input from stdin */ printf("Input Max Iterations for the (%d x %d) picture: ", ppm->w, ppm->h); if (scanf("%d", &iter_max) == 0) { return 0; } printf("Number of objects: "); if (scanf("%d", &obj_num) == 0) { return 0; } pot_list = (float*) malloc(obj_num * sizeof(float)); printf("Potentials of objects: \n"); for (i = 0; i < obj_num; ++i) { printf("\tObject %d = ", i+1); if (scanf("%f", &pot_list[i]) == 0) { WARNING("Warning: can not read more potentials."); break; } } /* End of Input */ printf("Detecting boundary\n"); ppm_to_boundary(ppm, pot_list, obj_num, mask, bounds); printf("Outputing boundary\n"); ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_gray); PPM_write(ppm_result, "output-boundary-gray.ppm"); PPM_free(ppm_result); printf("Calculating\n"); iteration(ppm->h, ppm->w, mask, bounds, iter_max); printf("Rendering\n"); /* scalar field ø */ ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_gray); PPM_write(ppm_result, "output-Phi-gray.ppm"); PPM_free(ppm_result); ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_hue); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-Phi-hue.ppm"); PPM_free(ppm_result); /* END scalar field ø */ /* E² = |grad ø|^2 */ e_field = potential_to_E(ppm->h, ppm->w, bounds); ppm_result = render_E(ppm->h, ppm->w, e_field, PPM_table_gray); PPM_write(ppm_result, "output-E-Field-gray.ppm"); PPM_free(ppm_result); ppm_result = render_E(ppm->h, ppm->w, e_field, PPM_table_hue); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-E-Field-hue.ppm"); PPM_free(ppm_result); free(e_field); /* END E² */ ppm_result = draw_e_lines(ppm->h, ppm->w, mask, bounds, COLOR_RED); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-E-Lines.ppm"); PPM_free(ppm_result); free(pot_list); free(mask); free(bounds); PPM_free(ppm); return 0; }