I'm trying to create a code that allows me to clear images to be read by and OCR engine. So far I haven't been able to accomplish much. Only install Imagemagink on my iOS project and use some of the API functions to create a Gray Scale image.
What I'm trying to achieve is something like this: http://www.fmwconcepts.com/imagemagick/textcleaner/
But I'm not too familiarized with the API. Does anyone knows how to do something like that using the API?
This is my code by the way.
regards,
Code: Select all
-(UIImage *)drawMonochromeImage:(UIImage *)image
{
// Create temporary file
NSString *tempFilePath = [NSTemporaryDirectory()
stringByAppendingPathComponent:@"temp.jpg"];
MagickWandGenesis();
MagickWand *wand = NewMagickWand();
NSData *data = UIImagePNGRepresentation(image);
MagickReadImageBlob(wand, [data bytes], [data length]);
// Monochrome image
//MagickQuantizeImage(wand,2,GRAYColorspace,1,MagickFalse,MagickFalse);
MagickDespeckleImage(wand);
MagickEnhanceImage(wand);
MagickQuantizeImage(wand,256,GRAYColorspace,0,MagickFalse,MagickFalse);
MagickBrightnessContrastImage(wand,-40,30);
// Write to temporary file
MagickWriteImage(wand,
[tempFilePath cStringUsingEncoding:NSASCIIStringEncoding]
);
// Load UIImage from temporary file
UIImage *imgObj = [UIImage imageWithContentsOfFile:tempFilePath];
// Display on device
return imgObj;
// [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
}