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 */
}
}
}