【发布时间】:2020-10-02 16:26:32
【问题描述】:
将卷积核应用于输入图像应生成具有完全相同尺寸的输出图像。然而,当在CIImage 上使用具有非零偏差的CIFilter.convolution3x3 时,检查输出会发现宽度、高度和原点坐标已经倾斜到无穷大,特别是CGFloat.greatestFiniteMagnitude。我试过这个过滤器的 5x5 和 7x7 版本,我尝试设置不同的权重和偏差,结论是一样的——如果偏差不是零,输出图像的大小和原点坐标似乎被破坏了。
这个过滤器的文档是here。
这是一些代码...
// create the filter
let convolutionFilter = CIFilter.convolution3X3()
convolutionFilter.bias = 1 // any non zero bias will do
// I'll skip setting convolutionFilter.weights because the filter's default weights (an identity matrix) should be fine
// make your CIImage input
let input = CIImage(...) // I'm making mine from data I got from the camera
// lets print the size and position so we can compare it with the output
print(input.extent.width, input.extent.height, input.extent.origin) // -> 960.0 540.0 (0.0, 0.0)
// pass the input through the filter
convolutionFilter.inputImage = input
guard let output = convolutionFilter.outputImage else {
print("the filter failed for some reason")
}
// the output image now contains the instructions necessary to perform the convolution,
// but no processing has actually occurred; even so, the extent property will have
// been updated if a change in size or position was described
// examine the output's size (it's just another CIImage - virtual, not real)
print(output.extent.width, output.extent.height, output.extent.origin) // -> 1.7976931348623157e+308 1.7976931348623157e+308 (-8.988465674311579e+307, -8.988465674311579e+307)
注意1.7976931348623157e+308 是CGFloat.greatestFiniteMagnitude。
这不应该发生。我可以提供的唯一其他信息是我正在 iOS 13.5 上运行此代码,并且我正在过滤的 CIImages 是从 CVPixelBuffers 中实例化的,这些 CVPixelBuffers 是从 CMSampleBuffers 中获取的,这些信息由设备的摄像头馈送自动传送到我的代码中。通过过滤器之前的宽度和高度为 960x540。
【问题讨论】:
-
对我来说,这听起来像是正确的行为,如果你想要硬边,你应该剪回原来的范围。
-
另请参阅此处对clamp-filter-crop 的讨论:stackoverflow.com/questions/12839729/…
-
@matt 但只要将偏差设置为零,我们就不会出现这种行为;程度保持不变。另请注意,现存的起源严重倾斜。如果您渲染到另一个像素缓冲区,事情将非常错位。为了正确使用它而不得不用笨拙的裁剪来跟进你的卷积似乎是错误的。
标签: ios swift convolution core-image cifilter