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:
convert \( $infile -colorspace gray -type grayscale -contrast-stretch 0 \) \ \( -clone 0 -colorspace gray -negate -lat ${filtersize}x${filtersize}+${offset}% -contrast-stretch 0 \) \ -compose copy_opacity -composite -fill "$bgcolor" -opaque none +matte \ -deskew 40% -sharpen 0x1 \ $outfile
Now the problem is that I haven't been able to replicate that on My Code. So my questions are:
Does any one knows a way of using the "ConvertImageCommand()" method using an UIImage as input instead of a file path? (Example here: http://www.imagemagick.org/discourse-server/viewtopic.php?t=25704)
As an alternative and keep on going with my actual code, could anyone point me in the right direction of converting the above command into an API method to complete the code below? So far I've found that the "-lat" option equivalent in the API is: "MagickAdaptiveThresholdImage()"
regards,
-(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];
}