OCR: How to find the right ColorMatrix to define new colors? - colors

I'm stuck right now with defining the dimension of each line. The list I want to scrape has various colors in it, and what disturbs me the most a selection:
As you can see the picture I try to analyze got a white background with green text. The selection background is grey with black text. And every second line has a slightly greyer background, but I managed to manipulate the contrast with a ColorMatrix.
Just for reference, I do have some other ColorMatrizes like Greyscale, Negative, SetContrast, SetBrightness and so on.
My method, which is searching the lines does work good with the most part of the picture, but the selection brakes it.
So now I'm stuck and don't know what to do. I googled for an hour, but didn't find a solution.
I thought, that maybe I can transform the background grey from the selection to white without affecting the text and greyscale the rest of the picture. But I can't find a ColorMatrix which does the job.
Do you know one or got a better solution?

Why use a color-matrix at all?
It works (at least for your specific example) much easier with ImageMagick's -threshold operation:
convert \
http://img18.imageshack.us/img18/210/lobbymd9.jpg \
-threshold 50% \
result.jpg
Visual Result:
=>
Thresholding basically leaves over only 2 values (zero or maximum) for each color. Every value below the threshold gets set to 0, values above the threshold get set to 255 (or 65535 if working at 16-bit depth). The end effect is a pure black+white picture.

Related

ImageMagick processing of scan images

I am uploading a picture of a document taken with my smartphone to my Linux server. On my Linux server I am using ImageMagick to cut the edges and do some processing (like gray color coding) to make it look like a scanned document.
Below is one sample image.
I want to trim the image so that only the paper is selected, and do further processing to make it look like a scanned image, similar to what a cam scanner does.
Note: I want the parameters for ImageMagick tool to be generic so that I can use the same command line options to process images taken under different conditions of light.
I agree with #Mark. However, I can offer a starting point that may help you get going in the right direction:
Isolate the Paper:
Assuming the paper is sufficiently contrasted against the background you can use something like:
## make the background transparent
convert 'input_image' \( -clone 0 -fill black -fuzz 10% +opaque "rgb(1,1,1)" -transparent black \) -delete 0 'transp_image'
You will have to change the rgb color values to match the 'white' color of the paper. The display command in imagemagick has a nice utility for this. Also you can play with the -fuzz percentage to isolate the paper only.
Remove the Background: Hopefully the above code will make all areas outside the paper transparent in which case you can trim away the background:
## trim the transparent background away
convert 'transp_image' -trim 'isolat_image'
From there you can do fancier things like changing the perspective. Try looking into -distort in imagemagick (http://www.imagemagick.org/Usage/distorts/#perspective). Though I am not sure how you would apply a distortion in a loop to pictures taken by hand -- each picture would probably require specific input parameters.
Good luck!

After effects - keying based on saturation

In my video, I'm trying to achive something similar to "sin city effect" - leaving one color, while rest is desaturated. since my video isn't suppost to by just black and white with one color pushing out, I need to find a way to composite the color layer over the video, without changing its color.
Basicaly what I need to know is, wheather there is a way to key out everything, that has 0 saturation.
Apply Leave color to your footage, choose the color you wanna leave and set amount to decolor to 100% and use hue to match color

Remove the picture edges

I downloaded a icon, and now i want to reset the color of it, but i'm not good at photoshop, i've set the color of it to be red, but there are to many edges and corners, please tell me how to remove those edges by using photoshop step by step, thanks a lot.
here is the icon i downloaded:
and this is my ugly one:
The best way to alter a single color like this on a simple image such as this is to alter the Hue and Saturation [CTRL / CMD + U]...
This allows you greater color control and keeps the anti-aliased edges of the image intact.
Most beginners alter colors like this by simply selecting the color with the wand, or using the paint bucket on the color. Unfortunately this usually does one of 2 things:
Makes the ragged edges that you saw.
Leaves a halo of the old color as an orphan.
I did this in a few seconds with that tool:

LaTeX \includegraphics and textline

Ok, I am beat. I tried a few things but I am unable to make this happen. I need some help now.
I want to be able to have some text and picture side by side (only one line, thus no need for wrapping or other fun. The picture is small enough to fit in a text line):
This is a text <temp.jpg placed center to the textline>
Problem is, when I use
This is a text \includegraphics{temp.jpg}
the pictures baseline is alligned with the text baseline. I want the picture (vertical) center to be aligned with the text baseline. How can I make this possible?
This is a text $\vcenter{\hbox{\includegraphics{temp.jpg}}}$
It sounds like you want \raisebox (see the raisebox section of the LaTeX wikibook), with a negative argument. Use dimensions ex (the notional height of an 'x' in the current font) or \baselineskip (the size between text baselines) as your units.
If you want to do more complicated things, such as move the graphics box down by half its height, you can, but it gets fiddly. If the graphic size isn't unpredictable, you're probably better off tuning this by hand anyway.
In my opinion, most simple answer \raisebox{-0.5\totalheight}{<your graphic here>}
This is a text \raisebox{-0.5\totalheight}{\includegraphics{temp.jpg}}
Explanation:
\raisebox moves vertically the whole text/picture given as second argument. The first argument is the vertical shift as a length. This command provides the length \totalheight which is, self-explanatory, the height of the whole text/picture that you want to raise. The factor -0.5 lowers exactly at the half of the length(as the question demands). For aesthetic adjustments just modify the factor's value.
By the way, with this method there is no need to get into math mode as in #AlexeiMalistov answer, and no need of double command \vcenter + \hbox

Find most readable colour of text that is drawn on a coloured surface

I'm not sure how to ask this but here goes.
I draw a filled coloured rectangle on screen. The colour is in form of R,G,B
I then want to draw text on top of the rectangle, however the colour of the text has to be such that it provides the best contrast, meaning it's readable.
Example:
If I draw a black rectangle, the obvious colour for text would be white.
What I tried right now is this. I pass this function the colour of the rectangle and it returns an inverted colour that I then use for my text.
It works, but it's not the best way.
Any suggestions?
// eg. usage: Color textColor = GetInverseLuminance(rectColor);
private Color GetInverseLuminance(Color color)
{
int greyscale = (int)(255 - ((color.R * 0.30f) + (color.G * 0.59f) + (color.B * 0.11f)));
return Color.FromArgb(greyscale, greyscale, greyscale);
}
One simple approach that is guaranteed to give a significantly different color is to toggle the top bit of each component of the RGB triple.
Color inverse(Color c)
{
return new Color(c.R ^ 0x80, c.G ^ 0x80, c.B ^ 0x80);
}
If the original color was #1AF283, the "inverse" will be #9A7203.
The contrast will be significant. I make no guarantees about the aesthetics.
Update, 2009/4/3: I experimented with this and other schemes. Results at my blog.
The most readable color is going to be either white or black. The most 'soothing' color will be something that is not white nor black, it will be a color that lightly contrasts your background color. There is no way to programmatically do this because it is subjective. You will not find the most readable color for everyone because everyone sees things differently.
Some tips about color, particularly concerning foreground and background juxtaposition, such as with text.
The human eye is essentially a simple lens, and therefore can only effectively focus on one color at a time. The lenses used in most modern cameras work around this problem by using multiple lenses of different refractive indexes (chromatic lenses) so that all colors are in focus at one time, but the human eye is not that advanced.
For that reason, your users should only have to focus on one color at a time to read the text. This means that either the foreground is in color, or the background, but never both. This leads to a condition typically called vibration, in which the eye rapidly shifts focus between foreground and background colors, trying to resolve the shape, but it never resolves, the shape is never in focus, and it leads to eyestrain.
Your function won't work if you supply it with RGB(127,127,127), because it will return the exact same colour. (modifying your function to return either black or white would slightly improve things)
The best way to always have things readable is to have white text with black around it, or the other way around.
It's oftenly achieved by first drawing black text at (x-1,y-1),(x+1,y-1),(x+1,y-1),(x+1,x+1), and then white text at (x,y).
Alternatively, you could first draw a semi-transparent black block, and then non-transparent white text over it. That ensures that there will always be a certain amount of contrast between your background and your text.
why grey? either black or white would be best. white on dark colors, black on light colors. just see if luminance is above a threshold and pick one or the other
(you don't need the .net, c# or asp.net tags, by the way)
You need to study some color theory. A program called "Color Wheel Pro" is fun to play around with and will give you the general idea.
Essentially, you're looking for complimentary colors for a given color.
That said, I think you will find that while color theory helps, you still need a human eye to fine tune.

Resources