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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:10:33+00:00 2026-06-14T13:10:33+00:00

I want to modify a grayscale image in a manner so that I can

  • 0

I want to modify a grayscale image in a manner so that I can change the pixel values to black for the top half of the image. I can certainly do this by iterating over in the usual manner like this:

for i in range(0,rows):
  for j in range(0,cols):
    if(condition)
      image[i,j] = 0;

But this is quite slow as I have to do video processing. I can see that I have to use Image.point(), but I am not sure how to implement it. Can someone help me out in this?

  • 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-14T13:10:34+00:00Added an answer on June 14, 2026 at 1:10 pm

    This will be much faster if you convert the PIL image to a numpy array first. Here’s how you can zero all the pixels with a value below 10:

    >>> import numpy as np
    >>> arr = np.array(img)
    >>> arr[arr < 10] = 0
    >>> img.putdata(arr)
    

    Or, as you stated in your comment, here’s you’d black out the top half of the image:

    >>> arr[:arr.shape[0] / 2,:] = 0
    

    Finally, since you’re doing video processing, notice that you don’t have to loop over the individual frames either. Let’s say you have ten frames of 4×4 images:

    >>> arr = np.ones((10,4,4)) # 10 all-white frames
    >>> arr[:,:2,:] = 0         # black out the top half of every frame
    >>> a
    array([[[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
    
       [[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to modify an existing Perforce label using a script that I can
I want to modify (Remove all white spaces) all the values of Column Name
I want to modify a connection string that's hard-coded in a Java application (jar
I want to modify a native joomla module that display articles of a category.
I want to modify this code which works pretty good but (or I don't
I want to modify this method (implement my own version of it) but I
I want to modify my function that strips the tag from the value of
I want to modify FTP so that it recovers from the last session during
I want to modify through the dom various element properties and then save that
I want to modify the code snippet below in such a way, that I

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.