Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Use Numpy to convert rgb pixel array into grayscale

What's the best way to use Numpy to convert a size (x, y, 3) array of rgb pixel values to a size (x, y, 1) array of grayscale pixel values?

I have a function, rgbToGrey(rgbArray) that can take the [r,g,b] array and return the greyscale value. I'd like to use it along with Numpy to shrink the 3rd dimension of my array from size 3 to size 1.

How can I do this?

Note: This would be pretty easy if I had the original image and could grayscale it first using Pillow, but I don't have it.

UPDATE:

The function I was looking for was np.dot().

From the answer to this quesiton:

Assuming we convert rgb into greyscale through the formula:

.3r * .6g * .1b = grey,

we can do np.dot(rgb[...,:3], [.3, .6, .1]) to get what I'm looking for, a 2d array of grey-only values.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

See the answers in another thread.

Essentially:

gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!