Quantcast

Image Transformation using OpenCV

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Image Transformation using OpenCV

opencv-users mailing list
HI Guys,
              Is it possible to transform an image into any shape instead
of any rectangular or any square ?

How to perform geometric transformation like Perspective transformation to
fit any ellipse shape or circle shape  ?

I am using 4 corner to CV::getperspective ()to get Homography and
warpperspective() to warp, but I need to shape like circle

Please help me



   Thanks & Regards
  Somnath Mukherjee
[hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV

opencv-users mailing list
I guess you're looking for
http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#warpaffine
and
http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html
Circle is something which you should look for fisheye transformation or
correction. Not sure.

-----------------------
Thanks and Regards

Aman Verma
Member Technical Staff - Adobe Systems
Series of Experiments <https://seriesofexp.wordpress.com/>
About Me <http://nitsurat.acm.org/aman/>

On Thu, Jul 28, 2016 at 10:31 AM, Somnath Mukherjee
[hidden email] [OpenCV] <[hidden email]> wrote:

>
>
> HI Guys,
>               Is it possible to transform an image into any shape instead
> of any rectangular or any square ?
>
> How to perform geometric transformation like Perspective transformation to
> fit any ellipse shape or circle shape  ?
>
> I am using 4 corner to CV::getperspective ()to get Homography and
> warpperspective() to warp, but I need to shape like circle
>
> Please help me
>
>
>
>    Thanks & Regards
>   Somnath Mukherjee
> [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV

opencv-users mailing list
HI,
    This is general geometric transformation...my problem is that I have an
image , I need to transform that image into a circle shape ,




   Thanks & Regards
  Somnath Mukherjee
[hidden email]

On Thu, Jul 28, 2016 at 11:43 AM, Aman Verma [hidden email]
[OpenCV] <[hidden email]> wrote:

>
>
> I guess you're looking for
>
> http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#warpaffine
> and
>
> http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html
> Circle is something which you should look for fisheye transformation or
> correction. Not sure.
>
> -----------------------
> Thanks and Regards
>
> Aman Verma
> Member Technical Staff - Adobe Systems
> Series of Experiments <https://seriesofexp.wordpress.com/>
> About Me <http://nitsurat.acm.org/aman/>
>
> On Thu, Jul 28, 2016 at 10:31 AM, Somnath Mukherjee
> [hidden email] [OpenCV] <[hidden email]> wrote:
>
>>
>>
>> HI Guys,
>>               Is it possible to transform an image into any shape instead
>> of any rectangular or any square ?
>>
>> How to perform geometric transformation like Perspective transformation
>> to fit any ellipse shape or circle shape  ?
>>
>> I am using 4 corner to CV::getperspective ()to get Homography and
>> warpperspective() to warp, but I need to shape like circle
>>
>> Please help me
>>
>>
>>
>>    Thanks & Regards
>>   Somnath Mukherjee
>> [hidden email]
>>
>>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV

opencv-users mailing list
I am not sure what you are saying, but as far as I can make out, I presume
that the image will still be an MxN quadrilateral (for display) with the
central part containing the original image that has been distorted into a
circular region (contained within the resulting MxN image).  Am I correct?

If so, applying a radial distortion to your principal point might be what
you need to do.  I am using the term principal point on the assumption that
this is a camera that has been calibrated.  But then, unless your principal
point is the centre of the image, you will introduce distortions but your
image will not be circular.

You could assume that the centre of the image is the principal axis and
compute the distorted points as

x(d) = x(0)[1 + K1*r^2 + K2*r^4+...]
y(d) = y(0)[1 + K1*r^2 + K2*r^4+...]

where x(0), y(0) are the original coordinates and x(d),y(d) are the
distorted coordinates.  K1, K2, ...Kn are the radial distortion
coefficients and will determine the degree of distortion (from barrel
distortion to something more extreme) where r^2 = x^2 + y^2.

Note: x, y will be measured to your origin, i.e., the principal point
(which in the assumption I have suggested, would be the centre of the
image).



On 28 July 2016 at 16:06, Somnath Mukherjee [hidden email]
[OpenCV] <[hidden email]> wrote:

>
>
> HI,
>     This is general geometric transformation...my problem is that I have
> an image , I need to transform that image into a circle shape ,
>
>
>
>
>    Thanks & Regards
>   Somnath Mukherjee
> [hidden email]
>
> On Thu, Jul 28, 2016 at 11:43 AM, Aman Verma [hidden email]
> [OpenCV] <[hidden email]> wrote:
>
>>
>>
>> I guess you're looking for
>>
>> http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#warpaffine
>> and
>>
>> http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html
>> Circle is something which you should look for fisheye transformation or
>> correction. Not sure.
>>
>> -----------------------
>> Thanks and Regards
>>
>> Aman Verma
>> Member Technical Staff - Adobe Systems
>> Series of Experiments <https://seriesofexp.wordpress.com/>
>> About Me <http://nitsurat.acm.org/aman/>
>>
>> On Thu, Jul 28, 2016 at 10:31 AM, Somnath Mukherjee
>> [hidden email] [OpenCV] <[hidden email]> wrote:
>>
>>>
>>>
>>> HI Guys,
>>>               Is it possible to transform an image into any shape
>>> instead of any rectangular or any square ?
>>>
>>> How to perform geometric transformation like Perspective transformation
>>> to fit any ellipse shape or circle shape  ?
>>>
>>> I am using 4 corner to CV::getperspective ()to get Homography and
>>> warpperspective() to warp, but I need to shape like circle
>>>
>>> Please help me
>>>
>>>
>>>
>>>    Thanks & Regards
>>>   Somnath Mukherjee
>>> [hidden email]
>>>
>>>
>>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RES: [OpenCV] Image Transformation using OpenCV [2 Attachments]

opencv-users mailing list
In reply to this post by opencv-users mailing list
(before anything, sorry but I am writing in my phone in the  middle of a trip. So if anyone could improve my answer giving some links to him and/or clarifying some confused point, I would be thankful!)


Hello Sommath.


So…. Just making random guesses here… What you asked looks a little bit strange request for me, so I was wondering what you wanna do… So I thought in 3 situations:


1) Assuming that you only need a circular shape, no matter if you lose part of the image next to the corners.
The best solution in my opinion, is to have a cut in the original image. For that, you could create another image with the same width and height, create a white circle using the function “circle”, and use this image as a mask in the original image.


2) Assuming that you need to fit the entire image in a spherical surface,in an animation or whatever in the OpenGL world.
Well, so it is not a problem of OpenCV. It is a problem of surface mapping in the OpenGL world.


3) If you really need to use the entire image in a spherical format, in the opencv world, well, it is a strange requirement for me…. But if you do, one observation. Even if the relevant information of the image is inside a circle, remember that the MAT structure of OpenCV is always a rectangular matrix. So, if you are going to compare images, or use it to put in a surface in the opengl world, you still will have a rectangular structure.
BUT, if this is the case, I agree with Aman. You are looking for something in the area of fisheye transformation. I am not sure if such function exist, but if it does, it is in that area.
If it doesn't exist, you can always implement your own function to map a pixel from one shape to another!! =] (I have a strong feeling that you should implement your own code if you really need to use the entire image, but not sure. You need to check the docs).
If you are going to this path, remember that is better to do the inverse projection, see where a pixel in the circular shape would be in the rectangular form. If it is in the middle of 3 or 4 pixels, make a mean or a Gaussian blur over that point, and copy the value to the pixel in the circular shape. Otherwise, you will have an alias effect.


I have a strong believe that your case is the first one. If not, good luck!


Sorry to not help more, but I am in my phone. Good luck!


Enviado do meu telefone Windows 10


De: Somnath Mukherjee [hidden email] [OpenCV]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV

opencv-users mailing list
In reply to this post by opencv-users mailing list
I think so. The poster must have tended to transform it to a wide angle pictuer. or super one, we call it as fisheye shoot.
shot by a very short focus distance lens.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV

opencv-users mailing list
In reply to this post by opencv-users mailing list
I think the Somnath wants to map a rectangular image to an ellipse ... or
any shape.  The exact function for that is remap:
http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#remap

Oh, it doesn't do the shape part, you do that part.  Why?  There are
approximately an infinite number of shapes but we have just one function.
You do the math. From each point in the destination image, where should it
come (floating point coordinates) in the source image. Interpolation will
take care of the fact that you must sample from 4 source pixels since you
will almost never exactly extract from a perfect integer pixel location.

Note what I said: Define an equation NOT: where each point in the source
image will go into the destination image. That will leave many "holes" in
the destination image, BUT instead: For each point in the destination
image, where did that come from in the source image (if it is out of
bounds, you must deal with how to map that).

So, you need to define an equation, a mapping, that defines what you mean
by "fill in this ellipse point from this other point in a rectangular
grid".  I suspect, once you really understand what you mean by that, you
can write the equation.  From there, you fill in the X and Y values of
remap and you are done.

Gary
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Image Transformation using OpenCV [2 Attachments]

opencv-users mailing list
In reply to this post by opencv-users mailing list
HI ,
      Thanks to all , actually I was trying to map one image region of
interest to a structure with same size , just like the attached example ,
map flowerstructure ROI to the specified structure in the structure.jpg






   Thanks & Regards
  Somnath Mukherjee
[hidden email]

On Thu, Jul 28, 2016 at 1:31 PM, Guilherme Schvarcz Franco
[hidden email] [OpenCV] <[hidden email]> wrote:

>
> [Attachment(s) <#m_5341657831606688873_TopText> from Guilherme Schvarcz
> Franco [hidden email] [OpenCV] included below]
>
> (before anything, sorry but I am writing in my phone in the  middle of a
> trip. So if anyone could improve my answer giving some links to him and/or
> clarifying some confused point, I would be thankful!)
>
>
>
> Hello Sommath.
>
>
>
> So…. Just making random guesses here… What you asked looks a little bit
> strange request for me, so I was wondering what you wanna do… So I thought
> in 3 situations:
>
>
>
> 1)      Assuming that you only need a circular shape, no matter if you
> lose part of the image next to the corners.
>
> The best solution in my opinion, is to have a cut in the original image.
> For that, you could create another image with the same width and height,
> create a white circle using the function “circle”, and use this image as a
> mask in the original image.
>
>
>
> 2)      Assuming that you need to fit the entire image in a spherical
> surface,in an animation or whatever in the OpenGL world.
>
> Well, so it is not a problem of OpenCV. It is a problem of surface mapping
> in the OpenGL world.
>
>
>
> 3)      If you really need to use the entire image in a spherical format,
> in the opencv world, well, it is a strange requirement for me…. But if you
> do, one observation. Even if the relevant information of the image is
> inside a circle, remember that the MAT structure of OpenCV is always a
> rectangular matrix. So, if you are going to compare images, or use it to
> put in a surface in the opengl world, you still will have a rectangular
> structure.
>
> BUT, if this is the case, I agree with Aman. You are looking for something
> in the area of fisheye transformation. I am not sure if such function
> exist, but if it does, it is in that area.
>
> If it doesn't exist, you can always implement your own function to map a
> pixel from one shape to another!! =] (I have a strong feeling that you
> should implement your own code if you really need to use the entire image,
> but not sure. You need to check the docs).
>
> If you are going to this path, remember that is better to do the inverse
> projection, see where a pixel in the circular shape would be in the
> rectangular form. If it is in the middle of 3 or 4 pixels, make a mean or a
> Gaussian blur over that point, and copy the value to the pixel in the
> circular shape. Otherwise, you will have an alias effect.
>
>
>
> I have a strong believe that your case is the first one. If not, good luck!
>
>
>
> Sorry to not help more, but I am in my phone. Good luck!
>
>
>
> Enviado do meu telefone Windows 10
>
>
>
> *De: *Somnath Mukherjee [hidden email] [OpenCV]
> <[hidden email]>
> *Enviado:*jeudi 28 juillet 2016 09:06
> *Para: *[hidden email]
> *Assunto: *Re: [OpenCV] Image Transformation using OpenCV
>
>
>
>
>
> HI,
>
>     This is general geometric transformation...my problem is that I have
> an image , I need to transform that image into a circle shape ,
>
>
>
>
>
>
>
>
>    Thanks & Regards
>
>   Somnath Mukherjee
> [hidden email]
>
>
>
> On Thu, Jul 28, 2016 at 11:43 AM, Aman Verma [hidden email]
> [OpenCV] <[hidden email]> wrote:
>
>
>
> I guess you're looking for
>
>
> http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#warpaffine
>
> and
>
>
> http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html
>
> Circle is something which you should look for fisheye transformation or
> correction. Not sure.
>
>
> -----------------------
>
> Thanks and Regards
>
>
>
> Aman Verma
>
> Member Technical Staff - Adobe Systems
>
> Series of Experiments <https://seriesofexp.wordpress.com/>
>
> About Me <http://nitsurat.acm.org/aman/>
>
>
>
> On Thu, Jul 28, 2016 at 10:31 AM, Somnath Mukherjee
> [hidden email] [OpenCV] <[hidden email]> wrote:
>
>
>
> HI Guys,
>
>               Is it possible to transform an image into any shape instead
> of any rectangular or any square ?
>
>
>
> How to perform geometric transformation like Perspective transformation to
> fit any ellipse shape or circle shape  ?
>
>
>
> I am using 4 corner to CV::getperspective ()to get Homography and
> warpperspective() to warp, but I need to shape like circle
>
>
>
> Please help me
>
>
>
>
>
>
>
>    Thanks & Regards
>
>   Somnath Mukherjee
> [hidden email]
>
>
>
>
>
>
>
>
>
Loading...