Бикубическая интерполяция с EasyBMP не работает должным образом

Я пишу программу, которая использует бикубическую интерполяцию, и я использую EasyBMP, но у меня есть проблема. В то время как входное изображение перец.

Мой вывод выглядит этот.

#define BOUNDS(val, min, max) if (val < min) { val = min; } else if (val > max) { val = max; }

void resize(float value)
{
BMP* temp = new BMP();
int in_w = image->TellWidth();
int in_h = image->TellHeight();
temp->SetSize(in_w*value, in_h*value);
RGBApixel input;

for (int y = 0; y < temp->TellHeight(); ++y)
{
float v = float(y) / float(temp->TellHeight() - 1);
for (int x = 0; x < temp->TellWidth(); ++x)
{
float u = float(x) / float(temp->TellWidth() - 1);

input = this->bicubicInterpolation(u,v);

temp->SetPixel(x,y,input);
}
}

delete image;
image=temp;
}RGBApixel bicubicInterpolation(float u, float v)
{
RGBApixel p[4][4];
int q,w;

float x = (u * image->TellWidth()) - 0.5;
int xint = int(x);
float dx = x - floor(x);

float y = (v * image->TellHeight()) - 0.5;
int yint = int(y);
float dy = y - floor(y);

for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
q=xint - 1 + j;
BOUNDS(q,0,image->TellWidth()-1)
w=yint - 1 + i;
BOUNDS(w,0,image->TellHeight()-1)
p[j][i] = image->GetPixel(q,w);
}
}
RGBApixel toReturn;
RGBApixel el1 = this->interpolation(p[0][0],p[1][0], p[2][0], p[3][0], dx);
RGBApixel el2 = this->interpolation(p[0][1],p[1][1], p[2][1], p[3][1], dx);
RGBApixel el3 = this->interpolation(p[0][2],p[1][2], p[2][2], p[3][2], dx);
RGBApixel el4 = this->interpolation(p[0][3],p[1][3], p[2][3], p[3][3], dx);
RGBApixel value = this->interpolation(el1, el2, el3, el4, dy);

return value;
}

RGBApixel interpolation(RGBApixel A, RGBApixel B, RGBApixel C, RGBApixel D, float t)
{
float a[3],b[3],c[3],d[3];
RGBApixel toRet;
a[0]=A.Red;
b[0]=B.Red;
c[0]=C.Red;
d[0]=D.Red;

a[1]=A.Green;
b[1]=B.Green;
c[1]=C.Green;
d[1]=D.Green;

a[2]=A.Blue;
b[2]=B.Blue;
c[2]=C.Blue;
d[2]=D.Blue;

float w[3];
float x[3];
float y[3];
float z[3];

float color[3];

for(int i=0; i<3; i++)
{
w[i]= -a[i] / 2.0f + (3.0f*b[i]) / 2.0f - (3.0f*c[i]) / 2.0f + d[i] / 2.0f;
x[i]= a[i] - (5.0f*b[i]) / 2.0f + 2.0f*c[i] - d[i] / 2.0f;
y[i]= -a[i] / 2.0f + c[i] / 2.0f;
z[i]= b[i];
color[i]= w[i] * t*t*t + x[i] * t*t + y[i] * t +z[i];
}
toRet.Red=color[0];
toRet.Green=color[1];
toRet.Blue=color[2];
toRet.Alpha=255;

return toRet;
}

Вы заметили ошибку, которую я сделал?

0

Решение

Это было beign вне диапазона. Просто нужно:

color[i]= w[i] * t*t*t + x[i] * t*t + y[i] * t +z[i];
BOUNDS(color[i],0,255);
0

Другие решения

Других решений пока нет …