Udayraj123 / OMRChecker

Evaluate OMR sheets fast and accurately using a scanner 🖨 or your phone 🤳.
MIT License
789 stars 327 forks source link

[v2][Feature] Improve CropPage pre-processor using colored images #212

Open Udayraj123 opened 2 months ago

Udayraj123 commented 2 months ago

Is your feature request related to a problem? Please describe. Previously, OMRChecker used to read all images in grayscale. But since we're supporting colored inputs and outputs in the v2 release, it is time to improve the CropPage pre-processor to work on lighter colored backgrounds (see photos below). Currently, for images with light colored backgrounds e.g. light yellow backgrounds - after normalisation(cv2.normalize), the page boundary doesn't seem to get detected at all.

Describe the solution you'd like We can introduce a flag in CropPage.tuningOptions{} to conditionally use cv2.Canny on the colored image instead of the grayscale image. This should help us find edges in the cases where background is not white but light colored (near-white in grayscale).

Describe alternatives you've considered N/A

Additional context Sample image where the grayscale calculation fails:

image

Debug outputs:

image image

Note: please share your queries and approaches on discord for quicker discussions:

Prasadayus commented 1 month ago

My approach to solution: Adjust Color Thresholding: We will implement adaptive or dynamic thresholding techniques tailored for lighter backgrounds. Instead of global thresholds, we will use adaptive thresholding (e.g., cv2.adaptiveThreshold), which calculates thresholds based on local neighborhoods. This would help distinguish light colors from the background effectively.

Background Subtraction: We will consider adding a preprocessing step to subtract or neutralize the background color. By estimating the average background color (e.g., light yellow), we could remove or normalize the background color before further processing.

Edge Detection Tuning: Lastly we can use canny edge detection with parameters that are adjusted dynamically based on the brightness or saturation levels of the image. This could help detect boundaries more effectively on lighter backgrounds.

@Udayraj123 If you like this approach then plz assign me this issue

Udayraj123 commented 1 month ago

Cool @Prasadayus, assigning this to you. Do ask your queries if any.

Prasadayus commented 1 month ago

Sir how to check if my solution is running right or wrong means on which sample I have to test ?

Udayraj123 commented 1 month ago

Hey @Prasadayus, for this task you will need to create a new sample image similar to the one shown in the issue description. Any OMR paper image on a light background like the yellow one would become overly bright and loose its edges, you can share a few samples like that and maybe we can pre-process it such that it fails for the current CropPage.