mardi 26 mai 2020

Random values +/- 10 from a supplied x that will not exceed a global range of 0-255

I have found similar, but not suitable answers to my issue. I need to build some noise into recieved RGB values, but the values cannot exceed 255 or be below 0.

I have the following example:

red,green,blue = (253, 4, 130)

print(
    (np.random.randint(red-10,red+10),
     np.random.randint(green-10,green+10),
     np.random.randint(blue-10,blue+10)))

# output values cannot be over 255 or under 0

#The following output would not be ok.
>>>(257, -2, 132)

How can I generate random +/- 10 value from any point within the range of 0-255 that will not exceed 255 or 0?




Aucun commentaire:

Enregistrer un commentaire