0

I have RGB images as numpy arrays and I want to replace to certain pixel value:

import numpy as np
import random

def rgb():
    L = [1]*3
    return [random.randrange(0, 256,1)for l in L]

def makeDummyData():
    #creates list of lists with 3 rgb, which contains values to replace (x)
    L = [1]*10000
    L = [rgb() for l in L]
    x = L[0]
    for i in range(500):
        L[i] = x
    return L, x

L, x = makeDummyData()
a = np.array(L).reshape(-1, 3)
a = np.array(a).reshape(100, 100, 3)
b = np.where(a == (np.array(x), [255,255,255], a))
print(b)

Instead of returning an array, where the target values are replaced, the output is (array([], dtype=int64),)

1
  • 2
    I think your parenthesis are little off. Commented Jan 28, 2020 at 16:04

1 Answer 1

0

np.where

  • Bracket seems to be off
b = np.where(a == np.array(x), [255,255,255], a) # After == an extra '(' is used
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.