Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:55:30+00:00 2026-06-01T11:55:30+00:00

I have an OCR based iPhone app that takes in grayscale images and thresholds

  • 0

I have an OCR based iPhone app that takes in grayscale images and thresholds them to black and white to find the text (using opencv). This works fine for images with black text on a white background. I am having an issue with automatically switching to an inverse threshold when the image is white text on a black background. Is there a widely used algorithm for checking the image to determine if it is light text on a dark background or vice versa? Can anyone recommend a clean working method? Keep in mind, I am only working with the grayscale image from the iPhone camera.

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:55:31+00:00Added an answer on June 1, 2026 at 11:55 am

    Since I am dealing with a grayscale IplImage at this point, I could not count black or white pixels but had to count the number of pixels above a given “brightness” threshold. I just used the border pixels as this is less expensive and still gives me enough information to make a sound decision.

    IplImage *image;
    int sum = 0; // Number of light pixels
    int threshold = 135; // Light/Dark intensity threshold
    
    /* Count number of light pixels at border of image. Must convert to unsigned char type to make range 0-255. */
    // Check every other pixel of top and bottom
    for (int i=0; i<(image->width); i+=2) {
        if ((unsigned char)image->imageData[i] >= threshold) { // Check top
            sum++;
        }
        if ((unsigned char)image->imageData[(image->width)*(image->height)
                           - image->width + i] >= threshold) { // Check bottom
            sum++;
        }
    }
    
    //Check every other pixel of left and right Sides
    for (int i=0; i<(image->height); i+=2) {
        if ((unsigned char)image->imageData[i*(image->width)] >= threshold) { // Check left
            sum++;
        }
        if ((unsigned char)image->imageData[i*(image->width) + (image->width) - 1] >= threshold) { // Check right
            sum++;
        }
    }
    
    // If more than half of the border pixels are light, use inverse threshold to find dark characters
    if (sum > ((image->width/2) + (image->height/2))) {
        // Use inverse binary threshold because background is light
    }
    else {
        // Use standard binary threshold because background is dark
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have PDF files that have been recognized using the OCR Text Recognition ->
I am new in iPhone app development. I have to implement the OCR in
I have PDF documents containing several images/pages of scanned documents. Their (OCR-produced) text content
I have an OCR program, written with C# (WinForms app). So it's main purpose
tesseract OCR have a command line interface, which allow us to recognize text from
I'm working in C# doing some OCR work and have extracted the text I
OCR texts often have words that flow from one line to another with a
I was incorporating the OCR in my iPhone app using open source library tesseract.I
I have got a text file created using OCR software - about one megabyte
I have some documents that went through OCR conversion from PDF into HTML. Because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.