Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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
Ios 将图像边缘压缩为自定义内核不会产生预期的结果_Ios_Swift_Core Image_Cikernel_Ciwarpkernel - Fatal编程技术网

Ios 将图像边缘压缩为自定义内核不会产生预期的结果

Ios 将图像边缘压缩为自定义内核不会产生预期的结果,ios,swift,core-image,cikernel,ciwarpkernel,Ios,Swift,Core Image,Cikernel,Ciwarpkernel,我开发了一个定制的CIWarpKernel,它是我的数字模型设计的换位,如下所示: kernel vec2 panoramaDistortion (vec2 center) { float pi = 3.141592653589793; vec2 t = destCoord(); float x = t.x / center.x - 1.0; // x ∈ -1...1 float y = t.y / center.y - 1.0;

我开发了一个定制的
CIWarpKernel
,它是我的数字模型设计的换位,如下所示:

kernel vec2 panoramaDistortion (vec2 center) {
    float pi = 3.141592653589793;
    vec2 t = destCoord();
    float x = t.x / center.x - 1.0;         // x ∈ -1...1
    float y = t.y / center.y - 1.0;         // y ∈ -1...1

    float rx = x;
    float delta = 50.0;
    float siny = sin(y * pi / 2.0);

    // See my model in Numbers: Aladdin PanoramPinch CIKernel file where $a2 = x and b$1 = y

    // sin($a2×pi()÷2)×(−cos(b$1×pi())×($a2+1)÷$w$3+sin($a2 ×pi()÷$w$5))
    // sin(y×pi()÷2)×(−cos(x×pi())×(y+1)÷$w$3+sin(y×pi()÷2))

    // sin($a22×pi()÷2)×(−cos(b$1×pi())×abs(1−$a22)÷$w$3−sin($a22 ×pi()÷$w$5))

    float ry =
      y >= 0.0 ?
        siny * (-cos(x * pi) * (y + 1.0) / delta + siny)
      : siny * (-cos(x * pi) * (1.0 - y) / delta - siny)
    ;

    return vec2(center.x * (rx + 1.0), center.y * (ry + 1.0));
}

阳性
y
的单元格为:
SIN($A2×PI()÷2)×个(−COS(B$1×PI())×($A2+1)÷$W$3+SIN($A2×PI()÷2))
其中,
$A2
y
B$1
x
$W$3
是中心拉伸因子

代码如下:

kernel vec2 panoramaDistortion (vec2 center) {
    float pi = 3.141592653589793;
    vec2 t = destCoord();
    float x = t.x / center.x - 1.0;         // x ∈ -1...1
    float y = t.y / center.y - 1.0;         // y ∈ -1...1

    float rx = x;
    float delta = 50.0;
    float siny = sin(y * pi / 2.0);

    // See my model in Numbers: Aladdin PanoramPinch CIKernel file where $a2 = x and b$1 = y

    // sin($a2×pi()÷2)×(−cos(b$1×pi())×($a2+1)÷$w$3+sin($a2 ×pi()÷$w$5))
    // sin(y×pi()÷2)×(−cos(x×pi())×(y+1)÷$w$3+sin(y×pi()÷2))

    // sin($a22×pi()÷2)×(−cos(b$1×pi())×abs(1−$a22)÷$w$3−sin($a22 ×pi()÷$w$5))

    float ry =
      y >= 0.0 ?
        siny * (-cos(x * pi) * (y + 1.0) / delta + siny)
      : siny * (-cos(x * pi) * (1.0 - y) / delta - siny)
    ;

    return vec2(center.x * (rx + 1.0), center.y * (ry + 1.0));
}
我的问题是,虽然换位是100%精确的,但我没有得到与我的模型相同的结果。请参见生成的平铺图像扭曲:

它是怎么来的,在中心y=0,在上边和下边有膨胀的

有关信息,我的平铺图像如下所示:

kernel vec2 panoramaDistortion (vec2 center) {
    float pi = 3.141592653589793;
    vec2 t = destCoord();
    float x = t.x / center.x - 1.0;         // x ∈ -1...1
    float y = t.y / center.y - 1.0;         // y ∈ -1...1

    float rx = x;
    float delta = 50.0;
    float siny = sin(y * pi / 2.0);

    // See my model in Numbers: Aladdin PanoramPinch CIKernel file where $a2 = x and b$1 = y

    // sin($a2×pi()÷2)×(−cos(b$1×pi())×($a2+1)÷$w$3+sin($a2 ×pi()÷$w$5))
    // sin(y×pi()÷2)×(−cos(x×pi())×(y+1)÷$w$3+sin(y×pi()÷2))

    // sin($a22×pi()÷2)×(−cos(b$1×pi())×abs(1−$a22)÷$w$3−sin($a22 ×pi()÷$w$5))

    float ry =
      y >= 0.0 ?
        siny * (-cos(x * pi) * (y + 1.0) / delta + siny)
      : siny * (-cos(x * pi) * (1.0 - y) / delta - siny)
    ;

    return vec2(center.x * (rx + 1.0), center.y * (ry + 1.0));
}