0

I have an image shown as below,

enter image description here

I choose three region of interest (ROI) labeled by the red box and I want to remove all yellow colors and replace them with white color (background color).

enter image description here

My code is,

a=np.copy(img)
a[0:0, 50:50][:,:,:]=255
a[130:270, 210:350][:,:,:]=255
a[0:340, 210:390][:,:,:]=255
plt.imshow(a)

However, the result is unexpected (nothing change).

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Jeremy_Tamu
  • 725
  • 1
  • 8
  • 21

1 Answers1

1

Having got to a console I can see the problem.

To simulate what you seem to be doing I used a random array with shape (400, 210, 3)

a = np.random.randint(256, size = (400,210,3))

Your selections

a[0:0, 50:50]
Out[10]: array([], shape=(0, 0, 3), dtype=int64)

0:0 and 50:50 both return zero element selections so there's a 3D array with two zero length axes. Setting this to 255 affected no elements.

a[130:270, 210:350]
Out[13]: array([], shape=(140, 0, 3), dtype=int64)

In this case 210:350 is out of the range for the axis of length 210. Numpy returns a zero length axis again. Setting this to 255 has no effect.

a[0:350, 210:390][:,:,:] 
Out[14]: array([], shape=(350, 0, 3), dtype=int64)

the axis 1 selection is again out of range so an array with a zero length axis is returned.

You are specifying the rectangles as (top left , bottom right) coordinates. It is row_range, column_range that is required.

I guess you want something like:

a[0:50, 0:50, : ] = 255
a[270:350, 130:210, : ] = 255
a[340:390, 0:210, : ] = 255

The axis 0 selection being the rows (y axis) and axis 1 being the columns, (x axis). Axis2 being the r g b components of the colours.

HTH

Tls Chris
  • 3,564
  • 1
  • 9
  • 24