Hi,
I'm a relative newbie to all this and trying to get a simple image processing program to run for a third year undergrad physics project. The program takes in a text image file which contains a 2D array of ints, performs some process on it (details not that important) and then outputs it to a new text file as a 2D array.
The code itself works fine for a 128 by 128 array, but when the array size is increased to anything larger than around 300 by 300, the code compiles, and runs but with no output. Putting print statements in the code show that it doesn't get beyond the variable initialisations.
I want to define an array of around 1000 by 1000 to allow selection of a range of input image sizes. I have tried using enum as an alternative to #define (suggested in a different thread on this site), but this only produced the same result.
The code shown below is just the skeleton of what is to follow - I will add variability of the image file paths and the processing for the image will come later - for now it simply brightens the image.
Code:
#include <stdio.h>
int main(void)
{
enum {NMAX=512, MMAX=512};
int imagearray[NMAX][MMAX], newimage[NMAX][MMAX];
int i,j,x,y,bright;
FILE *fp_in;
FILE *fout;
fp_in=fopen("TumSrc.txt","r");
for(i=0;i<NMAX;i++)
for(j=0;j<MMAX;j++)
{
fscanf(fp_in,"%u",&imagearray[i][j]);
printf("%u \n",imagearray[i][j]);
}
printf("Please enter a brightness value: \n", bright);
scanf("\n%d",&bright);
fout=fopen("newimage2.txt","w");
for (x=0;x<NMAX;x++)
for (y=0;y<MMAX;y++)
{if((imagearray[x][y]+bright)<=255)
newimage[x][y]=imagearray[x][y]+bright;
else newimage[x][y]=255;
}
for (x=0;x<NMAX;x++)
{
for (y=0;y<MMAX;y++)
fprintf(fout,"%u\t",newimage[x][y]);
fprintf(fout,"\n");
}
fclose(fp_in);
fclose(fout);
return 0;
}
I want to allow the user to input image dimensions so that the for loops don't run for the entire array - by defining NMAX and MMAX, the user can specify the for loop sizes using two integer variables (say, n and m). For now I have settled with trying to run for loops up to the values of NMAX and MMAX, but this doesn't work either!!
Any help or suggestions would be appreciated - I don't want my homework doing for me, just a suggestion as to why it doesn't work for large values would be good.....
I'm using XP with Borland 5.5 compiler, but have also got same results from windows 2000 with the same compiler.
Thanks in advance :-)