C_ThatGuy's_Computer_Problems

C_ThatGuy's_Computer_Problems - /* CP3 - Digital Picture...

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

View Full Document Right Arrow Icon
/************************************** CP3 - Digital Picture Edge Detection ************************************** Purpose: To process digital pictures and manipulate and output a cleaned edge picture. ************************************** Data Files: cp3.in--input file cp3.out--output file ************************************** #include <stdio.h> #define RC 10 /*defines the maximum row-column size of an array*/ /*Required functions */ int read_pictures(int m,int n,float P[RC] [RC],FILE *fin,FILE *fout); /*Reads in data from data file into an array*/ void threshold_picture(int m, int n,int T[RC] [RC],float P[RC][RC]); /*creates a thresholded image from the data*/ void edges_picture(int m,int n,int T[RC] [RC],int E[RC][RC],FILE *fout); /*detects the edges of the thresholded image and outputs to a file*/ /**********MAIN FUNCTION**********/ main() { FILE *fin,*fout; /*input/output file pointers */ int test; /*Condition*/ int m; /*row size*/ int n; /*column size*/ int count=1; /*data set counter*/ int T[RC][RC]; /*thresholded image array*/ int E[RC][RC]; /*edge-detected image array*/ float P[RC][RC]; /*data-scanned image array*/ /*Begin execution*/ fin=fopen("cp3.in","r"); fout=fopen("cp3.out","w"); fprintf(fout,"Mohamad Salman - masalman@uh.edu\n"); fprintf(fout,"CP3 output\n"); /*loop to process different data sets */ { fprintf(fout,"Image %d:\n",count); /*echo check*/ test = read_pictures(m,n,P,fin,fout); /*input the image*/ if(test==1) { threshold_picture(m,n,T,P); /*threshold the image*/ edges_picture(m,n,T,E,fout); /*output edge-detected image*/ } count++; /*increment data set counter*/ } /*end of input while*/ fclose(fin); fclose(fout); return 0; } /*end of main*/ /**********READ_PICTURES**********/ Purpose: To read in data values from input file into an array Parameters: m--maximum row size; n--maximum column size; P[RC][RC]--scanned image storage fin--input file pointer fout--output file pointer */ int read_pictures(int m,int n,float P[RC] [RC],FILE *fin,FILE *fout) { /* Local variables */ float dump; /*storage for junk variable*/ int i; /*"row" counter*/ int j; /*"column" counter*/ if(m>10 || n>10) /*test whether input data is 10x10*/ {fprintf(fout,"data is not 10 x 10 sized, cannot compute.\n\n"); for(i=0;i<m;i++) {for(j=0;j<n;j++) { fscanf(fin,"%f",&dump); /*dump excess data*/ } } return 0;} else {
Background image of page 1

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

View Full DocumentRight Arrow Icon
for(i=0;i<m;i++) {for(j=0;j<n;j++) { fscanf(fin,"%f",&P[i][j]); /*scan data into array*/ if(P[i][j]>1) P[i][j]=1; /*error correction*/ else if(P[i][j]<0) P[i][j]=0; /*error correction*/ } } return 1; } } /*end of read_pictures*/ /******THRESHOLD_PICTURE********/ void threshold_picture(int m,int n,int T[RC] [RC],float P[RC][RC]) { /* Local variables */ int i; /*"row" counter*/ int j; /*"column" counter*/ for(i=0;i<m;i++) {for(j=0;j<n;j++) { if(P[i][j]>=0.5) T[i][j]=1; else T[i][j]=0; } } } /*end of threshold_pictures*/ /********EDGES_PICTURE************/ /* Purpose: To create an edge-detected image from threshold-processed data and
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/26/2011 for the course ECE 3331 taught by Professor Staff during the Spring '08 term at University of Houston.

Page1 / 14

C_ThatGuy's_Computer_Problems - /* CP3 - Digital Picture...

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

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