int count_cb(void) { int num; if(gc.image == NULL || imgGetDimColorSpace(gc.image) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } num = imgCount(gc.image); IupSetfAttribute(gc.msgbar, "TITLE", "Objects in this picture: %d", num); return IUP_DEFAULT; }
int dilate_cb(void) { Image *tmp = gc.image; if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatating ..."); gc.image = imgDilatation(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatated ..."); return IUP_DEFAULT; }
int change_cb(void) { Image *tmp = gc.image; if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } IupSetfAttribute(gc.msgbar, "TITLE", "Changing binary colors ..."); gc.image = imgChangeBinary(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Binary colors changed ..."); return IUP_DEFAULT; }
Image* Colony::generateProbabilityImage( Image* input ) { if (imgGetDimColorSpace( input ) != 1) return 0; Image* output = imgCopy( input ); float* data = imgGetData( output ); int size = imgGetWidth( output ) * imgGetHeight( output ); float sum = 0; for (int i = 0; i < size; ++i) { sum += data[i]; } for (int i = 0; i < size; ++i) { data[i] /= sum; } return output; }
Colony::Colony(Image* image, DirectionalField* directionalFied) { if (imgGetDimColorSpace( image ) != 1) { Image* aux = imgGrey( image ); imgDestroy( image ); image = aux; aux = 0; } // Normalize image //imgNormalize( image, 2 ); // Apply gaussian filter for noise reduction //imgGauss( image ); imgWriteBMP( (char*)"debugImg/inputAfterGaussian.bmp", image ); _environment = new Environment( INITIAL_PHEROMONE, MIN_PHEROMONE, EVAPORATION_RATE, image, directionalFied ); generateProbabilityImages(); }
Image* Colony::generateProbabilityImage( Image* input ) { if (imgGetDimColorSpace( input ) != 1) return 0; Image* output = imgCopy( input ); float* data = imgGetData( output ); int size = imgGetWidth( output ) * imgGetHeight( output ); float sum = 0; for (int i = 0; i < size; ++i) { // if (isnan(data[i])) // { // printf( "Cannot generate probability image, NAN detected! on pixel %d\n", i ); // } sum += data[i]; } for (int i = 0; i < size; ++i) { data[i] /= sum; } return output; }