typedef struct imginfo{
int width;
int height;
unsigned char* img;
} imginfo;
void interpolation( imginfo *img,unsigned char *res,int res_width,int res_height){
int i,j;
unsigned char arr[img->height*img->width];
memcpy(arr,img->img,sizeof(arr));
// memset(res,0,sizeof(arr));
int width=img->width;
int height=img->height;
double h_times=(double)res_height/(double)height;
double w_times=(double)(res_width)/(double)width;
// unsigned char *tmp=(unsigned char *)malloc(res_height*res_width*sizeof(unsigned char));
printf("h_times=%f,w_times=%f \r\n",h_times,w_times);
unsigned char f11,f12,f21,f22;
int x1,y1,x2,y2;
double x=0,y=0;
for(j=0;j<res_height;j++){
for(i=0;i<res_width;i++){
x=i/w_times ;
y=j/h_times ;
x1=(int)(x-1) ;
x2=(int)(x+1) ;
y1=(int)(y-1) ;
y2=(int)(y+1) ;
f11=is_in_array(x1,y1,height,width)?(*(arr+x1+y1*width)):0;
f12=is_in_array(x1,y2,height,width)?(*(arr+x1+y2*width)):0;
f21=is_in_array(x2,y1,height,width)?(*(arr+x2+y1*width)):0;
f22=is_in_array(x2,y2,height,width)?(*(arr+x2+y2*width)):0;
*(res+i+j*res_width)= (unsigned char)(((f11 * (x2 - x) * (y2 - y)) +
(f21 * (x - x1) * (y2 - y)) +
(f12 * (x2 - x) * (y - y1)) +
(f22 * (x - x1) * (y - y1))) / ((x2 - x1) * (y2 - y1)));
}
}
img->width=res_width;
img->height=res_height;
}
C语言实现双线性插值
最新推荐文章于 2024-05-19 14:18:27 发布