- #1
hilman
- 17
- 0
Hello guys. I want to ask something about simple spatial resolution manipulating just by using c language. I have done my programming below, it managed to be compiled but for some reasons the program stucked in the middle when I try to run it. Really hope you guys can help. I am extremely beginner on this.
I am really a beginner, so, sorry if it is lacking too much.
[ EDIT ] Listing edited by mentor for better readability using code tags
C:
#include<stdio.h>
#define width 640
#define height 581
int main(void)
{
FILE *fp;
unsignedchar header[54];
unsignedchar img_work[width][height][3];
char input_file[128],output_file[128];
int v, h, w, i, c, s, ave_w[width], ave_h[height], average_h, average_w;
/*------------Reading image------------*/
printf("Enter name of the file¥n---");
scanf("%s",input_file);
printf("The file that would be processed is %s.¥n", input_file);
fp=fopen(input_file,"rb");
fread(header,1,54,fp);
fread(img_work,1,width*height*3,fp);
fclose(fp);
/*------------Spatial Resolution Program------------*/
printf ("enter level of spatialization-- ");
scanf ("%d", &v);
for (i=0; i<v; i++) {
s = s + s;
}
for(c=0; c<3; c++){
for(h=0; h<height; h++){
for(w=0; w<width; w=w+s){
average_w = 0;
for (i=0; i<s; i++) {
ave_w[i] = img_work[w+i][h][c] / s;
average_w = average_w + ave_w;
}
for (i=0; i<width; i=i+s) {
img_work[w+i][h][c] = average_w;
}
}
}
}
for(c=0; c<3; c++) {
for(w=0; w<width; w++) {
for(h=0; h<height; h=h+s) {
average_h = 0;
for (i=0; i<s; i++) {
ave_h[i] = img_work[w][h+i][c] / s;
average_h = average_h + ave_h[i];
}
for (i=0; i<height; i=i+s) {
img_work[w][h+i][c] = average_h;
}
}
}
}
/*------------Writing File------------*/
printf("Enter the name of the file that would be saved.¥n---");
scanf("%s",output_file);
printf("Name of the file that would be saved is %s.¥n",output_file);
fp=fopen(output_file,"wb");
fwrite(header,1,54,fp);
fwrite(img_work,1,width*height*3,fp);
fclose(fp);
printf("End.¥n");
return 0;
}
[ EDIT ] Listing edited by mentor for better readability using code tags
Last edited by a moderator: