Image Processing - Which OpenCV algorithm will fit my needs? - image-processing

I started to work on a small hobbyist program recently in the area of image processing, and I'm kind of a noob with image processing but I'm trying to figure out at least some aspects of it.
What I want to be able to do is separate between objects in an image by their color (preferably in a real-time video feed), and then recognize their color.
I read a little about OpenCV and also about some of the different algorithms.
I even started to work a little with the canny algorithm, but I'm not sure this is the algorithm I should begin with for my need, as it detects edges of objects regardless of their color.
Even if it is the algorithm I should use, what would be the best method to recognize the colors of the objects it marked for me?
I hope I made myself clear enough.
Thanks a lot!

Understand colour spaces - RGB is almost always the worst source to do image processing on.
Start with HSL and HSV

To separate or to make a color transparent (for instance to remove it) is very simple with OpenCV... I posted an answer (see the link below) which should help you (or maybe solve your problem).
Here is the code I posted
Moreover, the answer from Martin Beckett is absolutely right, RGB is not a good color space to evaluate a color, you can use HSV, the hue value in degree tells you the proper color (something you could compare from a wavelength in a light spectrum) while S and V code a sort of intensity (what I say is to simplify in order to explain that in many cases to use Hue to segment color images is enough).
Even if it is the algorithm I should use, what would be the best
method to recognize the colors of the objects it marked for me?
The type of algorithm you are searching for is called color segmentation... Here is a tutorial which could help you as well.
Welcome to image processing community,
Julien,

For starter you should learn about image array operation, for example using OpenCV function inRange to filter colors by minimum to maximum color range. Another option is by splitting multi-channel array (in this case R, G and B) to 3 different single-channel for further examination. Hope its help

Related

What is the difference between color deconvolution and K-means clustering for colors?

I have some color images needing segmentation. They are images of slides that are stained with hematoxylin and eosin ("H&E").
I found this method for color deconvolution by Ruifrok
http://europepmc.org/abstract/med/11531144
that separates out the images by color.
However it seems that you can do something similar just by using K-means clustering:
http://www.mathworks.com/help/images/examples/color-based-segmentation-using-k-means-clustering.html
I am curious what the difference is. Any insight would be welcome. Thanks.
I can't seem to find a copy of the article (well without paying) but they are not exactly the same.
K means seeks to cluster data. So if you just want to find dominant colors in an image, or do some sorting based on colors, this is the way to go. As a side note: Kmeans can be used on any vector. Its not confined to color, so you can use it for many other applications.
Color Deconvolution is trying to remove the effects of chemical dyes commonly used for microscopy. (If I understood the abstract properly). Based on the specific dye used, the algorithm tries to reverse its effects and give you the original color image back (before the dye was added). I found this website that shows some output. This is deconvolving the dye contribution to the RGB spectrum. It doesn't do any clustering/grouping (other than finding the dye)
Hope that helps
EDIT
If you didn't know, convolution is most often associated with signals/image processing. Basically you take a filter and run it over a signal. The output is a modified version of the original input. In this case, the original image is filtered by a dye with known RGB values. IF we know the full characteristics of the dye/filter we can invert it. Then by running the convolution again using the inverse filter we can hopefully de -convolve the effect. In principle it sounds simple enough, but in many cases this isn't possible.

After Effect's Rotoscoping brush algorithms

I don't think I'm going to get any replies but here goes: I'm developing an iOS app that performs image segmentation functions. I'm trying to implement the easiest way to crop out a subject from an image without the need of a greenscreen/keying. Most automated solutions like using OpenCV just aren't cutting it.
I've found the rotoscope brush tool in After Effects to be effective at giving hints on where the app should be cutting out. Anyone know what kind of algorithms the rotoscope brush tool is using?
Check out this page, which contains a couple of video presentations from SIGGRAPH (a computer graphics conference) about the Roto Brush tool. Also take a look at Jue Wang's paper on Video SnapCut. As Damien guessed, object extraction relies on some pretty intense image processing algorithms. You might be able to implement something similar in OpenCV depending on how clever/masochistic you're feeling.
The algorithm is a graph-cut based segmentation algorithm where Gaussian Mixture Models (GMM) are trained using color pixels in "local" regions as well as "globally", together with some sort of shape prior.
OpenCV has a "cheap hack" implementation of the "GrabCut" paper where the user specifies a bounding box around the object he wish to segment. Typically, using just the bounding box will not give good results. You will need the user to specify the "foreground" and "background" pixels (as is done in Adobe's Rotoscoping tool) to help the algorithm build foreground and background color models (in this case GMMs) so that it will know what are the typical colors in the foreground object you wish to segment, and those for the background that you want to leave out.
A basic graph-cut implementation can be found on this blog. You can probably start from there and experiment with different ways to compute the cost terms to get better results.
Lastly, the "soften" the edges, a cheap hack is to blur the binary mask to obtain a mask with values between 0 and 1. Then recomposite your image using the mask i.e. c[i][j] = mask[i][j] * fgd[i][j] + (1 - mask[i][j]) * bgd[i][j], where you are blending the foreground you segmented (fgd), with a new background image (bgd) using the mask values as blending weights.

IDEAL solution to separate text from background?

Suppose I have gray-scale photographic pictures of texts sheets. Each sheet of paper is exactly white and text is exactly black.
Unfortunately, the light is not uniform, also perspective shading occurs, also sheets of papers may be curved. Of course, there are some small hi freq noise on an image.
I AM SURE that there should be nearly IDEAL solution to separate text and background in this situation.
So what is it? :)
I don't believe it is impossible or even hard to turn such gray-scale images into nearly perfect black and white pictures. I cant prove this but I judge on my own perception: I need no any intelligence to recognize such pictures by an eye. They can be in any language even unfamiliar, but I will SEE what is written exactly.
So, how to teach computer to do the same?
UPDATE
Consider original image
Any global thresolding will cause artefacts (1) and nonuniform text representation (2)
I need some thresolding, which looks for local statistics.
Switch to adaptive thresholding.
Here you will find some introduction - http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm
Adaptive thresholding is designed to deal with exactly this kind of problems.

Recommended pattern recognition technique for chess board

I'm trying to do an application which, among other things, is able to recognize chess positions on a computer screen from screenshots. I have very limited experience with image processing techniques and don't wish to invest a great amount of time in studying this, as this is just a pet project of mine.
Can anyone recommend me one or more image processing techniques that would yield me a good result?
The conditions are:
The image is always crispy clean, no noise, poor light conditions etc (since it's a screenshot)
I'm expecting a very low impact on computer performance while doing 1 image / second
I've thought of two modes to start the process:
Feed the piece shapes to the program (so that it knows what a queen, king etc. looks like)
just feed the program an initial image which contains the startup position, from which the program can (after it recognizes the position of the board) pick each chess piece
The process should be relatively easy to understand, as I don't have a very good grasp of image processing techniques (yet)
I'm not interested in using any specific technology, so technology-agnostic documentation would be ideal (C/C++, C#, Java examples would also be fine).
Thanks for taking the time to read this, and I hope to get some good answers.
It' an interesting problem, but you need to specify a lot more than in your original question in order to find an acceptable answer.
On the input images: "screenshots" is quote vague a category. Can you assume that the chessboard will always be entirely in view? Will you have multiple views of the same board? Can you assume that no pieces will be partially or completely occluded in all views?
On the imaged objects and the capture system: will the same chessboard and pieces be used, under very similar illumination? Will the same lens/camera/digitization pipeline be used?
Salut Andrei,
I have done a coin counting algorithm from a picture so the process should be helpful.
The algorithm is called Generalized Hough transform
Make the picture black and white, it is easier that way
Take the image from 1 piece and "slide it over the screenshot"
For each cell you calculate the nr of common pixel in the 2 images
Where you have the largest number there you have the piece
Hope this helps.
Yeah go with Salut Andrei,
Convert the picture into greyscale
Slice into 64 squares and store in array
Using Mat lab can identify the pieces easily
Color can be obtained from Calculating the percentage of No. dot pixels(black pixels)
threshold=no.black pixels /no. of black pixels + no. of white pixels,
If ur value is above threshold then WHITE else BLACK
I'm working on a similar project in c# finding which piece is which isn't the hard part for me. First step is to find a rectangle that shows just the board and cuts everything else out. I first hard-coded it to search for the colors of the squares but would like to make it more robust and reliable regardless of the color scheme. Trying to make it find squares of pixels that match within a certain threshold and extrapolate the board location from that.

Converting truecolor RGB image to indexed colors

I want to convert a 24bit RGB image (8 bit for each channel) 8 bit using an indexed color palette.
My initial idea was to create an array and simply count the amount of times each color was represented in the image, but I figured it would be wasteful if there were large areas with slight change in color that used up all of the palette space in favor of smaller, but maybe more significant color groups.
Once I complete building the palette, my idea was to consider each RGB color as a 3-dimensional matrix and compare its dot product with each entry in the palette.
...
As you might see, I'm not completely in on the terminology, but I hope you get what I mean :)
My question is; Is anyone able to share insights on how to approach this or perhaps put me in the right direction to any reading material online?
thanks!
According to Paul Heckbert's paper from 1982 popularity algorithm is inferior to Median Cut.
There's family of Median-Cut like (space subdivision) algorithms that choose different criteria, e.g. minimize variance of colors in each partition).
There's fast, but ugly subdivision using Octtree.
There are clustering algorithms such as K-Means and Linde-Buzo-Gray.
An interesting odd one is NeuQuant neural network.
I'm still trying to figure out the best one for pngquant.
You're looking for color quantization.

Resources