Change image levels quickly
Blender is a bit limited as an image editor, you may find using an external image editor easier. One option is to use the compositor were masking nodes can be used to select a colour to use as a mask for other nodes.

As your asking with the tag of python, you can access the raw image data through bpy.data.images['img_name'].pixels[x]. This is a list of floats that makeup the pixel data, there are 4 per image pixel (red,green,blue,alpha). You can get the width and height through bpy.data.images['img_name'].size.

for p in bpy.data.images['img_name'].pixels:
    if p &lt; 0.45 and p &gt; 0.48:
        p = 0.2