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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:41:09+00:00 2026-05-24T13:41:09+00:00

So, this should be a comment to this thread , but it’s apparently closed,

  • 0

So, this should be a comment to this thread, but it’s apparently closed, so here it goes. I’ve been playing around quite successfully with matplotlib and numpy and mencoder, as has been suggested around here. I have since adopted Voki Codder buffer to stdin solution, which speeds the whole process up considerably. The thing is, I couldn’t find any documentation on the -format=”bgra” part of the command. This means that the bytes are from right to left blue green red alpha, right. Do they have to be uint32, or something else. The problem is I’m plotting colormaps of floats, so I’m trying to convert them to grayscale, but I’m getting lots of weird patterns which make me strongly believe I’m doing something wrong. I wrote this function to convert from floats to uint32 within a range. But the result is not why I expected, am I doing something terribly stupid?

def grayscale(x, min, max):
  return np.uint32((x-min)/(max-min)*0xffffff)
  • 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-05-24T13:41:09+00:00Added an answer on May 24, 2026 at 1:41 pm

    I think you’re getting confused on what the uint32 represents. It’s 4 bands of uint8 integers.

    If you have floating point data, and want to represent it in grayscale, you don’t want to rescale it to a full 32 bit range, you want to rescale it to an 8-bit range, and repeat that for the red, green, and blue bands (and then presumably put in a constant alpha band).

    You could also just use a different byteorder. Y8 is just a single grayscale, 8-bit band, and Y16 is a single, grayscale 16-bit band. (Have a look at the output of mencoder -rawvideo format=help for a full (though somewhat confusing) listing.)

    Just to illustrate using numpy for view a 32-bit integer as four bands of 8-bit integers:

    import numpy as np
    height, width = 20,20
    
    # Make an array with 4 bands of uint8 integers
    image = np.zeros((height, width, 4), dtype=np.uint8)
    
    # Filling a single band (red) 
    b,g,r,a = image.T
    r.fill(255) 
    
    # Fill the image with yellow and leave alpha alone
    image[...,:3] = (255, 255, 0) 
    
    # Then when we want to view it as a single, 32-bit band:
    image32bit = image.reshape(-1).view(np.uint32).reshape(height, width)
    # (Note that this is a view. In other words,  we could change "b" above 
    #  and it would change "image32bit")
    

    In your case, however, you probably want to do something more like this:

    import numpy as np
    from videosink import VideoSink
    
    height, width = 20,20
    numframes = 1000
    data = np.random.random((height, width, numframes))
    
    # Rescale your data into 0-255, 8-bit integers 
    # (This could be done in-place if you need to conserve memory)
    d    ata_rescaled = 255.0 / (data.max() - data.min()) * (data - data.min())
    data_rescaled = data_rescaled.astype(np.uint8)
    
    # The key here is the "Y8" format. It's 8-bit grayscale.
    video = VideoSink((height,width), "test", rate=20, byteorder="Y8")
    
    # Iterate over last axis
    for frame in data.T:
        video.run(frame.T)
    video.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a simple question, but I haven't been able to find a
This should be a really really simple thing, but for some reason it is
This should be easy for many of you, but for me it's just another
This should be easy, but I'm not sure how to best go about it.
I was told in a comment in another thread that I should be using
As a followon to the discussion in the comments of this answer , should
This should be fine seeing as the CLR hasn't actually changed? The boxes running
This should hopefully be a simple one. I would like to add an extension
This should a quick question for some easy rep. I'm doing some PHP Website
This should be straight forward for a guru. I don't have any code really

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.