I am new to OpenCV and I am learning to do some image processing. As a part of my project, I have a problem of warping an image patch in form of an ellipse into a destination ellipse. As far as I understand, I would need to calculate the affine transform between the two patches, and then warp this transformation into the destination patch. Browsing the internet for help, I didn't find a way to calculate affine transforms between two elliptical patches. Am I on the right track? I would be grateful if you could give me some suggestions how to proceed or where to look for more information.
Asked
Active
Viewed 570 times
2
-
1what do you mean "calculate affine transforms between two elliptical patches". What exactly is the problem. What exactly are you calculating an affine transform from? A set of points? An image of 2 ellipses? – Hammer Oct 08 '12 at 16:11
-
The elliptical patches represent a region of interest for a descriptor. Each descriptor in a source image is mapped to a descriptor from an image database. The idea is to reconstruct the source image using the database. I found the corresponding descriptors, and now I need to warp the corresponding elliptical patches in the source image. Each patch has already an affine transform, so I have to find the affine transform among a corresponding pair and to apply it. I just don't have an idea how to do that. – stckjp Oct 08 '12 at 19:37
-
1how many point correspondences do you have? Have you looked at [cv::getAffineTransform](http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html)? what about [cv::estimateAffine3D](http://opencv.willowgarage.com/documentation/cpp/structural_analysis_and_shape_descriptors.html)? – Hammer Oct 08 '12 at 19:53
-
is the problem getting the affine transform or doing the warping? – Hammer Oct 08 '12 at 19:53
-
The thing is that I need to warp every elliptical patch, from the corresponding image to the source image. The number of patches depends on the number of descriptors, which depends on the source image. Unfortunately, since I have ellipses, I can't use the classical affine transforms from opencv – stckjp Oct 08 '12 at 20:09
-
So, each image has many patches, and I need to warp the corresponding patches I found from the database into the source image that I need to reconstruct. – stckjp Oct 08 '12 at 20:11
-
An ellipse is defined by 3 points, why cant you use those? This would all be a lot clearer if you provided more detail in the question, ideally with pictures. – Hammer Oct 08 '12 at 21:09
-
Each patch describes a region of an image and it is given with a point representing a region center, its affine transform matrix, its scale, and its gradient orientation, and a descriptor vector. Now, I am at a point where I found corresponding elliptical patches between two different images (img1 and img2) using descriptor vectors, and what I would like to do for each patch of img2, is to find an affine transform with respect to a corresponding patch in img1, and warp image2 patch into img1 patch. I hope it's more clear now. – stckjp Oct 09 '12 at 12:43
-
So you have 2 affine transforms [A] and [B] both with respect to some origin O and you want to find the transform between [A] and [B]? Thats the whole question? – Hammer Oct 09 '12 at 14:52
-
yes, just that these two elements are ellipses – stckjp Oct 09 '12 at 16:00
1 Answers
1
The fact that your elements are ellipses is not relevant to the calculating of the transform. Transforms work equally well on arbitrary shapes. Say you have affine transforms [A] and [B] with respect to some origin O, you want the transform between [A] and [B]. There are several ways of thinking about doing this, the simplest one, is to get the transform from [A] to O, then from O to [B] and combine them. [A] to O is simply the inverse of [A] and O to [B] is just [B] so
final_transform = [B]*inverse([A]);
here is a similar question, solving with vector representations is equally valid.
To do the actual warping you can use cv::warpAffine
-
Does this still hold if the two ellipses have different points as centers? If I warp A into B, will the center of the new patch correspond to the center of B? – stckjp Oct 09 '12 at 17:07
-
I still don't understand why it is important that we be talking about ellipses, am I still misunderstanding the question? An affine transform maps an arbitrary configuration of points to a new location. They can be circles, triangles, doodles, anything. My premise is that you know the transforms [A] and [B], is that true? – Hammer Oct 09 '12 at 17:11
-
yes, that's true. My idea was to use this affine transform between two patches to warp one patch into the other. Is this correct reasoning? If so how can I achieve that? Thanks for your answers. – stckjp Oct 09 '12 at 19:03
-
yes you can use an affine transform to warp a patch, look at [cv::warpAffine](http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html) – Hammer Oct 09 '12 at 19:21
-