Three Dimensional Hough Space - image-processing

Im searching for radius and the center coordinates of circle in a image. have already tried 2D Hough transform. but my circle radius is also a unknown. Im still a beginner to Computer vision so need guild lines and help for implementing three dimensional hough space.

You implement it just like 2D Hough space, but with an additional parameter. Pseudo code would look like this:
for each (x,y) in image
for each test_radius in [min_radius .. max_radius]
for each point (tx,ty) in the circle with radius test_radius around (x,y)
HoughSpace(tx,ty,test_radius) += image(x,y)

Thiton gives you the correct approach to formalize the problem. But then, you will run in other problems inherent to the hough transform:
how do you visualize the parameter space? You may implement something with a library like VTK, but 3D visualization of data is always a difficult topic. The visualization is important for debugging your detection algorithm and is one of the nice thing with 2D hough transform
the local maximum detection is non trivial. The new dimension will mean that your parameter space will be more sparse. You will have more tuning to do in this area
If you are looking for a circle detection algorithm, you may have better options than the hough transform (google "Fast Circle Detection Using Gradient Pair Vectors" looks good to me)

Related

Which straight line detection algorithms will still detect lines that have suffered a degree of lens distortion in photos?

I've found other questions on the topic of detecting straight lines in images which I will read up on.
But I'm aware the in many photos the real life straight lines end up curved.
I don't have to de-curve fish-eye distortion or anything extreme.
But I would like to handle a "typical" amount of curve distortion as though they are still straight lines.
Are there some algorithms or techniques that can handle this in a "good enough" manner?
Here's an old photo of mine of a book showing the kind of curved straight lines I had in mind. It's a good example for the curvature and lens distortion. (It may not be a good example generally due to the other lines in the background, but that's beside the point of the current question.)
The curvature of the edges doesn't seem that severe, and at worst the Hough transform will just break the edges in a few segments.
I would be more worried by the lack of contrast of the edges (white on white) which can make the detection fail.
As it turns out, one of the most popular techniques used for straight line detection also exists in versions that work with curves.
It's called the "Hough Transform".
Wikipedia article
Stackoverflow tag
It was originally for detecting straight lines, but has been generalized to also work with curves and other arbitrary shapes. From the Wikipedia article:
The classical Hough transform was concerned with the identification of
lines in the image, but later the Hough transform has been extended to
identifying positions of arbitrary shapes, most commonly circles or
ellipses.
There are even papers on the specific topic of using Hough transforms to deal with lens distortion:
Automatic Lens Distortion Correction Using One-Parameter Division Models
A Hough transform-based method for radial lens distortion correction
Wide-Angle Lens Distortion Correction Using Division Models
Automatic curve selection for lens distortion correction using Hough transform energy
Blind radial distortion compensation from video using fast Hough transform

How to transform the image?

You can see the lanes are askew. I want to make the lanes perpendicular.
I used Photoshop's perspective transformation function, got the result:
Although the lanes are vertical now, the cars in the far end become large, the cars in the near end become so small. That is not what I want.
I tried Photoshop's warp function. Photoshop gave me 8 control points and I finally got my ideal result.
What is the name of that kind of transformation?
How to do the transformation programmatically? I'm using C# + EmguCV(OpenCV)
Thanks a lot.
It is called Radial Distortion. It is commonly fixed by Browns model. Here is a tutorial on how to fix it using Photoshop.
Be aware that in your case, you should first fix the radial distortion, and only then do a projective transformation (Homography), since radial distortion is a property of the lens, whereas the projective transformation is a property of the world you are taking a look at.
Apart from correcting for radial distortion, the perspective can be corrected by applying a homography transform (assuming the road is flat)

OpenCV Identifying Lines and Curves

I'm just starting to learn OpenCV programming. May I just ask about how can I identify lines and curves in OpenCV? My problem is that I have to identify if the image contains a convex or concave (horizontal or vertical curve) curve, a vertical, diagonal or a horizontal line.
In my code, I used CvSetImageROI to take a particular part of an image, and then I'm trying to identify each according to the said lines/curves.
Are there functions in OpenCV that are available? Thank you very much for the help. By the way, i'm using Linux and C++.
Hough transform http://en.wikipedia.org/wiki/Hough_transform, http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm
is the standard way to do it. In its simple form (as implemented in OpenCV) it can detect lines of arbitray position and angle and line segments.
Look here for an example
http://opencv.itseez.com/modules/imgproc/doc/feature_detection.html?highlight=hough#houghlinesp
For curves, the detection process is a bit more complicated, and you need the general Hough transform It is not yet available in OCV, but you can write it as an exercise or look for a good implementation.
http://en.wikipedia.org/wiki/Generalised_Hough_transform describes it (in short)

Finding a grid in an image

Having a match-3 game screenshot (for example http://www.gameplay3.com/images/games/jewel-quest-ii-01S.jpg), what would be the correct way to find the bound box for the grid (table with tiles)? The board doesn't have to be a perfect rectangle (as can be seen in the screenshot), but each cell is completely square.
I've tried several games, and found that there are some per-game image transformations that can be done to enhance the tiles inside the grid (for example in this game it's enough to take the V channel out of HSV color space). Then I can enlarge the tiles so that they overlap, find the largest contour of the image and get the bound box from it.
The problem with above approach is that every game (or even level inside the same game) may need a different transformation to get hold of the tiles. So the question is - is there a standard way to enhance either tiles inside the grid or grid's lines (I've tried finding lines with Hough transform, but, although the grid seems pretty visible to the eye, Hough doesn't find it)?
Also, what if the screenshot is obtained using the phone camera instead of taking a screenshot of a desktop? From my experience, captured images have less defined colors (which depends on lighting), and also can be distorted a little, as there is no way to hold the phone exactly in front of the screen.
I would go with the following approach for a screenshot:
Find corners in the image using for example a canny like edge detector.
Perform a hough line transform. This should work quite nicely on the edge image.
If you have some information about size of the tiles you could eliminate false positive lines using some sort of spatial model of the grid (eg. lines only having a small angle to x/y axis of the image and/or distance/angle of tile borders.
Identifiy tile borders under the found hough lines by looking for edges found by canny under/next to the lines.
Which implementation of the hough transform did you use? How did you preprocess the image?
Another approach would be to use some sort of machine learning approach. As you are working in OpenCV you could use either a Haar like feature detector. An example for face detection using Haar like features can be found here:
OpenCV Haar Face Detector example
Another machine learning approach would be to follow a Histogram of Oriented Gradients (Hog) approach in combination with a Support Vector Machine (SVM). An example is located here:
HOG example
You can find general information about HoG detection at:
Hog detection

OpenCV detect corners

I'm using OpenCV on the iPhone. I want to find a Sudoku in a photo.
I started with some Gaussian Blur, Adaptive Threshold, Inverting the image and Dilate.
Then I did some findContour and drawContour to isolate the Sudoku grid.
Then I've used the Hough Transform to find lines and what I need to do now is find the corners of the grid. The Sudoku photo may be taken in an angle so I need to find the corners so I can crop and warp the image correctly.
This is how two different photos may look. One is pretty straight and one in an angle:
Probabilistic Hough
http://img96.imageshack.us/i/skrmavbild20110424kl101.png/
http://img846.imageshack.us/i/skrmavbild20110424kl101.png/
(Standard Hough comes in a comment. I can't post more than two links)
So, what would be the best approach to find those corners? And which of the two transform is easiest to use?
Best Regards
Linus
Why not use OpenCV's corner detection? Take a look at cvCornerHarris().
Alternatively, take a look at cvGoodFeaturesToTrack(). It's the Swiss Army Knife of feature detection and can be configured to use the Harris corner detector (among others).
I suggest the following approach. First, find all intersections of lines. It is helpful to sepparate lines into "horisontal" and "vertical" by angle (i.e. find two major directions of lines). Then find the convex hull of acquired points. Now you have corners and some points on the boundaries. You can remove the latter by analysing the angle between neighbour points in the convex hull. Corners will have the angle about 90 degrees and points on the boundaries - about 180 degrees.

Resources