FYI上CIAreaAverage過濾器,它的編碼是這樣的:
CGRect inputExtent = [self.inputImage extent];
CIVector *extent = [CIVector vectorWithX:inputExtent.origin.x
Y:inputExtent.origin.y
Z:inputExtent.size.width
W:inputExtent.size.height];
CIImage* inputAverage = [CIFilter filterWithName:@"CIAreaAverage" keysAndValues:@"inputImage", self.inputImage, @"inputExtent", extent, nil].outputImage;
//CIImage* inputAverage = [self.inputImage imageByApplyingFilter:@"CIAreaMinimum" withInputParameters:@{@"inputImage" : inputImage, @"inputExtent" : extent}];
EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
CIContext *myContext = [CIContext contextWithEAGLContext:myEAGLContext options:options];
size_t rowBytes = 32 ; // ARGB has 4 components
uint8_t byteBuffer[rowBytes]; // Buffer to render into
[myContext render:inputAverage toBitmap:byteBuffer rowBytes:rowBytes bounds:[inputAverage extent] format:kCIFormatRGBA8 colorSpace:nil];
const uint8_t* pixel = &byteBuffer[0];
float red = pixel[0]/255.0;
float green = pixel[1]/255.0;
float blue = pixel[2]/255.0;
NSLog(@"%f, %f, %f\n", red, green, blue);
輸出應該是這個樣子:
2015-05-23 15:58:20.935 CIFunHouse[2400:489913] 0.752941, 0.858824, 0.890196
2015-05-23 15:58:20.981 CIFunHouse[2400:489913] 0.752941, 0.858824, 0.890196
謝謝你的建議。移動到GPU是我想的竅門。我的目的是處理像素亮度有意義的科學數據(光子到達事件)。保持一切線性是非常重要的,我不樂意將這類工作卸載到GPU上,除非我確信我完全理解它是如何工作的。不幸的是,CoreImage插件似乎將所有內容都轉換爲RGB,並且有時會爲圖像添加特殊的偏移和縮放因子(對於CIGaussianBlur爲true)。也許我會在需要拋光的時候解決這個問題!我需要學習OpenGL。 –