Open vividcode opened 11 years ago
Posted question on SO: http://stackoverflow.com/questions/18630842/ios-binarization-for-ocr
Final code I am using is below - and it provides good result for image 1, however image 2 looks noisy, and doesn't go well with OCR:
+(UIImage *)binarize : (UIImage *) sourceImage
{
UIImage * grayScaledImg = [self toGrayscale:sourceImage]; //grayscale using core image technique
GPUImagePicture *imageSource = [[GPUImagePicture alloc] initWithImage:grayScaledImg];
GPUImageAdaptiveThresholdFilter *stillImageFilter = [[GPUImageAdaptiveThresholdFilter alloc] init];
stillImageFilter.blurSize = 3.0;
[imageSource addTarget:stillImageFilter];
[imageSource processImage];
UIImage *imageWithAppliedThreshold = [stillImageFilter imageFromCurrentlyProcessedOutput];
// UIImage *destImage = [thresholdFilter imageByFilteringImage:grayScaledImg];
return imageWithAppliedThreshold;
}
I have these images:
Image 1:
Image 2:
I can't seem to find proper threshold value to handle Image 1 entirely for binarization. If ever I find, Image 2 becomes almost invisible.
I am using GPUImageLuminanceThresholdFilter code from this answer - http://stackoverflow.com/a/10939150/1506363.
One logical way seems to be split them into half to handle with separate threshold values. But then there arises the question of how be adaptive about it. My ultimate aim is to perform OCR and that is where most of my efforts are focused, so some easier binarization solution is highly appreciated.