Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda