Exemple #1
0
main( )
{
  load_image_data( );   /* Input of image1 */ 
  sobel_filtering( );   /* Sobel filter is applied to image1 */
  save_image_data( );   /* Output of image2 */
  return 0;
}
Exemple #2
0
int main(int argc, char* argv[])
{

  char *pgmInputFileName, *pgmOutputFileName;
  if(argc < 2 || argc > 3) {
      printf("Usage: %s InputFile.pgm <Output.pgm>\n", argv[0]);
      exit(1);
  }
  else if(argc == 2) {
    pgmInputFileName  = argv[1];
    pgmOutputFileName = "default_output.pgm";
  }
  else if(argc == 3) {
    pgmInputFileName  = argv[1];
    pgmOutputFileName = argv[2];
  }
  
  load_image_file( pgmInputFileName  );   /* Input of image1 */ 
  sobel_filtering( );                     /* Sobel filter is applied to image1 */
  save_image_file( pgmOutputFileName );   /* Output of image2 */
  printf("Output saved...OK\n");
  return 0;

}
Exemple #3
0
int main(void)
{
    unsigned error;
    unsigned char* image;
    unsigned width, height;
    unsigned char* png;
    size_t pngsize;
    LodePNGState state;
    char filename[] = "handmaze.png";  /* NAME OF INPUT IMAGE */

    lodepng_state_init(&state);
    /*optionally customize the state*/
    state.info_raw.colortype = LCT_GREY;

    lodepng_load_file(&png, &pngsize, filename);
    error = lodepng_decode(&image, &width, &height, &state, png, pngsize);
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));

    free(png);

    /*use image here*/
    //printf("Width=%d Height=%d\n", width, height);
    
    //FILE * fp;
    //fp = fopen("imgout.txt", "w");
    //fp = fopen("imgout.ram", "wb");
    //int i,x,y;
    //char * ramimg = (char*) calloc(2*width*height, sizeof(char));
    //for(i = 0; i < 2*width*height; i++){
        //fprintf(fp, "%d (%d,%d)=%d\n", i, i%width, i/width, image[i]);
    //    if(i%2 == 0)
    //        ramimg[i] = image[i/2];
    //    else
    //        ramimg[i] = 0;
    //}
    //fwrite(ramimg, sizeof(unsigned char), 2*width*height, fp);
    //free(ramimg);
    //fclose(fp);
    //for(y = 0; y < height; y++) {
    //    for(x = 0; x < width; x++) {
    //        fprintf(fp, "(%d,%d)=%d\n", x, y, image[coords(x,y,width,height)]);
    //    }
    //}
    
    unsigned char * gaussimg = (unsigned char*) calloc(width*height, sizeof(char));
    unsigned char * outimg = (unsigned char*) calloc(width*height, sizeof(char));
    gaussian_blur(width, height, image, gaussimg);
    sobel_filtering(width, height, gaussimg, outimg);
    
    int right_coord, startx, starty, index1=6, index2=5;
    int block_size =blocksize(width, height, image, &startx, &starty, 7, &right_coord, index1, index2);
    //printf("blocksize = %d\n", block_size);
    
    int solver;
    unsigned char path[144];
    int *size=(int *) malloc(sizeof(int));
    *size = 0;

    solver = dfs(width,height,image, startx, starty, startx, starty, block_size, path, size);
    
    //printf("size = %d\n", *size);
    int i1;
    for(i1 = *size; i1 >= 0; i1--)
    {
        printf("%c\n", path[i1]);
    }
    
    //int x, y;
    //for(x = 0; x < width; x++)
    //{
    //    for(y = 0; y < height; y++)
    //    {
    //        outimg[coords(x,y,width,height)] = image[coords(x,y,width,height)];
    //    }
    //}
    
    unsigned char* outpng;
    error = lodepng_encode(&outpng, &pngsize, outimg, width, height, &state);
    if(!error) lodepng_save_file(outpng, pngsize, "sobel.png");  /* NAME OF OUTPUT IMAGE */
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
    
    
    
    /* CLEANUP */
    lodepng_state_cleanup(&state);
    free(image);
    free(outimg);
    
    return 0;
}