DS_Packet

DS_Packet - image_io_v1.c 1: #include...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: image_io_v1.c 1: #include <strings.h> 2: #include <math.h> 3: #include <stdio.h> 4: 5: 6: int main (int argc, char **argv) 7: { 8: int i1[512][512], i2[512][512]; 9: int O, l, N1, N2, t; 10: FILE *fp; 11: char str[10]; 12: 13: fp = fopen(argv[1], "r"); 14: fscanf(fp, "%s", str); 15: if (strcmp (str, "P5") == 0) { 16: fscanf(fp, "%d %d ", &N2, &N1); 17: fscanf(fp, "%d ", &O) ; 18: 19: for (O=0; O < N1; O++) { 20: for (l=0; l < N2; l++) { 21: i1[O][l] = (unsigned char) (getc(fp)); 22: } 23: } 24: fclose(fp); 25: 26: t = atoi(argv[3]); 27: for (O=0; O < N1; O++) { 28: for (l=0; l < N2; l++) { 29: if (i1[O][l] > t) i2[O][l] = 255; 30: else i2[0][l] = 0; 31: } 32: } 33: fp = fopen(argv[2], "w"); 34: fprintf(fp, "P5\n"); 35: fprintf(fp, "%d %d\n255\n", N2, N1); 36: for (O=0; O < N1; O++) { 37: for (l=0; l < N2; l++) { 38: putc((unsigned char)i2[O][l], fp); 39: } 40: } 41: fclose(fp); 42: } 43: } 1 image_io_v2.c 1: #include <strings.h> 2: #include <math.h> 3: #include <stdio.h> 4: 5: 6: int main (int argc, char **argv) 7: { 8: int input_image[512][512], output_image[512][512]; 9: int row, col, MaxRows, MaxCols, ThresholdValue; 10: FILE *fp; 11: char str[10]; 12: 13: fp = fopen(argv[1], "r"); 14: fscanf(fp, "%s", str); 15: if (strcmp (str, "P5") == 0) { 16: fscanf(fp, "%d %d ", &MaxCols, &MaxRows); 17: fscanf(fp, "%d ", &row) ; 18: 19: for (row=0; row < MaxRows; row++) { 20: for (col=0; col < MaxCols; col++) { 21: input_image[row][col] = (unsigned char) (getc(fp)) ; 22: } 23: } 24: fclose(fp); 25: 26: ThresholdValue = atoi(argv[3]); 27: for (row=0; row < MaxRows; row++) { 28: for (col=0; col < MaxCols; col++) { 29: if (input_image[row][col] > ThresholdValue) 30: output_image[row][col] = 255; 31: else output_image[row][col] = 0; 32: } 33: } 34: fp = fopen(argv[2], "w"); 35: fprintf(fp, "P5\n"); 36: fprintf(fp, "%d %d\n255\n", MaxCols, MaxRows); 37: for (row=0; row < MaxRows; row++) { 38: for (col=0; col < MaxCols; col++) { 39: putc((unsigned char)output_image[row][col], fp); 40: } 41: } 42: fclose(fp); 43: } 44: } 2 image_io_v3.c 1: #include <strings.h> 2: #include <math.h> 3: #include <stdio.h> 4: #include <stdlib.h> 5: 6: #define MAXSIZE 512 7: int ReadImage (char *FileName, int Image[MAXSIZE], int *Height, int *Width); 8: int SaveImage (char *FileName, int Image[MAXSIZE], int Height, int Width); 9: 10: /*-----------------------------------------------------------------------*/ 11: int main (int argc, char **argv) 12: { 13: int input_image[MAXSIZE][MAXSIZE], output_image[MAXSIZE][MAXSIZE]; 14: int row, col, MaxRows, MaxCols, ThresholdValue; 15: 16: if (argc != 4) { 17: fprintf(stderr, "\nUsage: %s InImageFile OutImageFile ThresholdVal ue\n", argv[0]); 18: exit(1); 19: } 20: ReadImage (argv[1], input_image, &MaxRows, &MaxCols); 21: 22: ThresholdValue = atoi(argv[3]); 23: for (row=0; row < MaxRows; row++) { 24: for (col=0; col < MaxCols; col++) { 25: if (input_image[row][col] > ThresholdValue) 26: output_image[row][col] = 255; 27: else output_image[row][col] = 0;...
View Full Document

Page1 / 50

DS_Packet - image_io_v1.c 1: #include...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online