This technique comparing the pixel hues in HSB to a list of known hues seems to produce much better masks than my ColorQuantize
approach:
img = Import["https://i.sstatic.net/q9Q5A.png"] // ImageAdjust;
himg = ColorConvert[img, "HSB"];
cols = ColorConvert[{Red, Yellow, Green, Blue}, "HSB"];
diffAngle[a1_diffHue[c1_, a2_]c2_] := .5 - Abs[Abs[a1Abs[Abs[c1[[1]] - a2]c2[[1]]] - .5]
nearestcolpos[c_] :=
First[FirstPosition[cols,
First[MinimalBy[colsFirst@OrderingBy[cols, diffAngle[c[[1]]diffHue[c, #[[1]]]#] &]]]]&]
saturationThreshold = .1;
brightnessThreshold = .15;
isblack[c_] :=
c[[3]] < brightnessThreshold || c[[2]] < saturationThreshold;
hpalette = Map[If[isblack[#], 0, nearestcolpos[#]] &, ImageData[himg], {2}];
masks = Table[Image[hpalette /. (x_ /; x != i -> 0)], {i, Length[cols]}]