Results 1 to 11 of 11
  1. #1
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Exclamation Pixel Transform: Cartesian to Polar

    Hey guys, I'm working on a project where I need to transform a traditional image into a polar image (Rectangular|--->Circular).

    Suggestions? Anyone have experience with this type of idea? It's my assumption there is some known algorithm that I could apply here, or some method that I am unaware of.

    -Thanks!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Pixel Transform: Cartesian to Polar

    If you want to rotate the image a certain number or radians you can apply a rotational transform to a graphics instance.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Pixel Transform: Cartesian to Polar

    Not to rotate, but instead mutate/transform.... I want to go from an image that is rectangular to circular. [ ] ----> ( )

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Pixel Transform: Cartesian to Polar

    Quote Originally Posted by MattTuck View Post
    Not to rotate, but instead mutate/transform.... I want to go from an image that is rectangular to circular. [ ] ----> ( )
    That doesn't really tell me much. going from (x,y) to (r, theta) doesn't change the image, only the manner in which one references a given point. If you want to morph your image somehow, you might apply a home grown implementation of AffineTransformOp.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Pixel Transform: Cartesian to Polar

    Something like this



  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Pixel Transform: Cartesian to Polar

    I have never done that before (it looks similar to an anamorphic projection). Here is a link I found which has some code (not Java). It may offer some help.

    Polar To/From Rectangular Transform of Images - File Exchange - MATLAB Central

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Pixel Transform: Cartesian to Polar

    Rectangular coordinates (x,y) can be written in polar form as (r*sin(phi), r*cos(phi); you want coordinates (r, phi); note that r^2 == x^2+y^2 and phi == atan(y/x)

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  8. #8
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Pixel Transform: Cartesian to Polar

    Assuming I wrote it that way, all of my pixles will stay in the same place...they'll just be described in a polar form where r^2=x_max^2+y_max^2 and phi ranges from [0,90].

    I want to actually mutate the image. To move the pixel in (0,0)Java-cart(note: (0,0) is in the top left corner) to (r_max,0)polar

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Pixel Transform: Cartesian to Polar

    Quote Originally Posted by MattTuck View Post
    Assuming I wrote it that way, all of my pixles will stay in the same place...
    That is beyond me ... in my math those points don't stay at the same place.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  10. #10
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Pixel Transform: Cartesian to Polar

    It seems to me that is I preserve the height of y-axis as the radius then all I have to do is "bend" the x-axis 360. But in doing so I'd have gaps in my image, and I'm not sure how to handle that gradience.

  11. #11
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,717
    Rep Power
    17

    Default Re: Pixel Transform: Cartesian to Polar

    If I understand correctly you want to take each pixel in your source image and interpret its y-coordinate as r and its x-coordinate as phi. (You would scale the x-coordinate by 2*pi/width so that phi ends up going from 0->2*pi. You might also want to scale the y-coordinate to keep the final radius a reasonable size.). In other words your source image is telling you the colour of each pixel (r,phi) in the destination image.

    The tricky bit is that the pixels in the destination image don't lie *exactly* at places (r,phi) for integer r and phi.

    I can imagine two ways of dealing with this: The first is to simply round values. So, for each value in the destination image (1) calculate what r and phi is associated with that pixel, (2) scale these values if desired, (3) round the result to a pair of integers, (4) look up the value for the pixel in the original image.

    The more complicated way recognises that each pixel of the destination image really represents a region of the source image. Take the (weighted) mean of all the pixels in this region and use this for the colour of the target image pixel.

    ---

    As an aside CAT scanners face a similar problem. The values from the scanner are 1-d fourier transformed and assembled to make a 2-d image (whose pixel values are given for polar positions ie regularly spaced values of r and phi). This 2-d image is then inverse 2-d fourier analysed to reveal a section of the patient's inside. The problem is that the inverse transform wants the values at cartesian positions (ie regularly spaced values of x and y).

    [Edit: from a computational standpoint it makes no difference whether you view the problem as the mutation of an image or merely as a change of coordinate system.]
    Last edited by pbrockway2; 10-07-2015 at 03:45 AM.

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. Cartesian coordinate system (X > 0, Y>0)
    By cselic in forum Java 2D
    Replies: 0
    Last Post: 07-02-2010, 01:54 PM
  3. compare two images pixel by pixel
    By java_bond in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2010, 11:27 AM
  4. [SOLVED] Bouncing ball with polar coordinates
    By Ypsilon IV in forum New To Java
    Replies: 4
    Last Post: 04-22-2009, 12:19 AM
  5. Replies: 0
    Last Post: 04-16-2008, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •