Undistorting concentric circles in opencv - c++

I have an image consisting of concentric circles. I'm trying to undistort the image so that the circles are equal spacing apart around the edges, as if the camera is parallel to the plane. (Some circles will appear closer to the next which is fine, I just want equal spacing all around the edges between the two adjacent circles)
I've tried to estimate a rigid transform by specifying points of the outer circle, but it distorts the inner circles too much, and I've tried a findhomography by specifying points of all the circles, and comparing with points of circles of where they should be.
From what I see the outer circles are 'squished' vertically, so need to be smushed up horizontally, but the inner circles are more circular. What can I do to undistort this image?

https://code.google.com/p/ipwithopencv/source/browse/trunk/ThinPlateSpline/ThinPlateSpline/?r=4
Using this implementation of Thin Plate Spline, I was able to input a set of points representing all the distorted circles, and another set of points which represent where they should be, to get the desired output. It isn't absolutely perfect, but it's more than good enough!

Related

How to remove eyelashes noise using ellipse detection

Hopeful end result of detecting ellipse in photo and drawing edges accurately:
Picture I'm trying to work with:
I’m looking to detect the ellipses of an eye in a side view image but one problem is that when I run the canny function and draw the edges it can only draw edges on the eyelashes and make some sort of ellipse there. This noise is also causing problems because in my hough transform ellipse function I am thresholding for all values higher than .9 (and lower than .7) and these values on the eyelashes have the maximum pixel intensity values so they are taken into account.
Is there a way to remove the noise (eyelashes)? I am using skimage from sci-kit image for all of this. This is for a side view of the eye.

OpenGL: How to fill a polygon gradiently smoothly without spurious star edges

Suppose the polygon is a hexagon.
To fill it gradiently, assume there are many smaller hexagons inside.
The smaller the hexagon, the pixel on that hexagon has a brighter color.
However, after I finish it, I find that there are spurious star edges between the center and the corners, like in the attached image (ignore the two discs inside).
How should I design an algorithm to make the filling more smoothly?

Homography for Image Rectification

We can do image rectification given stereo images. For a single image we can find the two vanishing points and then the vanishing line. Using this vanishing line we can do projective rectification. But what constraints are required for affine rectification??
I basically want to rectify an image to its frontal view such that parallel line in the world are parallel and also parallel to the x-axis. I hope am making myself clear ..
Also what is the homography to transfer a vanishing point (x,y) in the image to (1,0,0) ???
Thanks in advance
A projective transformation transfers an imaged point to an ideal point (1,0,0). It thereby rectifies an image up to an affine transformation of what people would normally want to see. This process is "affine rectification". Affine transformations keep lines parallel, but can skew the image and make it look weird, so I'm not sure if that's where you want to stop. Affine transformations can turn circles into ellipses and can change the angle of intersecting lines.
To remove the affine transformation (metric rectification), one must identify the "conic dual to the circular points". This can be done by identifying two pairs of perpendicular lines; identifying an ellipse that should really be a circle; or by using two known length ratios. Once this is done, the only differences between your image and how you would like it to look will be its scale, its x and y positions and the rotation of the whole image.

Calculate vertices of a bounding box

I am stumped by this problem which looks very simple. I have a 2D bounding box of which I have two corner points. I wish to determine the remaining two corner points. An important constraint: the bounding box can be oriented in any way and not necessarily aligned to the horizontal and vertical axes (i.e. x and y axes).
I wish to do this as I want to raster scan the bounding box.
I'm sure this is not an answer you want to hear, however, as mentioned here before, two diagonally opposite points are not enough to define a rectangle on a 2D surface. As a picture is worth a thousand words, here's a picture of two different rectangles sharing the same diagonally opposite points.
As mentioned in the comments, you don't have complete information. Let me explain: Draw a dummy rectangle that you want to find the points for -- make sure the rectangle is rotated i.e. not "flat".
Now, pick the top-left and bottom-right points -- treat them as the top-left and bottom-right points of a rectangle that is sitting flat on the x-axis. This shows that you can have at least two rectangles with the same two opposing points. Similarly, you can alter the angle of tilt and get an infinite number of points.
If you want a unique rectangle, you need to define at least the tilt. Hope that helps.

Calculate minimum area rectangle for a polygon

I have a need to calculate the minimum area rectangle (smallest possible rectangle) around the polygon.
The only input i have is the number of points in polygon.
I have the co-ordinates of the points also.
This is called Minimum Bounding Box, it's most basic algorithm used in OCR packages. You can find an implementation using Rotating Calipers from the OpenCV package. Once you get the source code, check out this file,
cv/src/cvrotcalipers.cpp
The method you need is cvMinAreaRect2().
Use the rotating calipers algorithm for a convex polygon, or the convex hull otherwise. You will of course need the coordinates of the points in the polygon, not just the number of points.
First do a grahm-scan and get the convex hull of the set of points. Then you can use something like minimum rectangle discussed here
Follow the following algorithm
Rotate the polygon onto the XY plane
Pick 1 edge and align this edge with the X axis(use arctan). Use the min/max x,y to find the bounding rectangle. Compute Area and store in list
Do the same for remaining edges in clipped polygon.
Pick the rectangle with the minimum Area.
Rotate Bounding Rectangle back for Coplanar reverse rotation of Step 1 and step 2
for more detail check link Minimum-Area-Rectangle
Obviously, you'll need the coordinates of the points to get the answer. If the rectangle is aligned to the X and Y aces, then the solution is trivial. If you want the smallest possible rectangle, at any angle, then you'll need to do some sort of optimization process.