-1

I am trying to clear text in the image using OpenCV. i am using code below

cv::Mat original = [MAOpenCV cvMatGrayFromAdjustedUIImage:image];
cv::GaussianBlur(original, original, cvSize(11,11), 0);
cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 5, 2);
image = [MAOpenCV UIImageFromCVMat:original];
original.release(); 

This working fine but its also removing text color. just display border of large text. How can i preserve color of text in this example.

Here is the original image

enter image description here

Here is the image that converted using this code

enter image description here

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56

2 Answers2

0

try using cv::THRESH_BINARY_INV and after that invert the result !

Engine
  • 5,360
  • 18
  • 84
  • 162
  • Thanx for reply, but That will gives same result bcoz in `cv::THRESH_BINARY_INV` the color inside the text is not visible. – Dilip Manek Mar 26 '14 at 12:02
  • I can't test it now, but if you invert you image you'll get txt in white and and everything else in black, run the threshold binary, you'll get the text in 255 and the other stuff in 0 reinvert the whole thing and there you go , I hope it help ! http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html – Engine Mar 26 '14 at 12:26
  • and by the way I don't get why you're using adaptivethreshold and not simply threshold ? – Engine Mar 26 '14 at 12:31
  • Does it make any difference? – Dilip Manek Mar 26 '14 at 12:32
  • it depends on you application ;-) – Engine Mar 26 '14 at 12:33
  • Nope sorry, I still get border of text not its color. Trying simple threshold now. – Dilip Manek Mar 26 '14 at 12:43
  • if you want to get the real color of the text not only binary, you have to use the result of threshold binary, in which the whole text is in white = 255 and copy your original using the threshold result as a mask . – Engine Mar 26 '14 at 12:48
  • No no black color is okay. But problem is that code eliminate text inside color with the background color – Dilip Manek Mar 26 '14 at 13:16
  • 1
    You don't need any inversion here. Use simple threshold and cv::THRESH_BINARY as thresholdong type. – Andrey Smorodov Mar 27 '14 at 07:18
  • @AndreySmorodov i am using `cv::THRESH_BINARY` but i get the result like displayed in my images – Dilip Manek Apr 01 '14 at 04:32
  • @AndreySmorodov I have checked your answer here http://stackoverflow.com/questions/22122309/opencv-adaptive-threshold-ocr/22127181#22127181. really nice but i am facing similar issue that user has getting image in green color. Tried to change according to your comment but still same result. – Dilip Manek Apr 01 '14 at 06:11
0

For pictures of larger letters like yours, try to increase the 'Block Size' parameter passing into the adaptiveThreshold function.

from your 5

cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 5, 2);

try to increase it (e.g. to 15) until the letters are not hollowed anymore.

cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 15, 2);

Remember that the Block Size parameter has to be an odd number.

Miroslav
  • 322
  • 5
  • 13