How to know if certain pixel is red, or blue, or green

well a simple solution would be to search the distance on a 3D color cube. If a color must be either Red, green or blue, you can just find the closest point. Posterization filters work in a similar way (can work).

here is a project that incorporates it.