Mapping a circle to linear

289 views
Skip to first unread message

Luis Argerich

unread,
Feb 6, 2012, 4:03:05 PM2/6/12
to mat...@googlegroups.com
Hi Mathmappers,

Sorry to drop into the group with a question. Hope you it's not offensive.

I have a photo of the full moon in very large resolution that I took with a telescope and I would like to know if there's a way to present it in a different way.
What I would like to do is to map the border of the circle (moon) to a straight line to show the peaks, craters and mountains the lunar edge as a panoramic image.

In other words convert the perimeter of a cicle into a straight line.

Is this possible using Mathmap? How? 

I do have mathmap installed I'm just not good figuring out how to use it for this.

I appreciate your time answering my question.

Luis

Edgar Bonet

unread,
Feb 7, 2012, 4:28:08 AM2/7/12
to mat...@googlegroups.com
Hello!

On 06 Feb 2012, Luis Argerich wrote:
> I have a photo of the full moon in very large resolution that I took with a
> telescope and I would like to know if there's a way to present it in a
> different way.
> What I would like to do is to map the border of the circle (moon) to a straight
> line to show the peaks, craters and mountains the lunar edge as a panoramic image.
>

> In other words convert the perimeter of a circle into a straight line.

One of the easiest ways to map a circle into a straight line is to use
the complex logarithm. This function maps the unit circle into the line
x = 0. If you then multiply by i, you get an horizontal line (y = 0)
instead, with the inside of the moon below (y < O) and the sky above. A
benefit of the logarithm over other possible mappings is that it is a
conformal transformation, which means that the shapes of small objects
(craters...) are preserved. Conformality is good if you want remapped
images to look somewhat natural.

Now, since you have to write the mapping backwards, from the output
image pixel coordinates to the input image coordinates, you need to
write the reverse mapping, something like:

input_coords = exp(-i * output_coords)

with the proper scaling of both input and output coordinates to fit the
useful range of the images. For scaling the output, you have to choose
how much of the moon border you want to see in the image width. 2*pi is
the full border, but you may want to map slightly more than this, in
order to have some overlap and make sure that a crater that is cut by
(say) the left border is visible in full on the right side. For scaling
the input coordinates, you just need the moon edge to be mapped to the
unit circle.

I let you do the coding as an exercise (actually, I don't have MathMap
available nor the time to code right now). It should not be too
difficult, as MathMap knows about complex numbers, and it's exp()
function works as expected on complex arguments.

Regards,

Edgar.

Luis Argerich

unread,
Feb 9, 2012, 3:17:36 PM2/9/12
to mat...@googlegroups.com
Edgar,

Thanks a lot for your answer!

Unfortunately I can't write the code, I just don't know how to do it. My knowledge of mathmap is too basic

function circle_to_line(image in) 

end

And how to code the transformation inside? 
I appreciate the help!

Luis

Tom Rathborne

unread,
Feb 10, 2012, 4:07:08 AM2/10/12
to mat...@googlegroups.com
Hi Luis,

Send me a link to a low-res version of your image and I'll take a
crack at it for you.

Regards,

Tom

--
-- Tom Rathborne ----------------------------- Independent Science Architect --
The real voyage of discovery consists not in seeking new lands,
but in seeing with new eyes.
-- Marcel Proust

Edgar Bonet

unread,
Feb 10, 2012, 2:47:41 PM2/10/12
to mat...@googlegroups.com
On 09 Feb 2012, Luis Argerich wrote:
> function circle_to_line(image in)
>
> end

It's almost that, except that it's “filter” instead of “function”. ;-)

I don't know whether Tom sent you some script or not, but here is my
try
at it:

*** The script:

filter moon2panorama(
image in,
bool center_help (0),
float center_x: -20-20 (0),
float center_y: -20-20 (0),
float span: 270-450 (360),
float shift_x: -200-200 (0),
float shift_y: -200-200 (0)
)
scaled = ri:[x, y/(1+9*center_help)]/W*span;
shifted = (scaled - ri:[shift_x, shift_y])*pi/180;
remapped = I*exp(-I*shifted);
centered = (remapped*0.8+ri:[center_x, center_y]/100)*min(X, Y);
if center_help && abs(y/Y) < 0.01 then
rgbColor(1, 1, 0)
else
in(xy:[centered[0], centered[1]])
end
end

*** The manual:

1.- Horizontally resize the canvas to make room for the panoramic view

- menu: Image / Canvas Size...
- disconnect Width from Height (small chain)
- set a comfortable width, around 3.5 times the Moon's diameter
- click on Center, then Resize

Ideally, I would like the Moon's perimeter to be rendered at the
same resolution as in the original image. Then I would set the
canvas width to pi*moon_diameter_in_px*span/360, where span is the
horizontal span (in degrees) of the panorama you want to make. You
probably want to have a span of more than 360 deg in order to get
some overlap of the ends.

2.- Resize the working layer to the canvas size

- first make sure the selected background color in the toolbox is
black
- menu: Layer / Layer to Image Size

3.- Load the above code in MathMap

- menu: Filters / Generic / MathMap / MathMap
- paste the code into the Expression tab
- click on the Preview button
- click on the User Values tab to bring up the controls

4.- If the horizon is wavy, fix it with the center_* controls

- vertically center the horizon with the shift_y control
- check center_help: this will amplify the vertical variations
and give you a reference horizontal line
- use center_x and center_y to remove the waviness
- uncheck center_help when done

This waviness comes from the fact that the Moon was not perfectly
centered in the original image. If it was centered, then you don't
need this step. You will get a more accurate (but slower)
correction
if you uncheck Fast Preview in the Settings tab. If some residual
waviness persists, it's probably due to the Moon not being
perfectly
round (or perfectly full).

5.- Tune to taste

- the span slider controls how much of the Moon perimeter you will
have in the panorama, in degrees.
- shift_x controls what is in the center of the panorama. By
default
(when set to 0 degrees) it will be whatever was at the top of the
original image.
- shift_y controls the ratio of land/sky in the image. Beware that
only the area close to the limb will be rendered with adequate
resolution, features far from the limb have to be upscaled and
will show degraded resolution.

6.- Click on OK, crop as needed and enjoy

Hope this helps you get a nice panorama,

Edgar.

Luis Argerich

unread,
Feb 10, 2012, 3:38:40 PM2/10/12
to mat...@googlegroups.com
Tom thanks a lot! With Edgar's code I think we got it :) Thanks a lot for your offer to help too.

Tttttthank you Edgar!

I tried it with a NASA image and it certainly worked. Now I need to figure out what is the best moon phase to show some mountains and craters near the borders even if that means producing a less than 360 panorama. 

Edgar, some last questions:

1) Can I distribute your code to other photographers/astronomers that might be interested?
2) Can I have your full name to credit you if I put a photo somewhere with this used? (If you don't want just let me know)

Thanks a lot once again!

Edgar Bonet

unread,
Feb 10, 2012, 4:02:51 PM2/10/12
to mat...@googlegroups.com
Luis Argerich just wrote:
> 1) Can I distribute your code to other photographers/astronomers that
> might be interested?

Yes, sure!

> 2) Can I have your full name to credit you if I put a photo somewhere
> with this used? (If you don't want just let me know)

Edgar Bonet. You may link to edgar-bonet.org, but you don't need to.

Regards,

Edgar.

photo...@gmail.com

unread,
Feb 11, 2012, 3:02:23 PM2/11/12
to MathMap
thank for the handy filter and for the clear instructions
I may include in my next repack of MM for Windows
last is on
https://downloads.sourceforge.net/project/gimp-packagers/MathMap-Zip-Install%281%29.zip?r=&ts=1328990442&use_mirror=freefr
PS i still hope for a 64 bit build but no luck yet !

Nate C.

unread,
Jun 28, 2012, 8:39:09 PM6/28/12
to mat...@googlegroups.com
Edgar,

This piece of code is brilliant. I am looking for a filter that is similar in the goal of the moon filter, but in fact something simpler - all I need is a basic complex logarithmic transform. (Stage 1 of this: http://www.josleys.com/article_show.php?id=82). I am brand new to MM and its coding language and I am having a lot of trouble trying to make this happen.

I have images of cross sections of a tube with attachments on the outside of it, I'm looking this filter to make the tube cross-section appear linear with the decorations perpendicular to it; preferably without the large circular distortions of this moon filter. 

Please advise. 

Many thanks,
Nathaniel

ps. I'm working in MM_cocoa 



Edgar Bonet

unread,
Jun 29, 2012, 5:16:57 AM6/29/12
to mat...@googlegroups.com
Hello!

On 2012-06-29, Nate C. wrote:
> This piece of code is brilliant. I am looking for a filter that is similar in
> the goal of the moon filter, but in fact something simpler - all I need is a
> basic complex logarithmic transform. (Stage 1 of
> this: http://www.josleys.com/article_show.php?id=82). [...]

Well, my code does exactly that: a simple logarithmic mapping. Cannot be
simpler. The complications and sliders are only for shifting and
scaling, in order to correctly position the original image in the
complex plane, and then the complex plane back into the image canvas. If
your tubes happen to be perfectly centered in your original images, then
you can forget about the center_* controls and only use span and shift_*
for zooming and panning the resulting image. If the tube edge appears
wavy, that's because it was not perfectly centered in the first place,
then you need the center_* controls to fix this.

> I have images of cross sections of a tube with attachments on the outside of
> it, I'm looking this filter to make the tube cross-section appear linear with
> the decorations perpendicular to it; preferably without the large circular
> distortions of this moon filter.

What do you mean by "large circular distortions"? Distortion is
unavoidable if you want to map a circle into a straight line, simply
because a straight line is a *very* distorted circle. Any such mapping
will therefore have a large distortion of scale, with the inside of the
circle scaled up and the outside scaled down. Compared to other possible
mappings, the benefit of the complex logarithm is it's conformality:
angles and small shapes are preserved, thus at least you avoid local
distortions.

> Please advise.

I would advise that, after applying the filter, you crop and only keep a
narrow horizontal band (like a panorama) around the tube edge. This way
you avoid the most extreme scale distortions. Assuming the attachments
on the tube edge are small enough...

Regards,

Edgar.

Nathaniel Wood-Cohan

unread,
Jun 29, 2012, 3:12:37 PM6/29/12
to mat...@googlegroups.com
Thank you very much for your timely response. I now see how my idea of a distortion free transformation is pure fantasy. This filter accomplishes my goal, although I do need to refine my input images a bit.

What changes would have to be made to the filter to do the inverse transform (complex exponential). Change the exp(-l*shifted) to e^ ? I am unsure of the notation needed.

Many thanks,
Nate





--
You received this message because you are subscribed to the Google Groups "MathMap" group.
To post to this group, send email to mat...@googlegroups.com.
To unsubscribe from this group, send email to mathmap+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mathmap?hl=en.


Edgar Bonet

unread,
Jun 29, 2012, 4:00:05 PM6/29/12
to mat...@googlegroups.com
Hi again!

On 29.06.2012, Nathaniel Wood-Cohan wrote:
> What changes would have to be made to the filter to do the inverse
> transform (complex exponential). Change the exp(-l*shifted) to e^ ? I
> am unsure of the notation needed.

No, you should use the log() function. Mapping scripts work backwards:
they have to compute the pixel coordinates in the original image as a
function of the coordinates in the transformed image. This has been
explained several times on the list, and the reason should be obvious
when you think of your filter as a function that computes pixel values
as a function of pixel coordinates.

You may need to add some code to properly map the original image to the
complex plane, and then back to the image canvas: you may need to zoom
(multiply by a real), pan (add a complex) or rotate (multiply by an
imaginary). And beware of the branch cut of the logarithm!

Edgar.
Reply all
Reply to author
Forward
0 new messages