level 1
0SAS0
楼主
题目如下:
输入一个单通道1000*1000图像,要求将它缩放至200*200。输入输出尺寸是固定的,因此无需写更复杂的双线性插值。给出的函数声明如下
void (unsigned char *inputImg, int imgWidth, int imgHeight, int outWidth, int outHeight, unsigned char *outImg)
下面是我的程序
void (unsigned char *inputImg, int imgWidth, int imgHeight, int outWidth, int outHeight, unsigned char *outImg)
{
outImg = malloc(200*200*1);
for (int oy=0;oy<200;oy++)
{
for (int ox=0;ox<200;ox++)
{
int sum = 0;
for (int iy = oy*5;iy<oy*5+5;iy++)
{
for (int ix = ox*5;ix<ox*5+5;ix++)
{
sum += (int)inputImg[iy*1000+ix];
}
}
sum = sum/25;
outImg[oy*200+ox] = (unsigned char)sum;
}
}
}
因为面试官明确告诉我,输入输出尺寸是固定的,就是1000和200,所以我才没有用输入的WH
然而面试失败了,我怀疑是我这个程序写的有问题。希望大家提点建议
2021年09月29日 04点09分
1
输入一个单通道1000*1000图像,要求将它缩放至200*200。输入输出尺寸是固定的,因此无需写更复杂的双线性插值。给出的函数声明如下
void (unsigned char *inputImg, int imgWidth, int imgHeight, int outWidth, int outHeight, unsigned char *outImg)
下面是我的程序
void (unsigned char *inputImg, int imgWidth, int imgHeight, int outWidth, int outHeight, unsigned char *outImg)
{
outImg = malloc(200*200*1);
for (int oy=0;oy<200;oy++)
{
for (int ox=0;ox<200;ox++)
{
int sum = 0;
for (int iy = oy*5;iy<oy*5+5;iy++)
{
for (int ix = ox*5;ix<ox*5+5;ix++)
{
sum += (int)inputImg[iy*1000+ix];
}
}
sum = sum/25;
outImg[oy*200+ox] = (unsigned char)sum;
}
}
}
因为面试官明确告诉我,输入输出尺寸是固定的,就是1000和200,所以我才没有用输入的WH
然而面试失败了,我怀疑是我这个程序写的有问题。希望大家提点建议