Here is a first attempt based on nikie’s answer over on DSP.SE, as mentioned by cormullion in comments.
The first point to notice is that, as well as cropping out the black borders and labels, I’ve used the ImageAdjust
command to increase the contrast. This makes the Closing
process a bit cleaner as we’ll see later on.
raw = ImageCrop[
ImageCrop[
ImageRotate[Import["http://cityark.medway.gov.uk/Scans/Ecclesiastical_Rochester_\
Archdeaconry_Area_Parishes/P167_HIGH_HALSTOW_1653_1957/01_Incumbent_\
Service_Registers_1653_1957/P167_01_01.html/00000040.jpg"],180 Degree], {Full, 2820}, Top]];
sharpened = ImageAdjust[raw, 0.4];
It takes a bit of trial and error to work out the right size for the closing, but in cases where there are clear mildew spots like this one, the DiskMatrix
is the way to go.
cl1 = Closing[sharpened, DiskMatrix[6]]
Nikie’s method involved division of the ImageData
, which fails badly if there is an absolute black spot that one is trying to remove - it implies dividing by zero. With a bit of fiddling, I came up with this alternative, using only image processing functions rather than going to raw ImageData
and back. Notice again that I've increased the contrast. It’s a lot more legible at full size.
result1 = ImageAdjust[
ColorNegate[ImageSubtract[ColorNegate[sharpened], ColorNegate[cl1]]], .6]
Next I’m going to try an even more difficult case in full colour, one where there is significant damage to the original parchment. (It’s particularly interesting to me because the second entry on the page records the baptism of Daniel Crump or Cromp, my 6-x-great-grandfather.)
rawc = ImageCrop[ Import["http://cityark.medway.gov.uk/query/results/Scans/Ecclesiastical_Rochester_Archdeaconry_Area_Parishes/P362_SWANSCOMBE_1559_1978/01_Incumbent_Service_Register_1559_1978/P362_01_01.html/0055.jpg"] , {2000, 3400}, {Right,Bottom}];
The first thing to notice is that just using ImageAdjust
to increase the contrast and shift the gamma can make things a lot easier.
sharperc = ImageAdjust[rawc, {0.6, 0, 0.9}]
Nikie’s method for screening out the varying background colours would look something like this. Notice that I reduced the contrast and brightness slightly to avoid divide by zero problems.
whitec = ImageAdjust[Closing[sharperc, 5], {-.1, -0.1}]
Which produces something like:
The resulting text is quite faint but more legible than before. Adding contrast doesn’t help here because quill pen ink varies in color even within a letter or word, so you can’t find a threshold for Binarize
that doesn’t also bring in some of the residue background. Notice that I’ve used nikie’s method directly this time, but with a slight fudge factor in the denominator to avoid divide-by-zero errors.
whiteAdjustedc =
Image[ImageData[sharperc]/(ImageData[whitec] + 0.001)]
Remaining work to do would include finding a way to darken the tails of letters so they don’t disappear when increasing contrast in the image, and smoothing the Closing
background a bit more, which would remove some additional noise in the final image. I experimented with a final Closing[#,2]
to eliminate noise, but that removed too much of the ends of letters. There might be a filter that does that.
Inpaint
? $\endgroup$