1

I'm trying to follow this tutorial http://www.mathworks.com/help/vision/examples/automatically-detect-and-recognize-text-in-natural-images.html to detect text in image using Matlab.

As a first step, the tutorial uses detectMSERFeatures to detect textual regions in the image. However, when I use this step on my image, the textual regions aren't detected.

Here is the snippet I'm using:

colorImage = imread('demo.png');
I = rgb2gray(colorImage);
% Detect MSER regions.
[mserRegions] = detectMSERFeatures(I, ...
    'RegionAreaRange',[200 8000],'ThresholdDelta',4);
figure
imshow(I)
hold on
plot(mserRegions, 'showPixelList', true,'showEllipses',false)
title('MSER regions')
hold off

And here is the original image

and here is the image after the first step

[![enter image description here][2]][2]

Update

I've played around with parameters but none seem to detect textual region perfectly. Is there a better way to accomplish this than tweaking numbers? Tweaking the parameters won't work for wide array of images I might have.

Some parameters I've tried and their results:

[mserRegions] = detectMSERFeatures(I, ...
    'RegionAreaRange',[30 100],'ThresholdDelta',12);



[mserRegions] = detectMSERFeatures(I, ...
    'RegionAreaRange',[30 600],'ThresholdDelta',12);
Anthony
  • 33,838
  • 42
  • 169
  • 278
  • 1
    Try reducing 'MaxAreaVariation', since your text & background have very little variation (reduce false positives), reducing the minimum value for 'RegionAreaRange', since small characters may be smaller than 200 pixels (increase true positives), and increasing 'ThresholdDelta' since you know there is stark contrast between the text and background (reduce false positives). – kmac Nov 16 '15 at 20:47
  • @kmac, you should make this an answer. – Dima Nov 16 '15 at 21:10
  • I didn't test it at all... I guess I can if it actually works. :) – kmac Nov 16 '15 at 21:13

1 Answers1

1

Disclaimer: completely untested.

Try reducing MaxAreaVariation, since your text & background have very little variation (reduce false positives). You should be able to crank this down pretty far since it looks like the text was digitally generated (wouldn't work as well if it was a picture of text).

Try reducing the minimum value for RegionAreaRange, since small characters may be smaller than 200 pixels (increase true positives). At 200, you're probably filtering out most of your text.

Try increasing ThresholdDelta, since you know there is stark contrast between the text and background (reduce false positives). This won't be quite as effective as MaxAreaVariation for filtering, but should help a bit.

kmac
  • 688
  • 4
  • 15
  • I played around with lot of numbers but none seem to detect text region perfectly. Is there a better way to do this than simply tweaking numbers? - I've updated the question. – Anthony Nov 16 '15 at 22:29
  • Do you have more information about what you're trying to do? Is the text/background always the same color? Is the text always on a flat background? MSER is a more general tool than what you're using it for. You might be better off masking the exact background and text pixel values rather than using MSER. – kmac Nov 16 '15 at 23:25
  • My goal is to extract the textual regions and then send them to ocr. I already have a solution in opencv that uses several thresholding steps to get the textual regions. However, it doesn't work on all images because it isn't algorithm based but rather steps based (i.e. threshold, canny, etc). The text will always be brighter than the background. I came across another answer on SO that used SWT: http://stackoverflow.com/questions/19960826/how-to-make-the-blackboard-text-appear-clearer-using-matlab/19971599#19971599 which I thought would work but doesn't. I can ask a separate question for it. – Anthony Nov 17 '15 at 00:07
  • So right away you should be able to filter out the filled in letters (o, a, b, etc) in your above examples by making sure the feature is light-on-dark. You'll probably have to deal with some false positives, whatever the method (maybe remove those that have a low score from OCR and are not adjacent to other detected characters). Try being even more accepting with the `RegionAreaRange`, something like [8 1000], and go just before the limits of `MaxAreaVariation` and `ThresholdDelta`. If that doesn't work, good luck with SWT. – kmac Nov 17 '15 at 01:57