How to create this mask?

I am trying to isolate some sprites and then process all of these with a shader (
Specifically what I want to do is put several fake lights represented by a sprite, and then process only these sprites with the shader.
I think the fastest way is to create a mask, but I really don’t have much idea how to do it.
Here is an example:

Any ideas?

Now I understand a little more how shaders work. With this function I have been able to generate the mask, now I just need to figure out how to generate an image from that function and then process it with the other shader without having to exit the shader

sampler s0;
texture lights;
sampler lights_sampler = sampler_state { Texture = (lights); };

float4 CreateMask (float2 coords: TEXCOORD0) : COLOR0
    float4 color = tex2D (s0, coords);
    float4 lights_color = tex2D (lights_sampler, coords);  

    if (all (color == lights_color))
        return color;

    return float4 (0, 0, 0, 1);