Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to improve this pixel remover process?

I have a numpy binary file .npy, containing all the BGR values.

Example

[[ 47  65  82]
 [ 48  65  84]
 [ 49  64  80]
 ...
 [164 170 169]
 [164 173 176]
 [165 171 170]]

I can remove a specific bgr pixel value using img[np.where((img == [b,g,r]).all(axis=2))]=[255,255,255] from the entire image.

for all the above bgr values

this is a very simple loop to filter through each pixel

#go through each pixel
for index,x in np.ndindex(__pixels.shape):
    if x == 0:
        __b = __pixels[index,x]
    elif x == 1:
        __g = __pixels[index,x]
    elif x == 2:
        __r = __pixels[index,x]
        #Change the color of white
        print(__pixels.shape[0]," ",index)
        img[np.where((img == [__b,__g,__r]).all(axis=2))] = [255, 255, 255]

It there any other efficient way where in I can remove these range of pixels stored as numpy array from the entire image?

How to improve this pixel remover process?

I have a numpy binary file .npy, containing all the BGR values.

Example

[[ 47  65  82]
 [ 48  65  84]
 [ 49  64  80]
 ...
 [164 170 169]
 [164 173 176]
 [165 171 170]]

I can remove a specific bgr pixel value using img[np.where((img == [b,g,r]).all(axis=2))]=[255,255,255] from the entire image.

for all the above bgr values

this is a very simple loop to filter through each pixel

#go through each pixel
for index,x in np.ndindex(__pixels.shape):
    if x == 0:
        __b = __pixels[index,x]
    elif x == 1:
        __g = __pixels[index,x]
    elif x == 2:
        __r = __pixels[index,x]
        #Change the color of to white
        print(__pixels.shape[0]," ",index)
        img[np.where((img == [__b,__g,__r]).all(axis=2))] = [255, 255, 255]

It there any other efficient way where in I can remove these range of pixels stored as numpy array from the entire image? image?