Ask Your Question

Revision history [back]

Error - create an image - different resolutions

Hello,

im trying to create a pricture from an array. Sometimes it works and sometimes not. 1st correct one: 500x503 2nd something wrong 500x500 (500x501, 500x502 the same) there is a diagonal in the picture and i dont know why. 1st: image description

2nd: image description

in the daten[count_array] are 500x500 values that need to be printed.

I dont want to paste the whole code, so here is just the interesting part:

.....
difference = max_value - min_value; //diff for scaling
skalierung = difference/255; //scaling 

count_array = 0;
fp = fopen(dateiname,"w");//open file and write ...
if(fp==NULL)
    fprintf(stderr,"Error!\n");

//write details in .txt
fprintf(fp,"%d\n",hoehe);//hight 
fprintf(fp,"%d\n",breite);//width
fprintf(fp,"%Lf\n",min_value); 
fprintf(fp,"%Lf\n",max_value);


//create picture
for(i=1; i<=((hoehe)*(breite)); i++)                    //height*width
{
    lambda = daten[count_array];                        //read Lyapunov-value from array
    fprintf(fp,"%Lf\n",lambda);                         //write current value in .txt
    count_array++;                                      //next lyapunov value

    for (n=min_value; n<=max_value; n=n+skalierung)     //grey value 1-255
    {
        if (lambda>=n && lambda<(n+skalierung))         //correct grey value ?
        {

//write pixel -> x start=0 ; y start=255 ; count= grey-value startvalue = 255
            cvLine(img,cvPoint(x,y),cvPoint(x,y),CV_RGB(count,count,count));
            Anzahl[count]=Anzahl[count]+1;              //count number of pixels with that grey-value
            break;                                      //exit loop, go to next pixel
        }
        else
        {
            count=count-1;                              //no->next grey value
        }
    }
    y=y-1;//decrease y -> rows
    count=255;//grey-value -> start-value

//if y=0 increase x and set y to start-value    
    if (y==0)
    {
        y=hoehe;
        x++;
    }
}
for (i=0; i<=255; i++)
{
    printf("Anzahl[%d]: %d\n", i, Anzahl[i]);//Number of pixels with grey-value i
}

//save,show,close picture
fclose(fp);
cvSaveImage(bildname, img);                                                                             
cvNamedWindow("Test",2);
cvShowImage("Test",img);
cvWaitKey();    
cvReleaseImage(&img);
cvDestroyWindow("Test");

}

Error - create an image - different resolutions

Hello,

im trying to create a pricture from an array. Sometimes it works and sometimes not. not.

1st correct one: 500x503 500x503

2nd something wrong 500x500 (500x501, 500x502 the same) there is a diagonal in the picture and i dont know why. 1st: why.

1st: image description

2nd: image description

in the daten[count_array] are 500x500 values that need to be printed.

I dont want to paste the whole code, so here is just the interesting part:

.....
difference = max_value - min_value; //diff for scaling
skalierung = difference/255; //scaling 

count_array = 0;
fp = fopen(dateiname,"w");//open file and write ...
if(fp==NULL)
    fprintf(stderr,"Error!\n");

//write details in .txt
fprintf(fp,"%d\n",hoehe);//hight 
fprintf(fp,"%d\n",breite);//width
fprintf(fp,"%Lf\n",min_value); 
fprintf(fp,"%Lf\n",max_value);


//create picture
for(i=1; i<=((hoehe)*(breite)); i++)                    //height*width
{
    lambda = daten[count_array];                        //read Lyapunov-value from array
    fprintf(fp,"%Lf\n",lambda);                         //write current value in .txt
    count_array++;                                      //next lyapunov value

    for (n=min_value; n<=max_value; n=n+skalierung)     //grey value 1-255
    {
        if (lambda>=n && lambda<(n+skalierung))         //correct grey value ?
        {

//write pixel -> x start=0 ; y start=255 ; count= grey-value startvalue = 255
            cvLine(img,cvPoint(x,y),cvPoint(x,y),CV_RGB(count,count,count));
            Anzahl[count]=Anzahl[count]+1;              //count number of pixels with that grey-value
            break;                                      //exit loop, go to next pixel
        }
        else
        {
            count=count-1;                              //no->next grey value
        }
    }
    y=y-1;//decrease y -> rows
    count=255;//grey-value -> start-value

//if y=0 increase x and set y to start-value    
    if (y==0)
    {
        y=hoehe;
        x++;
    }
}
for (i=0; i<=255; i++)
{
    printf("Anzahl[%d]: %d\n", i, Anzahl[i]);//Number of pixels with grey-value i
}

//save,show,close picture
fclose(fp);
cvSaveImage(bildname, img);                                                                             
cvNamedWindow("Test",2);
cvShowImage("Test",img);
cvWaitKey();    
cvReleaseImage(&img);
cvDestroyWindow("Test");

}