Yes, should point out that I assumed PhotoShop since the term "layer" mask was used. If I get a chance over the weekend, I have PS actions for luminance masks as per the link I gave above, and also have similar process icons using pixel maths for PixInsight if that's what you're using.