Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 立方亚像素定位_Python_C++_Image_Image Processing_Cimg - Fatal编程技术网

Python 立方亚像素定位

Python 立方亚像素定位,python,c++,image,image-processing,cimg,Python,C++,Image,Image Processing,Cimg,我试图理解使用的CImg.h文件从图像中提取值的代码在做什么 该函数使用以下语句: float dx(float x, float y, CImg<float> &i) { float val = i.cubic_atXY(x + 0.5, y); return val; } float dx(float x、float y、CImg&i){ float val=i.cubic_atXY(x+0.5,y); 返回val; } 我认为它是在坐标(x+0.5,

我试图理解使用的CImg.h文件从图像中提取值的代码在做什么

该函数使用以下语句:

float dx(float x, float y, CImg<float> &i) {
    float val = i.cubic_atXY(x + 0.5, y);
    return val;
}
float dx(float x、float y、CImg&i){
float val=i.cubic_atXY(x+0.5,y);
返回val;
}
我认为它是在坐标(x+0.5,y)上寻找三次插值的亚像素。我发现这个函数是在文件的第12450行附近定义的,但是我真的不知道如何将它翻译成其他代码,比如python


使用这种库的人能够理解它吗?

cubic\u atXY
是一些看起来很枯燥的代码,但基本上所有简单的算术运算在其他编程语言中都应该具有类似的语法。唯一非通用的行如下所示,例如:

const Tfloat Ipp = (Tfloat)atXY(px,py,z,c,out_value)
这是一个C型演员。它将调用
atXY()
的结果强制转换为
Tfloat
。顺便说一下,这看起来像是双三次插值。

调用atXY()是为了检查用于进行双三次插值的点是否在帧限制内。 正如Carlton所说的和我所确认的,它是一种双三次插值,用于提取图像中任何位置的子像素值。 我试图将代码翻译成python,最后执行以下代码,得到与CImg.h函数相同的结果

*考虑到我使用逻辑运算符直接实现了
atXY()
函数,并且由于python使用(idRow,idCol)作为矩阵索引,索引(x,y)被更改为(y,x)

def bicubic(fx, fy, img):

   img = img.astype(float)
   h,w = np.shape(img)

   if(fx < 0 or fx > w-1 or fy < 0 or fy > h-1):
       val = 0
       return val

   x = int(fx)
   y = int(fy)

   dx = fx - x
   dy = fy - y

   px = 0 if x-1<0 else x-1
   py = 0 if y-1<0 else y-1

   nx = x+1 if dx>0 else x
   ny = y+1 if dy>0 else y

   ax = w-1 if x+2>=w else x+2
   ay = h-1 if y+2>=h else y+2

   Ipp = img[py,px]; Icp = img[py,x]; Inp = img[py,nx]; Iap = img[py,ax];
   Ip = Icp + 0.5*(dx*(-Ipp+Inp) + dx*dx*(2*Ipp-5*Icp+4*Inp-Iap) + dx*dx*dx*(-Ipp+3*Icp-3*Inp+Iap))
   Ipc = img[y,px]; Icc = img[y,x]; Inc = img[y,nx]; Iac = img[y,ax];
   Ic = Icc + 0.5*(dx*(-Ipc+Inc) + dx*dx*(2*Ipc-5*Icc+4*Inc-Iac) + dx*dx*dx*(-Ipc+3*Icc-3*Inc+Iac))
   Ipn = img[ny,px]; Icn = img[ny,x]; Inn = img[ny,nx]; Ian = img[ny,ax];
   In = Icn + 0.5*(dx*(-Ipn+Inn) + dx*dx*(2*Ipn-5*Icn+4*Inn-Ian) + dx*dx*dx*(-Ipn+3*Icn-3*Inn+Ian))
   Ipa = img[ay,px]; Ica = img[ay,x]; Ina = img[ay,nx]; Iaa = img[ay,ax];
   Ia = Ica + 0.5*(dx*(-Ipa+Ina) + dx*dx*(2*Ipa-5*Ica+4*Ina-Iaa) + dx*dx*dx*(-Ipa+3*Ica-3*Ina+Iaa))

   val = Ic + 0.5*(dy*(-Ip+In) + dy*dy*(2*Ip-5*Ic+4*In-Ia) + dy*dy*dy*(-Ip+3*Ic-3*In+Ia))
   return val
def双立方(外汇、财政、img):
img=img.astype(浮动)
h、 w=np.形状(img)
如果(fx<0或fx>w-1或fy<0或fy>h-1):
val=0
返回值
x=int(fx)
y=int(fy)
dx=fx-x
dy=fy-y
如果x-10或y,则px=0
如果x+2>=w,则ax=w-1,否则x+2
如果y+2>=h,则ay=h-1,否则y+2
Ipp=img[py,px];Icp=img[py,x];Inp=img[py,nx];Iap=img[py,ax];
Ip=Icp+0.5*(dx*(-Ipp+Inp)+dx*dx*(2*Ipp-5*Icp+4*Inp-Iap)+dx*dx*dx*(-Ipp+3*Icp-3*Inp+Iap))
Ipc=img[y,px];Icc=img[y,x];Inc=img[y,nx];Iac=img[y,ax];
Ic=Icc+0.5*(dx*(-Ipc+Inc)+dx*dx*(2*Ipc-5*Icc+4*Inc-Iac)+dx*dx*dx*(-Ipc+3*Icc-3*Inc+Iac))
Ipn=img[ny,px];Icn=img[ny,x];Inn=img[ny,nx];Ian=img[ny,ax];
In=Icn+0.5*(dx*(-Ipn+Inn)+dx*dx*(2*Ipn-5*Icn+4*Inn-Ian)+dx*dx*dx*(-Ipn+3*Icn-3*Inn+Ian))
Ipa=img[ay,px];Ica=img[ay,x];Ina=img[ay,nx];Iaa=img[ay,ax];
Ia=Ica+0.5*(dx*(-Ipa+Ina)+dx*dx*(2*Ipa-5*Ica+4*Ina-Iaa)+dx*dx*dx*(-Ipa+3*Ica-3*Ina+Iaa))
val=Ic+0.5*(dy*(-Ip+In)+dy*dy*(2*Ip-5*Ic+4*In Ia)+dy*dy*dy*(-Ip+3*Ic-3*In+Ia))
返回值

这是一个双三次插值,正如您在另一个例子中看到的那样。它进行双三次插值以查看该精确点的值。正如我所看到的,Python没有从网格中确定这个点值的函数。