Hi everybody, here is my first post on Wolfram Community
The idea presented here is inspired by
whiteboardClean.sh script for ImageMagic. Let's suppose there is a whiteboard photo, like this
SetDirectory[NotebookDirectory[]]
initial = Import["Whiteboard.jpg"]
The algorithm should clean it thereby making a text more visible. I aim here to make a simple algorithm with a few (clearly undestood) parameters without fine tuning (like choosing a precise threshold for binarization). However, in order to make image processing efficient one usually needs some information
a priori.
There are three initialization parameters:
thickness = 4;
denoising = 2;
enhancement = 4;
We assume that there are only lines/curves on the whiteboard and we know approximately the thickness of these lines. It is not necessary to know the thickness exactly it is rather a characteristic scale or an upper-bound estimate for it. There are a lot of methods to extract such scale from the image automatically, hence I take it as known. The meaning of other two parameters will be clear from the following. The first step is denoising:
image = ColorNegate@WienerFilter[initial, denoising];
The second step is to prepare a simple approximate mask for the text:
mask = Erosion[
Composition[ColorNegate, DeleteSmallComponents, ColorNegate]@
Dilation[EdgeDetect[ColorConvert[image, "GrayScale"], thickness + 1],
thickness], thickness - 2];
Here is a demonstration how it works:
HighlightImage[initial, mask]
The third step is to prepare a background:
background =
Inpaint[ImageMultiply[image, ColorNegate@mask], mask,
Method -> "NavierStokes"];
The fourth step is to subtract the background and enhance colors:
result = Sharpen@
ColorNegate@
ImageMultiply[
ImageSubtract[ImageMultiply[image, mask],
ImageMultiply[background, mask]], enhancement]