I came up with the following Whiteboard filter inspired by this github post. A Whiteboard filter is useful for making handwritten notes more readable.
whiteboardfilter[img_] := MinFilter[
ImageApply[
(If[Mean[#] > 0.85, 1, Min[#]]) &
,
Sharpen[ColorNegate[
GaussianFilter[MedianFilter[img, 2], 40] - img
],
5
]
],
1
]
More compactly:
whiteboardfilter[img_] := MinFilter[ImageApply[
If[Mean[#] > 0.8, 1, Min[#]] &,
Sharpen[ColorNegate[GaussianFilter[MedianFilter[img, 2], 40] - img], 5]
], 1]
Sample uses
This is a scan of some of my handwritten notes in black ink, blue ink, pencil, and red ink.
Applying the filter:
This is a photo of the same handwritten notes, taken with my tablet:
Applying the filter:
This is a photo of an actual whiteboard where I wrote with a red marker, a blue marker, a black marker, and a green marker, taken with my tablet.
Applying the filter:
Details
- Tweaking the parameters may help you get a better result for you. In my case, moving the bound 0.85 between 0.8 and 0.95 gave other acceptable results.
- I have not tested this filter with pictures of chalk over a greenboard or a blackboard.
- Though it can be easily inferred from the code, this is how the filter works:
-
Apply a Median filter with radius 2
-
To this, apply a Gaussian filter with radius 40
-
To this, subtract the original image, and color negate the result.
-
Sharpen this with radius 5.
-
Apply the following function to the channel values of each pixel: If the mean of the channels is greater than 0.85, put 1 (White), otherwise use the mean. This step helps a lot with the noise in the background of the images, because it replaces very clear pixels with the color White.
-
Apply a Min filter with radius 1.





