Issue with binarization of gray colored text of Tesseract - image

I am using Tesseract to recognize some values from the photo which is taken via camera of a phone. My problem is that I cannot recognize numbers which are written in gray color. I know that tesseract performs binarization on the input image. I manually performed the binarization and I realized that all gray texts disappear after binarization. As you can see in the binarized image, there are not any values appeared infront of sollwert and pos/neg toleranz. I can manually set a high threshold to keep my gray colored text,but I need a automatic way in my app. Beside that, the high threshold returns a mostly black image which it also lost some of information. Do you have any suggestions on how to keep my gray color text after binarization?
Thanks in advance

Related

How can I binarize images with text? [MATLAB]

I have a problem with a binarization method.
I have images with text, which I want to binarize.
I want the text ends up being white, but there are images with the text darker than the background and there are images with text less dark than the background.
I want to binarize images like these, but I want the text in white color in the binarized images.
By the way, I am binarizing images with this code. This code is good for images with text darker than the background but it isn't good for text less darker than the background. I think I need a method to know if the text is more or less dark than the background for to invert or no invert the binarization.
umb = graythresh(originalImage);
binaryImage =(~im2bw(originalImage,umb));
How can I do it?
Thanks a lot for the help
there are 2 possible solutions which I had in mind:
solution1:
generate a grayscale image using rgb2gray function.
generate a histogram from the grayscale image, and ignore the transparent pixels. you can use imhist function.
check what is the histogram maximal value. if the value is high - the background is probably light and the text should be darker than the background. in this case - take the negative image (for example, by using imcomplement), and then binarize it. otherwise - you can binarize it as is.
solution 2:
the solution asserts that the image is simple enough, i.e. doesn't have a lot of connected components other than the letters.
binarize the input image.
divide the image into connected components using bwconncomp function.
for each connected component find it's representative value, it can either be 0 or 1
check what is the most common represantative value. if it is 1 - the letters are dark. in this case take the negative image and than binarize. otherwise - binarize the input image as is.
good luck!

[Image Processing]Thresholding Not Ignoring the transparent pixels

Currently I am trying to crop the face along with hairs by the help of image segmentation methods, and then I have set all the non color pixels to be transparent, Then I am trying to apply Binary Threshold technique and Adaptive Threshold. But I am getting non-desirable results. Unfortunately the OpenCV methods are not ignoring the transparent pixels, and in documentation it is not defined how to handle this case, Any experienced help is appreciated (However I can replace the transparent pixels by a color value, provided I get the desired results)
Image 1.png(original Image with transparent background)
Image2.png(Image after applying simple binary threshold)
Image3.png(Image after adaptive threshold)
Clearly some image distortion/Noise is seen in the transparent areas of the image ?
And I was able to solve this issue , I am posting this answer to help other fellow people for the educational purposes, and due to limited clarification about this thing, So the hack is to change the background color to be white(it worked in my case but you can surely choose some other background color), So now I colored all the pixels with alpha value 0 as while colored opaque pixels and then applied the required operations, And the outputs were as per expectation:
Then applied some more image processing features to create this image out of this:

Matlab GUIDE blurs image?

my plan is implementing an image in a Matlab GUIDE figure. Somehow the output is always blurred (see screenshot). On the left you can see the image in Photoshop on the right in Matlab - notice how the font and other parts become blurred.
I experimented with JPEG and PNG file formats (no compression), I also tried various pixel sizes(resolutions smaller, same and bigger as the actual position of the image) and DPI(values between 30-300) settings, because I expected some scaling issue. Somehow I am stuck - Looking forward to your input!
Thank you,
Florian
Screenshot of the issue: http://s1.bild.me/bilder/260513/6875414Screen_Shot_2014-06-29_at_23.19.34.png
Most probably the reason for the blur is interpolation.
If the axis size you allocated for the image is different from the size of the image MATLAB will resize the image to occupy the whole area.
In order to prevent any interpolation you must set the axis dimension to be the image dimension.

UIImage - highlight single color only

I need to convert an image to greyscale except for a single color. For example, if there is some red in the image (like a red bus), this will remain in color, but the rest of the image will remain in black & white.
I think I should be able to do a rudimentary job of this by going over each pixel individually, such as here: http://brandontreb.com/image-manipulation-retrieving-and-updating-pixel-values-for-a-uiimage . I am assuming I would just leave certain pixels alone if their red component was above a certain amount, and green/blue was below a certain amount. Otherwise, set the pixel to grayscale. Is this a good approach?
I'm more interested in whether or not it is possible to do to the live camera input, such as with a Core Image filter, or using GPUImage, but I haven't been able to find any suitable filters. Any suggestions?
Update:
This seems to be possible using GPUImage with a GPUImageLookupFilter, as per: https://stackoverflow.com/a/19340583/334982
I've created a lookup.png file in Photoshop, by dropping the Saturation for all colours except red to 0. This works ok, but it doesn't seem to grey out all colours. For example, my skin still looks fairly skin coloured, and my brown table is still fairly brown.

Edge Detection and transparency

Using images of articles of clothing taken against a consistent background, I would like to make all pixels in the image transparent except for the clothing. What is the best way to go about this? I have researched the algorithms that are common for this and the open source library opencv. Aside from rolling my own or using opencv is there an easy way to do this? I am open to any language or platform.
Thanks
If your background is consistend in an image but inconsistent across images it could get tricky, but here is what I would do:
Separate the image into some intensity/colour form such as YUV or Lab.
Make a histogram over the colour part. Find the most occuring colour, this is (most likely) your background (update) maybe a better trick here would be to find the most occuring colour of all pixels within one or two pixels from the edge of the image.
Starting from the eddges of the image, set all pixels that have that colour and are connected to the edge through pixels of that colour to transparent.
The edge of the piece of clothing is now going to look a bit ugly because it consist of pixels that gain their colour from both the background and the piece of clothing. To combat this you need to do a bit more work:
Find the edge of the piece of clothing through some edge detection mechanism.
Replace the colour of the edge pixels with a blend of the colour just "inside" the edge pixel (i.e. the colour of the clothing in that region) and transparent (if your output image format supports that).
If you want to get really fancy, you increase the transparency depending on how much "like" the background colour the colour of that pixel is.
Basically, find the color of the background and subtract it, but I guess you knew this. It's a little tricky to do this all automatically, but it seems possible.
First, take a look at blob detection with OpenCV and see if this is basically done for you.
To do it yourself:
find the background: There are several options. Probably easiest is to histogram the image, and the large number of pixels with similar values are the background, and if there are two large collections, the background will be the one with a big hole in the middle. Another approach is to take a band around the perimeter as the background color, but this seems inferior as, for example, reflection from a flash could dramatically brighten more centrally located background pixels.
remove the background: a first take at this would be to threshold the image based on the background color, and then run the "open" or "close" algorithms on this, and then use this as a mask to select your clothing article. (The point of open/close is to not remove small background colored items on the clothing, like black buttons on a white blouse, or, say, bright reflections on black clothing.)
OpenCV is a good tool for this.
The trickiest part of this will probably be at the shadow around the object (e.g. a black jacket on a white background will have a continuous gray shadow at some of the edges and where to make this cut?), but if you get this far, post another question.
if you know the exact color intensity of the background and it will never change and the articles of clothing will never coincide with this color, then this is a simple application of background subtraction, that is everything that is not a particular color intensity is considered an "on" pixel, one of interest. You can then use connected component labeling (http://en.wikipedia.org/wiki/Connected_Component_Labeling) to figure out seperate groupings of objects.
for a color image, with the same background on every pictures:
convert your image to HSV or HSL
determine the Hue value of the background (+/-10): do this step once, using photoshop for example, then use the same value on all your pictures.
perform a color threshold: on the hue channel exclude the hue of the background ([0,hue[ + ]hue, 255] typically), for all other channels include the whole value range (0 to 255 typically). this will select pixels which are NOT the background.
perform a "fill holes" operation (normally found along blob analysis or labelling functions) to complete the part of the clothes which may have been of the same color than the background.
now you have an image which is a "mask" of the clothes: non-zero pixels represents the clothes, 0 pixels represents the background.
this step of the processing depends on how you want to make pixels transparent: typically, if you save your image as PNG with an alpha (transparency) channel, use a logical AND (also called "masking") operation between the alpha channel of the original image and the mask build in the previous step.
voilĂ , the background disappeared, save the resulting image.

Resources