Error - create an image - different resolutions

asked 2014-10-06 10:09:11 -0600

Thomas M. gravatar image

updated 2014-10-06 10:11:18 -0600

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");

}

edit retag flag offensive close merge delete

Comments

1

Rule 1: if it is using IplImages, - it is outdated.

please lookup how to use cv::Mat instead

berak gravatar imageberak ( 2014-10-06 10:12:56 -0600 )edit
1

"I dont want to paste the whole code, so here is just the interesting part" - unfortunately, the only interesting part went missing, - how do you feed your data into opencv structures ?

berak gravatar imageberak ( 2014-10-06 10:14:30 -0600 )edit

The problem is, im not the best in programming. At the beginning, the includes (i use opencv 2.4.9 ) include <stdio.h> include <math.h> include <opencv2/opencv.hpp> include <opencv2/highgui/highgui.hpp> include <opencv/cv.h> include <math.h> include <stdlib.h> include <string.h>

include "Funktionen.h"

include <iostream>

define PI 3.14159265359

void SI_Function (char AB[75],int Voriteration, int Iteration, long double start, long double stoer, int hoehe, int breite, int laenge, long double x_achse_anfang, long double x_achse_ende, long double y_achse_anfang, long double y_achse_ende, long double b, char dateiname[75], char bildname[75]) { printf("SI-Function");

IplImage *img = cvCreateImage(cvSize(breite,hoehe),IPL_DEPTH_8U,3);     
cvZero(img);
Thomas M. gravatar imageThomas M. ( 2014-10-06 10:20:59 -0600 )edit
1

again, forget IplImages, cv* functions. it's all dead since 2010.

berak gravatar imageberak ( 2014-10-06 10:23:09 -0600 )edit