Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Extract pixels within certain color range.

I saw this statement being used to extract values of the images within a certain limit

Method 1

yuv_object = ((yuv_image > np.array([77,154,130])).astype(np.float32) + (yuv_image < np.array([187,177,161])).astype(np.float32) * (-0.5))

Values extracted by pixel at each location range between 0,1

but when I run this

Method 2

yuv_image[np.where((yuv_image >= [77,154,130]).all(axis=2) & (yuv_image <= [187,177,161]).all(axis=2))] =[255,255,255]

I expected the pixels inside the range be turned to white color, but I get back the original image

Can anyone explain why this is happening?

I have a two to three such upper and lower limit ranges, I want to check at once turn a pixel to white.

Method 1 does this sequentially not at once

How can I do it at once?

click to hide/show revision 2
retagged

updated 2018-04-27 07:50:22 -0600

berak gravatar image

Extract pixels within certain color range.

I saw this statement being used to extract values of the images within a certain limit

Method 1

yuv_object = ((yuv_image > np.array([77,154,130])).astype(np.float32) + (yuv_image < np.array([187,177,161])).astype(np.float32) * (-0.5))

Values extracted by pixel at each location range between 0,1

but when I run this

Method 2

yuv_image[np.where((yuv_image >= [77,154,130]).all(axis=2) & (yuv_image <= [187,177,161]).all(axis=2))] =[255,255,255]

I expected the pixels inside the range be turned to white color, but I get back the original image

Can anyone explain why this is happening?

I have a two to three such upper and lower limit ranges, I want to check at once turn a pixel to white.

Method 1 does this sequentially not at once

How can I do it at once?