1

我想将从相机拍摄的图像转换为黑白并打印。此图像只是从文档或纸张中获取的。所以我使用以下代码:

{

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:  srcImg ];            

GPUImageAdaptiveThresholdFilter *stillImageFilter = [[GPUImageAdaptiveThresholdFilter alloc] init];
stillImageFilter.blurSize = 1;


[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];

UIImage *outputImg = [stillImageFilter imageFromCurrentlyProcessedOutput];
[stillImageSource release];
[stillImageFilter release];


}

但是输出图像有很多锯齿,因为图像是完全二值化的,它只需要部分二值化。所以我先将源图像转换为灰度然后给出最大对比度,图像看起来很好,但光影无法去除。任何想法,谢谢。

4

1 回答 1

0

尝试在 GPUImageAdaptiveThresholdFilter 之后应用 GPUImageLuminanceThresholdFilter,并使用“blurSize”属性

-(UIImage *)doBinarize:(UIImage *)sourceImage
{

 GPUImagePicture *imageSource = sourceImage;

    GPUImageAdaptiveThresholdFilter *stillImageFilter = [[GPUImageAdaptiveThresholdFilter alloc] init];
    stillImageFilter.blurRadiusInPixels = 8.0;//play with it

    GPUImageLuminanceThresholdFilter *stillImageFilter2 = [[GPUImageLuminanceThresholdFilter alloc] init];
    stillImageFilter2.threshold = 0.5f;//
    [stillImageFilter addFilter:stillImageFilter2];

    [stillImageFilter prepareForImageCapture];



    [imageSource addTarget:stillImageFilter];

    [imageSource processImage];


    UIImage *retImage = [stillImageFilter imageFromCurrentlyProcessedOutput];

    [imageSource removeAllTargets];

    return retImage;
}
于 2014-01-13T21:05:38.363 回答