使用CoreImage / GPUImage调平和匹配曝光

时间:2016-07-15 13:17:33

标签: objective-c

我想知道是否可以使用CoreImageGPUImage对一组图片进行曝光。我该怎么做呢?

示例 假设您有4张图像,但第三张图像的曝光不同。你如何调整曝光水平以使所有4张图像具有相同的曝光?

我的一个想法是使用AVCapture测量和匹配曝光,即如果输入图像为-2.0,则只需使用CoreImage添加2.0。

另一个想法是实现直方图均衡..

以前有人曾经处理过同样的任务吗?任何见解?

1 个答案:

答案 0 :(得分:0)

您可以使用CoreImage(#import)和ImageIO(CGImage)并使用EXIF Dictionary Keys密钥提取exif元数据:kCGImagePropertyExifExposureTime,kCGImagePropertyExifExposureMode,kCGImagePropertyExifExposureProgram,kCGImagePropertyExifExposureBiasValue,kCGImagePropertyExifExposureIndex,kCGImagePropertyExifWhiteBalance

- (NSDictionary*) exifData: (NSString*) path {  

NSDictionary* dic   =   nil;
NSURL* url          =   [NSURL fileURLWithPath: path];  

if ( url )  
{
    CGImageSourceRef source = CGImageSourceCreateWithURL ((CFURLRef) url, NULL);

    if (source != nil)
    {
        CFDictionaryRef metadataRef = 
        CGImageSourceCopyPropertiesAtIndex (source, 0, NULL);  
        if (metadataRef)   
        {  
            NSDictionary* immutableMetadata = (NSDictionary *)metadataRef;  
            if (immutableMetadata)
            {
                dic = [NSDictionary dictionaryWithDictionary : (NSDictionary *)metadataRef];
            }
            CFRelease ( metadataRef );
        }
        CFRelease(source);  
        source = nil;  
     }
 }

return dic;
}

用法:

NSDictionary* dic = [self exifData: path];  
if (dic)
{  
    NSString *s = [dic valueForKey: kCGImagePropertyExifExposureTime];  
    NSLog(@"Image : %@ - ExposureTime : %.2f", path, [s floatValue]);  
}

然后用:

改变曝光或白平衡
- (UIImage *) changeImageExposure:(NSString*) imagename exposure:(float) exposure {  
   CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed: imagename]];
   CIFilter *exposureAdjustmentFilter = [CIFilter filterWithName:@"CIExposureAdjust"];
   [exposureAdjustmentFilter setValue:inputImage forKey:kCIInputImageKey];
   [exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:exposure] forKey:@"inputEV"];
   CIImage *outputImage = exposureAdjustmentFilter.outputImage;
   CIContext *context = [CIContext contextWithOptions:nil];
   return [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];
}