Applying a convolution kernel to an input image should produce an output image with the exact same dimensions. Yet, when using a CIFilter.convolution3x3 with a non-zero bias on a CIImage, inspecting the output reveals that the width, height, and origin coordinate have been skewed into infinity, specifically CGFloat.greatestFiniteMagnitude. I've tried the 5x5 and 7x7 versions of this filter and I've tried setting different weights and biases and the conclusion is the same - if the bias is anything other than zero the output image's size and origin coordinate appear to be ruined.
The documentation for this filter is here.
Here is some code...
// 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)
Notice that 1.7976931348623157e+308 is CGFloat.greatestFiniteMagnitude.
This shouldn't be happening. The only other information I can provide is that I'm running this code on iOS 13.5 and the CIImages I am filtering are being instantiated from CVPixelBuffers grabbed from CMSampleBuffers that are automatically delivered to my code by the device's camera feed. The width and height are 960x540 before going through the filter.