[Python] Tesseract OCR misreads coloured labels a scaned image despite correct recognition of...

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on processing OCT scan images using Tesseract OCR. My goal is to extract patient information, including eye labels "OD" (right eye) and "OS" (left eye), from these scans. While Tesseract accurately recognises other colored text (both blue and red) in the images, it consistently misreads the "OD"/"OS" labels, which are also in blue.

    • Preprocessing Steps:
    1. Converted images to grayscale using OpenCV.
    2. Cropped specific region of interests (ROIs) containing the "OD"/"OS" labels.

    # ROIs in (x, y, width, height)
    INFO_ROI = ( 389, 259, 1032, 798) # Info Block

    # load in GRAYSCALE
    gray = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
    if gray is None:
    print(f"⚠️ Could not read {fn}")
    continue

    # crop INFO block & OCR it
    x,y,ww,hh = INFO_ROI
    info_crop = gray[y:y+hh, x:x+ww]
    # use PIL for pytesseract
    txt = pytesseract.image_to_string(Image.fromarray(info_crop), config="--psm 6").strip()

    # detect OD vs OS
    m_eye = re.search(r"\b(OD|OS)\b", txt, re.IGNORECASE)
    eye = m_eye.group(1) if m_eye else "UNKN"

    print(f" {fn} → ID {patient_id}, Eye {eye}")


    I tried to debug for txt and received arbitrary values for OD and OS regions like 7 ‘e@hsg= or 7 ‘ekg ~=

    • Questions

    1. Why does Tesseract misread the "OD"/"OS" labels while correctly recognising other blue text in the same image?


    2. Are there specific preprocessing techniques or Tesseract configurations that can improve the recognition of these labels?

    Continue reading...

Compartilhe esta Página