Material Editor: Generate mask from color ID texture
Two independent node groups for creating a mask based on a color and a texture :

material setup :



the first node group outputs boolean 1/0  ( all comparisions are "less than "):



the second node group outputs grayscale :



adjust the sensitivity/clipping to get a good result "sensitivity is added to overcome  errors due to rounding the numbers"