First attempt with acceptable result
Here is an approach which gives a satisfactory result. ColorsNear
by default uses the "CIE2000"
ColorDistance
metric which works well in this case. The obtained image is readable and doesn't have too many artifacts. However, the result critically depends on a good choice for the penColor
value, and requires manual adjusting the distance
parameter.
penColor = {169, 147, 209}/255.;
(* This value is found by trial and error *)
distance = .16;
img2 = ColorDetect[img, ColorsNear[RGBColor[penColor], distance]]
mask = MorphologicalBinarize[ColorNegate[ImageApply[Min[#/penColor] &, img]]]
final = img*ColorNegate[img2] - mask



The inscription looks contrasting and, which is very important, at the same time naturally continuous, the noise level is acceptable.
Improved approach based on DominantColors
Here is an attempt to improve the algorithm.
The main disadvantage of the previous approach is that it cruicially depends on manually choosen value for the pen color. Let's employ DominantColors
for finding this value automatically:
dc = DominantColors[img, 3]

The first color is background, the second is print color and the third is writing color.
Second, we can directly isolate the writing, the print and the background with ColorDetect
. The "CIE76"
ColorDistance
metric in this case allows to achieve the same results as the "CIE2000"
, but is much faster:
(* This value is found by trial and error *)
dist = .219;
{back, print, writing} = ColorDetect[img, ColorsNear[#, dist, "CIE76"]] & /@ dc;
Surprisingly, some places where the writing overlaps itself and becomes most saturated are not recognized by ColorDetect
as part of the writing, but fortunately are not recognized as part of the background either (same problem with the "CIE2000"
metric):
ImageTake[#, {697, 754}, {923, 951}] & /@ {img, writing, back}

Due to this feature we should use back
at the final stage for filling such holes in the writing as follows:
final = ColorNegate[writing + print + ColorNegate[back]]

The result is very similar to what we got with the previous method. The significant advantage of this approach is that it has only one parameter, which must be adjusted by trial and error.
However, the result can be improved further by clipping the grayscale values from the top:
Manipulate[ImageClip[
ImageTake[final, {215, 520}, {850, 1232}], {0, thr2}, {0, 1}],
{{thr2, .82}, .9, .6, -.01}]

The value thr2 = .82
seems optimal:
final2 = ImageClip[final, {0, .82}, {0, 1}]

Binarize[Blur[ColorNegate@DeleteSmallComponents[ColorNegate@Binarize[ImageAdjust[img, .2], .99], 100], 3], .8]
You can play with the parameters to achieve a more desirable result ... $\endgroup$Binarize
cann't give a good result. I would expect that a solution going through a LAB colorspace for separating the handwritten text would give something better. Also, I think there should be a neural net based approach for this purpose (since the problem is very common). $\endgroup$