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); } } }