Message Boards Message Boards

3
|
5674 Views
|
1 Reply
|
3 Total Likes
View groups...
Share
Share this post:

Whiteboard image filter in Mathematica

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.

notebook scan

Applying the filter:

filtered notebook scan

This is a photo of the same handwritten notes, taken with my tablet:

notebook photo

Applying the filter:

filtered notebook photo

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.

whiteboard photo

Applying the filter:

filtered whiteboard photo

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:
  1. Apply a Median filter with radius 2

  2. To this, apply a Gaussian filter with radius 40

  3. To this, subtract the original image, and color negate the result.

  4. Sharpen this with radius 5.

  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.

  6. Apply a Min filter with radius 1.


Posted 4 years ago

Hi Luis,

Nice work. Another approach is described in this post.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract