2

I need filters to improve text visibility on photo, since it has some noise. Which filters (algorithms) do you know for this purpose?

Now, I use monochrome filter but it doesn't improve image quality. I need to filter can determine medium background of little area and make image monochrome depending on medium background.

For example almost all picture background is white and grey characters but some areas has darker color (grey) and black characters. I need to algorithm can understand that some area of image more darker and make level of black accepting lower.


For example, source image: Photo
And processed photo (median, monochrome filters) Processed photo

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    Please post an image so we don't have to guess. – Mark Setchell Feb 08 '16 at 21:13
  • **Use CamScanner (An android/ios app).** Although I am engineer myself and love coding but as you didn't mention about coding, anbd also you somewhere mentioned that you are new to image processing that's why I would suggest you to use this app/tool instead of reinventing wheel. PS: I am impressed by George's. – Pervez Alam Feb 09 '16 at 05:26
  • I need to write it. It's my task, I cannot use third parties software, unfortunately – Denis Sologub Feb 09 '16 at 09:27

2 Answers2

4

Unfortunately I'm not able to provide an accurate and fast answer using an image processing package in code, but I can provide some hints based on some really quick tests done in Photoshop(sorry, visual thinker, slow typist). Worst case scenario, you can run Photoshop filters from Matlab, but the filters are used should be available or not to difficult to implement since I've constraint myself to:

  • Curves
  • Levels
  • High Pass

In simple terms, I recommend first getting read of the gradient dark to bright gradient: it will be easier to play with contrast/threshold on a more even image. In Photoshop I applied curves (which other people wondered about implementing in code)

curves curves settings

Not perfect, but it illustrates the idea of cancelling out a bit of that strong gradient.

On the resulting image I applied levels:

levels levels settings

Afterwards, a high pass:

high pass

You can use the high pass result and blend it (overlay) with the previous step which will emphasize the details:

high pass + overlay

then apply a stamp filter (a mixture of small Gaussian blur + threshold):

stamp filter

or even simpler, on the high pass result, apply curves again or threshold:

curves curves settings

The idea is threshold should deal with the segmentation at the last stage and you need to make it's job as easy as possible by cancelling out elements not pertaining to the text itself (like the flash light like gradient). If you need to cleanup small dots later, morphological filter (like erode, then dilate) should help. You can also find some info on detecting gradients as well.

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Thank you very much! I never made image processing earlier so I try to understand your answer. I think that can make all these actions with image – Denis Sologub Feb 09 '16 at 00:19
  • 1
    No worries. In terms of coding, feel free to choose whatever language your comfortable with. If you're starting from scratch, you might find Python and [numpy](http://www.scipy-lectures.org/advanced/image_processing/) easy to iterate with. The above Photoshop filters should also work in Gimp which is cross-platform and open [source](https://www.gimp.org/downloads/#mirrors) – George Profenza Feb 09 '16 at 00:25
  • I write program on C++ although if language from c family then it's all same almost) Thanks for code samples. – Denis Sologub Feb 09 '16 at 00:29
  • 1
    No worries. For C++ you might like [CImg](http://cimg.eu/reference/group__cimg__tutorial.html) or [Magick++](http://www.imagemagick.org/Magick++/?ImageMagick=euqj79qcd73925ive9hf8sme42) or [OpenCV](http://opencv.org/)'s Image Processing package (although it feels overkill for just for one package given what the library can offer) – George Profenza Feb 09 '16 at 00:32
  • Hi @GeorgeProfenza .. Could you help me with this? http://stackoverflow.com/questions/43758096/opencv-python-stamp-filter-photoshop – VK321 May 05 '17 at 15:51
  • @VinodKumar Unfortunately I won't be able to help with the OpenCV Pythron right know as I'm caught with projects. FWIW you can have a look at this [old answer](http://stackoverflow.com/questions/2345436/how-to-create-photoshop-stamp-filter-analog-in-any-pixel-shading-language/2346024#2346024). It's a shading language(per pixel operations), but it boils down to gaussian blur and threshold mostly. HTH – George Profenza May 05 '17 at 20:41
  • @VinodKumar I found a bit of time to have a quick play with OpenCV Python. The built-in filters work nicely :) Have fun! – George Profenza May 06 '17 at 21:13
1

You could provide an example image.

If you want to make an image black and white you can use a threshold operation as long as your text is darker than the darkest background value.

Compare every pixel vs the global threshold. If higher set it to new value a, if lower set it to new value b. For equals you have to choose one option.

If not you can use a so called local threshold. Here you calculate the threshold for every pixel from its sourrounding. There are many algorithms for calulating that local threshold value.

To name a few local thresholding algorithms: Bernsen Sauvola Mean Median MidGrey Niblack

They all calculate threshold values based on some limited area around your pixel.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • I don't know how to determine this surround area and how to separate medium background colour from medium character colour. Can you post names of these algorithms? – Denis Sologub Feb 08 '16 at 20:59
  • I do not understand how to make the average value of the background color dynamically calculated. Because when user takes a photo this image can be lighted not normally. (for example, it can has lighten areas. Text is visible on these areas but background lighter as well as text and simple monochrome algorithm translates all it into white colour). – Denis Sologub Feb 08 '16 at 21:03
  • 1
    maybe you should explain which tools you are using. I do not know any "monochrome filter". Do you have any basic knowledge in image processing? Do you know how median, mean, min and max filters work or in general neighbourhood operators? – Piglet Feb 08 '16 at 21:12
  • Just I wrote a simple filter where user sets some level (for example, 50) algorithm passes through all image pixels and averages colour channels (pixel colour becomes grey) and if pixel grey value is lower 50 then it black otherwise it's white. – Denis Sologub Feb 08 '16 at 21:16
  • I know only median because use it to smooth edges and noises – Denis Sologub Feb 08 '16 at 21:17
  • 1
    I highly recommend you get familiar with the basics of filters befor you continue doing anything. Read something about neighbourhood operations so you get an idea how those filters work. – Piglet Feb 08 '16 at 21:20