Filter out everything of a certain color using openCV | opencv filter color
cv2.InRangecreatesamask,whichbasicallymeansitcreatesanimageofthesamesizewherethepixelvaluesthatareintherangeare255,andthevaluesoutsidetherangeare0.https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#void%20inRange(InputArray%20src,%20InputArray%20lowerb,%20InputArray%20upperb,%20OutputArray%20dst)[1]Ifyouwanttohavetheoppositeofthatyoucantaketheoutputofcv2.inRangeandperformabitwise_not:https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-not[2]Ifyo...
cv2.InRange creates a mask, which basically means it creates an image of the same size where the pixel values that are in the range are 255, and the values outside the range are 0.
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#void%20inRange(InputArray%20src,%20InputArray%20lowerb,%20InputArray%20upperb,%20OutputArray%20dst)[1]
If you want to have the opposite of that you can take the output of cv2.inRange and perform a bitwise_not:
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-not[2]
If you want to then use that to black out the pixels in your original image you could do a bitwise_and:
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-and[3]
So I would do something like:
mask = cv2.inRange(img, (255, 0, 0), (100, 0, 0)) # modify your thresholds inv_mask = cv2.bitwise_not(mask) no_sky = cv2.bitwise_and(img, inv_mask) References https://doc...