Contrast correction
Contents
[
Hide
]
Low contrast and blurring are the most typical distortions when text is photographed with a smartphone camera, especially in low light conditions. They make it difficult for the OCR algorithms to operate successfully, significantly reducing the recognition accuracy.
Aspose.OCR can automatically increase the contrast of images before proceeding to recognition.
Contrast correction automatically converts the image to black and white.
Automatic contrast adjustments
To automatically increase the image contrast before recognition, run the image through contrast_correction_filter
processing filter.
# Instantiate Aspose.OCR API
api = AsposeOcr()
# Initialize image processing
filters = PreprocessingFilter()
filters.add(PreprocessingFilter.contrast_correction_filter())
# Add image to the recognition batch and apply processing filter
input = OcrInput(InputType.SINGLE_IMAGE, filters)
input.add("source.png")
# Save processed image to the "result" folder
ImageProcessing.save(input, "result")
# Recognize the image
result = api.recognize(input)
# Print recognition result
print(result[0].recognition_text)
Usage scenarios
Automatic contrast adjustment is recommended for the following images:
- Photos, especially those taken in low light conditions without optical or digital image stabilization.
- Old papers.
- Text on a background.