Esempio n. 1
0
int main(int argc, char *argv[])
{
  PICTURE *pic,*pic2;
  int opdim = 4;
  float lowthresh = 0.05f, highthresh = 0.9f;

  switch (argc) {
	case 6: highthresh = (float)atof(argv[5]); argc--;
	case 5: lowthresh = (float)atof(argv[4]); argc--;
	case 4: opdim = atoi(argv[3]); argc--;
	case 3: case 2: case 1: dofiles(argc,argv); 
		fprintf(stderr,"%s: operator side = %d\n", PROGNAME,opdim); 
		break;
	default: fprintf(stderr,
	"usage: %s [infile] [outfile] [side] [lowthresh] [highthresh]\n",
				PROGNAME);
		exit(1); }
  if ((pic = readpic(FILEIN)) == NULL) 
		{ fprintf(stderr,"%s: failed to read input file\n",PROGNAME); 
			exit(1); }
  if ((pic->fileid) != IMAGE_ID)
		{ fprintf(stderr,"%s: wrong type of input file\n",PROGNAME); 
			exit(1); }
  timex(); pic = grad(pic,opdim); timex();
  // pic = morphgrads(pic); /* optional thinning */
  pic = gradmag(pic);
  pic2  = ftoim(pic,lowthresh,highthresh,1); 
  freepic(pic); /* ftoim does not free pic */
  writepmpic(pic2,FILEOUT);
  exit(0);
}
Esempio n. 2
0
/*
Send a picture to the LCD. Buff should point to a large enough page-aligned
buffer. It's not allocated inside the routine for speed reasons.
*/
int sendpic(int f, char* file, char* buff) {
    int y;
    y=readpic(file,buff);
    if (!y) return 0;
    lseek(f,0x4200,SEEK_SET);
    write(f,buff,128*128*2);
    return 1;
}
Esempio n. 3
0
void wxPicToolFrame::OnbtnExtractOneClick(wxCommandEvent& event)
{

    if (indexchoice_tb == -1) {
        wxMessageBox(_("Make a choice first, then give commands, sir."), _("I'm sorry, captain, I can't do much more"));
        return;
    }
    SDL_Surface* s;

    SDL_Init(SDL_INIT_VIDEO);
    wxString fn;
    fn.Printf("Tibia%d.bmp", indexchoice_tb);
    fn = txtOutput->GetValue() + "/" + fn;

    if(readpic(txtPic->GetValue().c_str(), indexchoice_tb, &s)){
        wxMessageBox(_("Reading of the sprite file has failed.\n"
                       "Hast thou messed it up?\n"
                       "Hast thou placed it in wrong place?\n"
                       "Thee must fix the file."), _("I'm sorry, captain, I can't do much more"));
        SDL_Quit();
        return;
    }

    if(SDL_SaveBMP(s, fn.c_str())){
        wxMessageBox(_("Thy bitmap file is unwritable"), _("I'm sorry, captain, I can't do much more"));
        SDL_FreeSurface(s);
        SDL_Quit();
        return;
    }
    wxMessageBox(_("Thou hast succeeded, mighty nightly lord!"), _("YOU WIN"));

    SDL_FreeSurface(s);
    SDL_Quit();


}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  PICTURE *pic;
  int bperc = 5, wperc = 5, sz;
  vmessage();
  switch (argc) {
    case 5: wperc = atoi(argv[4]);
    case 4: bperc = atoi(argv[3]);
    case 3: case 2: dofiles(argc,argv);
 /*  fprintf(stderr,"%s %d %d %s %s\n",PROGNAME,bperc,wperc,FILEIN,FILEOUT); */
		break;
    default: (void)fprintf(stderr,
	     "usage: contrast infile outfile [blackpercent][whitepercent]\n");
      exit(1);  }
  if ((pic = readpic(FILEIN)) == NULL) exit(1);
  if ((pic->fileid) != IMAGE_ID)
	{ (void)fprintf(stderr,"%s: wrong type of input file\n",PROGNAME);
      exit(1);
   }
	sz = (pic->items)*(pic->samples);
  contrast(pic,bperc*sz/100,wperc*sz/100);
  writepmpic(pic,FILEOUT);
  exit(0);
}
Esempio n. 5
0
int main (int argc, char **argv) {
	SDL_Surface *s = NULL;

	if (argc == 1){
		fprintf(stderr, "pictool: no input files\n");
		exit(1);
	}
	if(argc == 2){
		if(!strcmp(argv[1], "--help")){
			show_help();
			exit(0);
		}
		else{
			if(picdetails(argv[1])){
				fprintf(stderr, "pictool: bad format\n");
				exit(4);
			}
			exit(0);
		}
	}
	if(argc == 3){
		fprintf(stderr, "pictool: not enough arguments\n");
		exit(2);
	}

	SDL_Init(SDL_INIT_VIDEO);

	if(argc == 5 && !strcmp(argv[4], "--topic")){
	    int error;
		dbgprintf(":: Loading from bitmap %s\n", argv[3]);
		s = SDL_LoadBMP(argv[3]);
		dbgprintf(":: Success\n");

		if (error = writepic(argv[1], atoi(argv[2]), s))
		{
		    printf("Error writing pic: %d\n", error);
		    exit(error);
		}
		SDL_FreeSurface(s);
	}
	else if(argc == 4 || !strcmp(argv[4], "--tobmp")){
		if(readpic(argv[1], atoi(argv[2]), &s)){
			fprintf(stderr, "pictool: conversion to bmp failed: bad format\n");
			SDL_Quit();
			exit(4);
		}
		dbgprintf(":: Saving to %s\n", argv[3]);
		if(SDL_SaveBMP(s, argv[3])){
			fprintf(stderr, "pictool: saving to bmp failed\n");
			SDL_Quit();
			exit(6);
		}
		dbgprintf(":: Success\n");
		SDL_FreeSurface(s);
	}
	else{
		fprintf(stderr, "pictool: unrecognized argument\n");
		SDL_Quit();
		exit(5);
	}

    dbgprintf(":: SDLQuit\n");
    SDL_Quit();
    dbgprintf(":: Return\n");
	return 0;
}
Esempio n. 6
0
int main()
{
	char fileName[BUFFER_SIZE],fileName2[BUFFER_SIZE],ci;
	int i,j,rows,cols,option=1;
  int value=0;

	printf("\tOption #0: Quit.\n");
	printf("\tOption #1: Add to brightness.\n");
	printf("\tOption #2: Subtract from brightness.\n");
	printf("\tOption #3: Sobel edge highlighter.\n");

	while (option){
		printf("\nEnter a number (1-3) to specify an option listed above: ");
		scanf("%d", &option);

		if (option<0||option>3)
			printf("Please enter a number between 0 and 3.\n");
		else if (option==0)
			break;

    switch(option){
      case 1:
      	// Add (value) to brightness of image
	  	  printf("Enter image filename: ");
	  	  scanf("%s", fileName);
		    img = readpic(fileName);
		    printf("Successfully read image file '%s'\n", fileName);
        printf("How much would you like to increment the brightness in the image? ");
        scanf("%d", &value);
        
        // add given brightness value to image
    		addtopixels(img,value);
    		printf("Enter image filename for output: ");
				scanf("%s", fileName);
				
				// write out temporary buffer to actual image file
				writeoutpic(fileName,img);
        break;

      case 2:
      	// subtract (value) to brightness of image
        // Read first image
        printf("Enter first image file: ");
        scanf("%s", fileName);
        img = readpic(fileName);
        printf("Successfully read image file '%s'\n", fileName);

        // Read second image
        printf("Enter another image file: ");
        scanf("%s", fileName2);
        printf("Successfully read image file '%s'\n", fileName2);
        printf("How much would you like to decrement the brightness in the image? ");
        scanf("%d", &value);
        addtopixels(img,0-value);
        
				printf("Enter image filename for output: ");
				scanf("%s", fileName);
				
				// write out subtracted brightness image buffer to designated
				// image file
				writeoutpic(fileName,img);
        break;

      case 3:
        // sobel edge highlighter
        printf("Enter image filename: ");
        scanf("%s", fileName);
        img = readpic(fileName);
        printf("Successfully read image file '%s'\n", fileName);
        
        // Initialize temporary image variables
        sobelout = setImage();
				temppicx = setImage();
				temppicy = setImage();
				
				// Call sobel function on temporary images and input image
				sobelfunc(img,sobelout,temppicx,temppicy); 
				printf("Enter image filename for output: ");
				scanf("%s", fileName);
				
				// Write temporary file out to designated filename
				writeoutpic(fileName,sobelout);
				
				// Free temporary sobel func-only image files
				free(sobelout);
				free(temppicx);
				free(temppicy);
        break;

      default:
      	// if the user is retarded or entered 0, exit
        printf("Exiting.\n");
        free(img);
        break;
    }
    
    // free all the temporary image files
		free(img);
    free(img2);
		img = NULL;
    img2 = NULL;

		return(EXIT_SUCCESS);
	}
}
int main()
//Declare and initialize Variables inside main function
{
        char fileName[BUFFER_SIZE];
        int i,j,rows,cols,user_input=0,Value1=0,loop=1;
        char ci;

//Print out menu
while (loop = 1){
       // printf("Please select an option:\n");
       // printf("1) Read in a picture file and process it.\n");
       // printf("2) Read in two picture files and subtract the second picture from the first.\n");
        printf("Read in a pic and apply the sobelfunc function to it.                           Use a grayscale pic saved as a *.pgm in your computer                           Please enter the number 3 on your keyboard and then hit the enter key                        \n");
      //  printf("4) Exit.\n");

        scanf("%d", &user_input);

//Read in an image and prompt user to enter a value for the image
 
        if (user_input == 1){
        printf("enter image filename in the format *.pgm: ");
        scanf("%s", fileName);

        img = readpic(fileName);

        printf("Successfully read image file '%s'\n", fileName);
        
        printf("Enter a value for the picture: ");
        scanf("%d", &Value1);
        system("pause");
        F3(img, numRows, numCols, Value1);
        F4(img, numRows, numCols, Value1);

        printf("Enter image filename for output: ");
        scanf("%s", fileName);

        writeoutpic(fileName,img);

        free(img);
        img = NULL;
                                  }
//Read in two images and subtract the second from the first
        else if (user_input == 2) {
        printf("Enter first image filename: ");
          scanf("%s", fileName);
       //   temppicx = readpic(fileName);
          
          printf("Enter second image filename: ");
          scanf("%s", fileName);
         // temppicy = readpic(fileName);
          
        //  sobelout = setImage();      
       //   subtractpixels(sobelout, temppicx, temppicy);
          printf("Enter image filename for output: ");
          scanf("%s", fileName);

         // writeoutpic(fileName,sobelout);    
          free(temppicx);
          temppicx = NULL;   
          free(temppicy);
          temppicy = NULL;
        
                                   }
//Read in a picture and apply the sobelfunc function to it
        else if (user_input == 3){

        printf("Enter pic filename (*.pgm, example dog.pgm): ");
                scanf("%s", fileName);

                img = readpic(fileName);  

                sobelout= setdImage();
                          
                
                candid = setImage();  

                sobelout= setdImage();
                temppicx= setdImage();
                temppicy= setdImage();
                
                finaly= setImage();
                sobelout2=setImage();
                 
               cannyfunc(img,sobelout,temppicx,temppicy,candid,finaly);

                printf("Enter mag filename for output: ");
                scanf("%s", fileName);
for(i=0;i<numRows;i++) for (j=0;j<numCols;j++) sobelout2[i][j]= (int) sobelout[i][j];
              writeoutpic(fileName,sobelout2); 
                
                    
                printf("Enter peaks filename for output: ");
                scanf("%s", fileName);

               writeoutpic(fileName,candid); 
                printf("Enter final filename for output: ");
                scanf("%s", fileName);

             writeoutpic(fileName,finaly);
                    
                    
                free(img);
                img = NULL;
        
                                  }
  
        
//Exit the program.
        else if (user_input == 4) {
        return(EXIT_SUCCESS);     
                                 }
                                  }
        
}