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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:00:15+00:00 2026-06-14T05:00:15+00:00

I am dealing with myWxImage , an image. myLabelImage , a numpy array that

  • 0

I am dealing with

  1. myWxImage, an image.
  2. myLabelImage, a numpy array that has the same shape as the image and contains one label (an integer) for every pixel
  3. myLookupTable, a 1-dimensional numpy array, i.e. a vector, that has as many entries as there are labels. (I use it to map labels to floating point numbers.)

The goal is to iterate through the pixels and, for every pixel, consider its label, look up the corresponding floating point number and multiply it with the color of this pixel.

The following code does exactly this but is too slow. Do you have a simple suggestion how to do this faster without resorting to C++ or GPU programming which would, of course, make a lot of sense here?

weightedImage = wx.EmptyImage(myWxImage.Width, myWxImage.Height)
rgb = numpy.zeros(3, dtype=int);
for x in range(0, myWxImage.Width):
    for y in range(0, myWxImage.Height):
        label = myLabelImage[x, y]
        weight = myLookUpTable[label]
        rgb[0] = myWxImage.GetRed(x, y)
        rgb[1] = myWxImage.GetGreen(x, y)
        rgb[2] = myWxImage.GetBlue(x, y)
        rgb = rgb * weight
        weightedImage.SetRGB(x, y, rgb[0], rgb[1], rgb[2])
myBitmap = wx.BitmapFromImage(weightedImage)

# draw myBitmap
  • 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-14T05:00:17+00:00Added an answer on June 14, 2026 at 5:00 am

    If the label image and the lookup table are constant, you could try the follwing:

    1. precalculate the weight vector as a 1D numpy float array (reshape+lookup),
    2. use the wxImage GetData call to get the RGB image data
    3. turn it into a numpy array using fromstring
    4. use numpy element-wise multiplication to get the final image
    5. turn it back into an image using numpy array.tostring + wxImage.SetData

    It might be quicker to directly do the multiply on the image buffer itself (using GetDataBuffer) instead of round-tripping through a numpy array; you’d have to time and see.

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

Sidebar

Related Questions

Dealing with go's funcs I discovered that one can't force the compiler to control
i'm dealing with memcpy to copy one array into another: here is the code,
When dealing with persistant MySQL connections, the one problem is that they get dropped
Other questions dealing with use of match_parent pre 2.2 have answers stating one should
I am dealing with very primitive HTML construction that goes like this: <a NAME=header1></a><b><font
When dealing with image processing and computer vision these two terms come up perennially
When dealing with a flash application that will run in a browser, it's obvious
When dealing with websites with large amount of javascript, i see that these are
I'm dealing with a web-service that serves video files (host). They provide you with
I'm dealing with a weird bug that I don't manage to fix. It's a

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.