Udayraj123 / OMRChecker

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

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

Open Udayraj123 opened 3 weeks ago

Udayraj123 commented 3 weeks 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 4 days 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 4 days ago

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