1. The algorithm for grey-scale only.
1.1. We have the formula of obtaining the probability that the pixel black-and-white Sij=(Rij+Gij+Bij)/3; Pij = 1 — (|Sij-Rij| + |Sij-Gij| + |Sij-Bij|)/765;
1.2. Set the resulting probability T = 1. Begin to scan a picture on a grid in increments of 1-50 pixels or randomly a few pixels; the more we scan the more plausible our probability. For each of the scanned pixels find Pij; T = T * Pij; If the probability fell below 0.9, then stop scanning and say that the picture is not black and white when it comes to the end, then we say that black and white.
2. Algorithm of obtaining of the palette.
2.1. Run through the picture collect all the colors if the color is greater than 500 the picture is not black and white, if less, then find the probability of kinship colors in tone on the basis of probability say that the picture is b/W or Sepia, etc.