Question: #include #include #include #define ROWS 512 #define COLUMNS 512 #define sqr(x) ((x)*(x)) int main( int argc, char **argv ) { int i, j, k; int


#include
#define ROWS 512 #define COLUMNS 512
#define sqr(x) ((x)*(x))
int main( int argc, char **argv ) {
int i, j, k; int threshold[3], A; FILE *fp; char *ifile, *ofile; unsigned char image[ROWS][COLUMNS], bimage[ROWS][COLUMNS], head[32]; char filename[9][50], ch; float xbar, ybar;
strcpy(filename[0], "image1.raw"); strcpy(filename[1], "image1-b.ras"); strcpy(filename[2], "image1.ras"); strcpy(filename[3], "image2.raw"); strcpy(filename[4], "image2-b.ras"); strcpy(filename[5], "image2.ras"); strcpy(filename[6], "image3.raw"); strcpy(filename[7], "image3-b.ras"); strcpy(filename[8], "image3.ras"); header ( ROWS, COLUMNS, head );
printf("Filename: Threshold Area X Y ");
for ( k = 0; k
/* Read the image */ if (( fp = fopen( ifile, "rb" )) == NULL ) { fprintf( stderr, "error: couldn't open %s ", ifile ); exit( 1 ); }
for ( i = 0; i
/* Convert each image into binary image with its respective threshold value compute the center of same image and mark the center of same image*/ /* Save the binary image */ ofile = filename[3*k+1]; if (( fp = fopen( ofile, "wb" )) == NULL ) { fprintf( stderr, "error: could not open %s ", ofile ); exit( 1 ); } fwrite( head, 4, 8, fp ); for ( i = 0 ; i
printf("%s: %d %d %d %d ", ifile, threshold[k], A, (int)xbar, (int)ybar);
/* Save the original image as ras */ ofile = filename[3*k+2]; if (( fp = fopen(ofile, "wb" )) == NULL ) { fprintf( stderr, "error: could not open %s ", ofile ); exit( 1 ); } fwrite( head, 4, 8, fp ); for ( i = 0 ; i
}
printf("Press any key to exit: "); gets ( &ch );
return 0; }
void clear( unsigned char image[][COLUMNS] ) { int i,j; for ( i = 0 ; i
void header( int row, int col, unsigned char head[32] ) { int *p = (int *)head; char *ch; int num = row * col;
/* Choose little-endian or big-endian header depending on the machine. Don't modify this */ /* Little-endian for PC */ *p = 0x956aa659; *(p + 3) = 0x08000000; *(p + 5) = 0x01000000; *(p + 6) = 0x0; *(p + 7) = 0x00000000;
ch = (char*)&col; head[7] = *ch; ch ++; head[6] = *ch; ch ++; head[5] = *ch; ch ++; head[4] = *ch;
ch = (char*)&row; head[11] = *ch; ch ++; head[10] = *ch; ch ++; head[9] = *ch; ch ++; head[8] = *ch; ch = (char*)# head[19] = *ch; ch ++; head[18] = *ch; ch ++; head[17] = *ch; ch ++; head[16] = *ch;
/* Big-endian for unix */ /* *p = 0x59a66a95; *(p + 1) = col; *(p + 2) = row; *(p + 3) = 0x8; *(p + 4) = num; *(p + 5) = 0x1; *(p + 6) = 0x0; *(p + 7) = 0xf8; */ }
Computer Problem For each of three supplied 512 X 512 gray level images 1) Display the gray level image 2) Use GIMP or IrfanView to display a gray level histogram of the image. 3) Choose a threshold that will separate object from background 4) Write a program to threshold the gray level image to obtain a binary image. For display purposes, let gray level 0 indicate background and let gray level 255 indicate object in the binary image. Your program should print out the area and center of area of the object and output the binary image with the center of area indicated by a small cross with gray level 128. You may assume for all calculations that there is only one connected object in the binary image. You do not need to find connected components. 5) Display the binary image that your program generates and check that your center of area appears correct. For each of the three images, submit your generated binary image and the values for your threshold, the object area, and the object center of area (x, y). Assume that the origin (0,0) of the (x,y) coordinate system is at the bottom left corner of the image. O > 0 = A Area = , b(x, y) b(x, y) has value 0 or 1 Center Ex Lyxb(x,y), Xo Ex Ey yb(x,) Y) Yo Indicate the center using a small but obvious cross or 50x50 patch with gray level 128. Origin of the (x,y) coordinate system is at the bottom left corner of the image (transform between two coordinate systems). , O = A
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
