{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C_ThatGuy's_Computer_Problems

C_ThatGuy's_Computer_Problems - CP3 Digital Picture Edge...

Info iconThis preview shows pages 1–4. 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 - [email protected]\n"); fprintf(fout,"CP3 output\n"); /*loop to process different data sets */ while(fscanf(fin,"%d %d",&m,&n)>0) { 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 Document Right 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 output to a file. Parameters: m--maximum row size; n--maximum column size; T[RC][RC]--threshold image storage E[RC][RC]-- edge-detected image storage fout--output file pointer*/ void edges_picture(int m,int n,int T[RC] [RC],int E[RC][RC],FILE *fout){ /* Local variables */ int i; /*"row" counter*/ int j; /*"column" counter*/ for (i=0; i<m; i++) for[j=0; j<n;j++) E[i][j]=0; { if (T[i][j] !=1) continue; if (i-1>=0 && T[I-1][j]==0) E[i][j]=1; if (I+1<m && T[I+1][j]==0) E[i][j]=1; if (j-1>=0 && T[i][j-1]==0) E[i][j]=1; if (j+1<n && T[i][j+1]==0) E[i][j]=1; } for(i=0;i<m;i++) {for(j=0;j<n;j++) { fprintf(fout,"%d\t",E[i][j]); } fprintf(fout,"\n"); } fprintf(fout,"\n"); } /*end of edges_pictures*/ /***********End of file*****************/
Background image of page 2
/*********************************** CP4 - Morse Code Encoder/Decoder ************************************ Purpose: To implement the encoding and decoding of messages using Morse Code.
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}