Geometry Transformation and Bilinear Interpolation

This is a discussion on Geometry Transformation and Bilinear Interpolation within the C Programming forums, part of the General Programming Boards category; Hallo, I´ve already write my programm for the geometry Transformation from Picture in c.But now i want to test in ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    Geometry Transformation and Bilinear Interpolation

    Hallo, I´ve already write my programm for the geometry Transformation from Picture in c.But now i want to test in the main() and that isnot work. I use the affine Transformation to scale,rotate and cross the Picture.Thanks for your help.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    #define AUS 150
    short **allocate_image_array(int length,int width);
    int BerechnungTerm(float a1,float a2,float a0,float b1,float b2,float b0,int bilinear,int n,int m,short **out_bild,short **in_bild) ;
    
    main()
    {  float a1=2.2, a2=3.2,a0=1.2, b1=2.0, b2=2.1, b0=2.3;
       int m=16,n=16,i,j,bilinear=0;
       short out_bild[16][16];
      short in_bild[16][16]=
      { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
    -3,0,0,3,0,0,0,0,-2,0,0,-1,0,0,0,0,
    2,0,0,-2,0,0,0,0,1,0,0,1,0,0,0,0,
    0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,
    0,0,0,0,-3,0,0,3,0,0,0,0,-2,0,0,-1,
    0,0,0,0,2,0,0,-2,0,0,0,0,1,0,0,1,
    -3,3,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,-3,3,0,0,-2,-1,0,0,
    9,-9,9,-9,6,3,-3,-6,6,-6,-3,3,4,2,1,2,
    -6,6,-6,6,-4,-2,2,4,-3,3,3,-3,-2,-1,-1,-2,
    2,-2,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,2,-2,0,0,1,1,0,0,
    -6,6,-6,6,-3,-3,3,3,-4,4,2,-2,-2,-2,-1,-1,
    4,-4,4,-4,2,2,-2,-2,2,-2,-2,2,1,1,1,1};
    //if(Bilinear==0)
    BerechnungTerm(a1,a2,a0,b1,b2,b0,bilinear,n,m,**out_bild,**in_bild);
    //printf("Bere")
       system("Pause");
          }
    /*----------------------------------------------------------------------------*/
    /*Hier wird zuerst ein speicherplatz reserviert*/
    /*----------------------------------------------------------------------------*/
    
    
    short **allocate_image_array(int length,int width)
    //long length, width;
    {
    int i;
    typedef int* ptr;
    //short **the_array;
    ptr* the_array = (ptr*) malloc(length * sizeof(int *));
    for(i=0; i<length; i++){
      if(the_array[i] == '\0'){
        printf("\n\tmalloc of the_image[%d] failed", i);
      } /* ends if */
    } /* ends loop over i */
    //return(the_array);
    } /* ends allocate_image_array */
    
    /*----------------------------------------------------------------------------*/
    /*Hier wird der Speicherplatz freigegeben*/
    /*----------------------------------------------------------------------------*/
    
    void free_image_array(int **the_array,int length)
    //short **the_array;
    //long length;
    {
    int i;
    for(i=0; i<length; i++)
    free(the_array[i]);
    //return(1);
    } /* ends free_image_array */
    
    
    /*----------------------------------------------------------------------------*/
    /*Methode Bilinear Interpolation*/
    /*----------------------------------------------------------------------------*/
    
    short bil_int(short **in_Bild,double x,double y,long izeilen,long jspalten)
    {double fractionx,fractiony,unmoinx,unmoiny,temp_double;
     int ceilx,ceily,floorx,floory;
     short A,B,C,result=AUS;
    
     if(x<0.0||x>(double)(jspalten-1)||y<0.0 || y >=(double)(izeilen-1)) return(result);
    
            temp_double = floor(x);
            floorx = temp_double;
            
            temp_double = floor(y);
            floory = temp_double;
            
            temp_double = ceil(x);
            ceilx = temp_double;
            
            temp_double = ceil(y);
            ceily = temp_double;
            
            fractionx = x - floor(x);
            fractiony = y - floor(y);
            
            unmoinx = 1.0 - fractionx;
            unmoiny = 1.0 - fractiony;
            
            temp_double = unmoinx *(double)(in_Bild[floory][floorx]) + fractionx *(double)(in_Bild[floory][ceilx]);
            A = temp_double;
            
            temp_double = unmoinx *(double)(in_Bild[ceily][floorx]) + fractionx *(double)(in_Bild[ceily][ceilx]);
            B = temp_double;
            
            temp_double = unmoiny * (double)(C) + fractiony * (double)(B);
            C = temp_double;
            
     return(C);
    
    
    }
    
    
    /*----------------------------------------------------------------------------*/
    /*Die 6 Parameter werden gegeben und und wir bekommen das in_bild Matrix*/
    /*----------------------------------------------------------------------------*/
    
    int BerechnungTerm(float a1,float a2,float a0,float b1,float b2,float b0,int bilinear,
                            int n,int m,short **out_bild,short **in_bild) {
    
         int i,j,ialt_j,ialt_i;
         double altx,alty;
    
        for( i=0; i < n ; ++i){
          if((i%10)==0) printf("%d",i);
            for( j=0; j < m ; ++j)
            {
             //tempx =  iaVa1[0]+iaVa1[1] * i + iaVa1[2] * j ;
             //tempy =  iaVa2[0]+iaVa2[1] * i + iaVa2[2] * j ;
             altx=(double)(j)*a1 + (double)(i)*a2 + (double)a0  ; 
             alty=(double)(i)*b1 + (double)(j)*b2 + (double)b0  ; 
      
             ialt_j=alty; //hier wird ein typkonvertierung durchgeführt
             ialt_i=altx; //hier wird ein typkonvertierung durchgeführt
             if(bilinear == 0){
                                if(ialt_j < 0||ialt_j >= m|| ialt_i < 0||ialt_i >= n)
                                return out_bild[i][j] = AUS;
                               else
                                return out_bild[i][j] = in_bild[ialt_i][ialt_j];
    
                               } /* ends if bilinear */
    
                        else{ 
                          out_bild[i][j] = bil_int(in_bild,altx, alty,n, m); //aufruf der Methode Bilinear Interpolation
                             } /* ends bilinear if */
            }
        }
    }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by KFill Filter View Post
    But now i want to test in the main() and that isnot work.
    Always tell us what doesn't work (does the program crash? is the output wrong? something else?) and also copy'n'paste the errors/warnings from your compiler or OS.

    Code:
    $ gcc -Wall -Wextra -ggdb3 -o foo foo.c -lm
    foo.c:9:1: warning: return type defaults to ‘int’ [-Wreturn-type]
    foo.c: In function ‘main’:
    foo.c:14:3: warning: missing braces around initialiser [-Wmissing-braces]
    foo.c:14:3: warning: (near initialization for ‘in_bild[0]’) [-Wmissing-braces]
    foo.c:31:1: warning: passing argument 10 of ‘BerechnungTerm’ makes pointer from integer without a cast [enabled by default]
    foo.c:7:5: note: expected ‘short int **’ but argument is of type ‘short int’
    foo.c:31:1: warning: passing argument 11 of ‘BerechnungTerm’ makes pointer from integer without a cast [enabled by default]
    foo.c:7:5: note: expected ‘short int **’ but argument is of type ‘short int’
    foo.c:11:20: warning: unused variable ‘j’ [-Wunused-variable]
    foo.c:11:18: warning: unused variable ‘i’ [-Wunused-variable]
    foo.c: In function ‘allocate_image_array’:
    foo.c:40:45: warning: unused parameter ‘width’ [-Wunused-parameter]
    foo.c: In function ‘bil_int’:
    foo.c:77:8: warning: variable ‘A’ set but not used [-Wunused-but-set-variable]
    foo.c: In function ‘BerechnungTerm’:
    foo.c:148:1: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘allocate_image_array’:
    foo.c:53:1: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘main’:
    foo.c:34:7: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘bil_int’:
    foo.c:105:33: warning: ‘C’ may be used uninitialised in this function [-Wuninitialized]
    One problem is that you are not passing the arrays to your function. You don't need the two asterisks before the array names.
    Code:
    BerechnungTerm(a1,a2,a0,b1,b2,b0,bilinear,n,m,**out_bild,**in_bild);
    should be
    Code:
    BerechnungTerm(a1,a2,a0,b1,b2,b0,bilinear,n,m,out_bild,in_bild);
    Bye, Andreas
    Last edited by AndiPersti; 11-06-2012 at 09:00 AM.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    @Andreas: thanks,ive used devc++ , somethimng is going wrong in the main() ...i want to have as answer the output Matrix out_bild, can someone help me?

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    I'm afraid you have to be more specific than "something is going wrong in main()". What is that something (error message, computer crash, ...)?

    You will also get more responses if you clean up your code (e.g. consistent indentation) so that it's easier to read for us. Some people here will probably ignore you if you just dump it here.

    Bye, Andreas

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    I´ve already reviewed, the programm, my problem is? i dont know how write the main() function and get the answer...

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    I´ve already reviewed, the programm, my problem is? i dont know how write the main() function and get the answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple string transformation function
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2010, 04:34 PM
  2. bilinear and average weight resize
    By Mario F. in forum Tech Board
    Replies: 5
    Last Post: 05-31-2008, 11:53 AM
  3. bilinear interpolation
    By cboard_member in forum Game Programming
    Replies: 5
    Last Post: 03-28-2007, 10:51 PM
  4. Buggy Transformation Update Function..
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-04-2006, 04:52 PM
  5. Super fast bilinear interpolation
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 06-18-2002, 09:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21