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 8526693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:20:46+00:00 2026-06-11T08:20:46+00:00

I’m doing some amateur image analysis using Python, specifically Numpy, PIL and OpenCV. However,

  • 0

I’m doing some amateur image analysis using Python, specifically Numpy, PIL and OpenCV. However, I’m not too pleased with the performance of PIL, so I would like to port those parts of the code to OpenCV. This will also make it easier to port the code to C/C++ later on, if needed.

Anyways, I’m having some trouble with porting parts of my code, and would love some help here. Specifically, the parts I need changed is:

Function: Find the red, green and blue (R,G,B) intensity with the most pixels in the image. Currently done through the histogram. Input image is in the form of a Python PIL image.

def bgcalcRGB(img):

    hist = img.histogram()

    R=0;G=0;B=0; avgR=0.; avgG=0.; avgB=0.; Rmax=175+15; Rmin=175-15;
    Gmax=160+15; Gmin=160-15; Bmax=150+15; Bmin=150-15;

    for x in range(Rmin,Rmax,1):
        if hist[x] > avgR: avgR = hist[x]; R = x
    for x in range(256+Gmin,Gmax+256,1):
        if hist[x] > avgG: avgG = hist[x]; G = x - 256
    for x in range(256*2+Bmin,Bmax+256*2,1):
        if hist[x] > avgB: avgB = hist[x]; B = x - 256*2
    return (R,G,B)

Function: Serves as a simultaneous threshold of the RGB channals. If a certain RGB pixel is within a certain range (independent for R,G and B), it is coloured white. If not, it is discarded and coloured black. Input image is a Python PIL image.

def mask(low, high):
    return [255 if low <= x <= high else 0 for x in range(0, 256)]

img1 = img.point(mask(val1-uc1,val1+uc1)+mask(val2-uc2,val2+uc2)+mask(val3-uc2,val2+uc2)).convert('L').point([0]*255+[255]).convert('RGB')

So what I need is help with translating the above code to using only OpenCV, or at least not using Python PIL.

Thanks!

  • 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-11T08:20:48+00:00Added an answer on June 11, 2026 at 8:20 am

    you should try SimpleCV

    It is based on Python OpenCV bindings, scipy, numpy, pygame, PIL. SimpleCV is very easy to learn and implement.

    img = Image("filename.jpg") will load the image in BGR form.

    To access x, y pixel of the image, color = img[x, y]

    to get cv2.cv.iplimage => img.getBitmap()

    SimpleCV integrates scipy and numpy for fast computation and Machine Learning moduels. It includes pygame display.

    To display the image, img.show()

    It also includes various tracknig features(Lucas Kanade Tracker, CAMShift, etc), keypoint match features(SURF, SIFT, ASIFT, STAR, ORB, MSER, etc), and many other blob features.

    Basic Image Processing and image data extraction can be easily done using SimpleCV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.