Python, access to certain values in array

Viewed 249

I have an array of coordinates (y,x) refered to a specific pixels in an image fig300[0,:,:]. I want find these coordinates in my image and for these pixel change their intensity.

The output of my array, called brighter_spot is this:

array([[116, 159],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [134, 380],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106],
       [ 90, 752],
       [116, 159],
       [235, 206],
       [508, 106]], dtype=int64)

I built the for-loop in this manner:

for y,x in brighter_spot:
        if fig300[0,y,x] == brighter_spot.any():
            fig300[0,y,x] = 0

The for-loop don't have any effect, I think that it don't run properly inside the array comparing each couple. How could I fix it?

2 Answers

Try this:

for y in range(brighter_spot):
    for x in range(y):
        if np.isin(brighter_spot, fig300[0, y, x]).any():
            fig300[0,y,x] = 0

"I want to find these coordinates in my image and for these pixel change their intensity".

Simply do

for x,y in brighter_spot:
    fig300[0,y,x] = ...

Not sure what you want to achieve with brighter_spot.any(). you should check the doc: https://numpy.org/doc/stable/reference/generated/numpy.any.html

This looks for any non None value in the array. In your case it always returns true, and you then compare a pixel value with a boolean at each iteration, what always returns False. That's why the for-loop doers not have any effect.

Related