Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Image Distort Question

573 views
Skip to first unread message

Charlie

unread,
Nov 14, 2005, 6:16:38 PM11/14/05
to
Hi,

I'm trying to change the shape of an image, my problem is this :

I want to print on my CDs (printable CDs, Epson Printer)
I have a load of square album images
I would love to be able to distort the square image to a circlular
image so it will fit on a CD
I know it's going to squash/distort it but I thought it would be a cool
look for my backup CDs of stuff I've purchased from iTunes. (using Gimp
on a Mac if that makes a difference)

Thanks
Charlie

Animesh Kumar

unread,
Nov 14, 2005, 7:28:03 PM11/14/05
to
Charlie wrote:

Filter - > Map -> Object; with options "sphere" and "transparent
background" and "new image window"

Spamless

unread,
Nov 15, 2005, 12:56:06 AM11/15/05
to

I don't know what plugins you may have. There is always Curve_Bend
(I am using gimp 2.2.9, Linux, with perlGimp2.0 installed) (you will have
to play around with it) (in my setup Filters->Distorts->Curve_Bend) (if
the layer grows larger than the canvas, use IMAGE->Fit_Canvas_to_Layers).

You might also want to try (for a different effect) the Polar_Coords filter
(Filters->Distorts->Polar Coords) (just trying it ... I see that the text
went from left to right to right to left - flipping the image horizontally
fixed that).

If you have installed mathmap (you would have to download and instal it) you
can also try its Inverse Lambert Azimuthal projection unless you prefer its
Radial Eversion or Sphere (part of the imae will be on the back - you can
add blank stuff around the image ...) (those under mathmap's DISTORTS
section) or (under its MAP) Sphere or Sphere_with_Reflection. With MathMap
you can enter your own equation for distortion. I would have to check to see
where the base is (upper left for rectangular coordinates? Center for
polar?) and you could also map the center out (so that the hole in the CD
does not cover up too much).

Spamless

unread,
Nov 15, 2005, 1:11:09 AM11/15/05
to
On 2005-11-15, Spamless <Spam...@Nil.nil> wrote:
> On 2005-11-14, Charlie <spla...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to change the shape of an image, my problem is this :
>>
>> I want to print on my CDs (printable CDs, Epson Printer)
>> I have a load of square album images
>> I would love to be able to distort the square image to a circlular
>> image so it will fit on a CD
>> I know it's going to squash/distort it but I thought it would be a cool
>> look for my backup CDs of stuff I've purchased from iTunes. (using Gimp
>> on a Mac if that makes a difference)

And ... how squashed? Drawing a circle centered on the image whose edges
just reach the edge of the image (an inscribed circle) do you want to pull
the parts above the circle down (and below up)? Curve bend can do that.
The parts to the left and right in (rotate 90 degrees, curve bend and
rotate back). Pull them in to the center? With rectangular coords with
origin at the center, try scaling the x and y coordinates by
MAX(|x|,|y|)/SQRT(x^2 + y*2). A perl script or mathmap would, I think
be the tool for that.

Spamless

unread,
Nov 20, 2005, 9:41:42 AM11/20/05
to
On 2005-11-15, Spamless <Spam...@Nil.nil> wrote:
> On 2005-11-14, Charlie <spla...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to change the shape of an image, my problem is this :
>>
>> I want to print on my CDs (printable CDs, Epson Printer)
>> I have a load of square album images
>> I would love to be able to distort the square image to a circlular
>> image so it will fit on a CD
>> I know it's going to squash/distort it but I thought it would be a cool
>> look for my backup CDs of stuff I've purchased from iTunes. (using Gimp
>
> If you have installed mathmap (you would have to download and instal it) you
> can also try its Inverse Lambert Azimuthal projection unless you prefer its
> Radial Eversion or Sphere (part of the imae will be on the back - you can
> add blank stuff around the image ...) (those under mathmap's DISTORTS
> section) or (under its MAP) Sphere or Sphere_with_Reflection. With MathMap
> you can enter your own equation for distortion. I would have to check to see
> where the base is (upper left for rectangular coordinates? Center for
> polar?) and you could also map the center out (so that the hole in the CD
> does not cover up too much).

Hmmm ... I, too, decided to play around with putting an album image on a CD
label and wanted to warp it to a circular shape.

I am using mathmap-1.0.1 with Gimp 2.2.9.

In mathmap one can choose the MATHMAP and EXAMPLES section and there alter
the code. I did not see a way of saving the changed code, but one can edit
the mathmaprc file in one's ~/.gimp directory.

The following are just my tests, they are designed for a SQUARE image (crop
or scale first) (most albums covers are almost square so this should not
cause much of a problem) WITH an alpha channel.

What should be near the center hub of the label? The center of the album
cover image? In that case, probably the best is to use a conformal map of a
unit disk to a square using, say, the usual Schwarz-Christoffel
transformation (the complex variable z in the unit disk is mapped to the
variable w in a square with w=INTEGRAL(dz/SQRT(1-z^4)). I will pass on that
(for the moment, anyway) since it involves programming elliptic integrals
using complex numbers.

A simpler method is just to scale each direction to pull things in to the
circle. That is what the first method does. Unfortunately, this leads to
"kinks" at forty-five degree angles.


The next few do things differently. They wrap the cover image (SQUARE with
ALPHA) around the circular label with the bottom of the cover image towards
the center. This has the obvious problem that when one gets around the left
edge abuts the right edge along some line.

The second formula is a conformal mapping for that. The text appears nice
but, like a Mercator (conformal) projection where the Northern lattitudes
are exaggerated, in this case the top of the image takes up most of the
disk.

The third formula is an equal area mapping (like a Cylindrical projection
map). Like a world map using a cylindrical projection, the northern regions
(top of the image) appear to be squashed radially while being stretched out
around the disk (they take up some area, but due to the stretching around
the disk).

The fourth formula uses a simple linear exponent and the fifth lets you
choose the exponent for the radial mapping. A value somewhere between .5 and
1.5 seems to do pretty well (depending on the cover art). The USER VALUES
tab in mathmap will give a slider to set the value.


The last two, like the first, have the center of the image at the center of
the label. They don't pull the corners in radially but pull down from the
top and up from the bottom (the first routine) and left from the right and
right from the left edge (the second routine) to provide a circular image.
That last, the horizontal scaling, keep lines of text horizontal and looks
more like a Christmas ornament, I think.


# Some mathmap 1.0.1 routines to turn a SQUARE (image/layer) WITH TRANSPARENCY
# into a circular disk with transparency outside the disk.

# Pull in corners
lin=max(abs(x),abs(y));
if (lin == 0 ) then lin=1 end;
if (r <= X) then origVal(xy*r/lin) else rgba:[0,0,0,0] end

# Conformal (bottom at center)
c=X/pi; A=exp(Y/c)/Y;
if (r <= Y) then origVal(xy:[(-c*a+X),c*log(A*r)]) else rgba:[0,0,0,0] end

# Equal area (bottom at center)
z=user_float("zoom",1,10);
c=X/pi; A = 2/Y;
if (r<=Y) then origVal(xy:[-c*a+X,-Y+z*A*r*r]) else rgba:[0,0,0,0] end

# Another choice.
c=X/pi; A = 2;
if (r<=Y) then origVal(xy:[-c*a+X,-Y+A*r]) else rgba:[0,0,0,0] end

# General
theexp=user_float("exponent",.25,4);
c=X/pi; A = 2*Y^(1-theexp);
if (r<=Y) then origVal(xy:[-c*a+X,-Y+A*r^theexp]) else rgba:[0,0,0,0] end

# Adjust vertically
s=sqrt(X^2-x^2)/X; if (s == 0) then s=1 end;
if (r<=Y) then origVal(xy:[x,y/s]) else rgba:[0,0,0,0] end

# Adjust horizontally
s=sqrt(Y^2-y^2)/Y; if (s == 0) then s=1 end;
if (r<=Y) then origVal(xy:[x/s,y]) else rgba:[0,0,0,0] end

Spamless

unread,
Nov 21, 2005, 2:48:27 PM11/21/05
to
On 2005-11-20, Spamless <Spam...@Nil.nil> wrote:

> What should be near the center hub of the label? The center of the album
> cover image? In that case, probably the best is to use a conformal map of a
> unit disk to a square using, say, the usual Schwarz-Christoffel
> transformation (the complex variable z in the unit disk is mapped to the
> variable w in a square with w=INTEGRAL(dz/SQRT(1-z^4)). I will pass on that
> (for the moment, anyway) since it involves programming elliptic integrals
> using complex numbers.

Ah, heck. Why not be complete? It is only an (elliptic) integral using
complex numbers!

Here is a map from a square (scale or crop first) with alpha channel to a
circular disk which is conformal (it uses the Schwarz-Christoffel
transformation - a point, z, in the unit disk is mapped to a point, w, in a
square via:
w = INTEGRAL[dt/sqrt(1-t^4): from 0 to z]
where z and w are complex numbers).

The integral is an elliptic integral (with complex numbers). I simply used a
power series approximation. The resulting square does not have horizontal
edges and it has a particular size. The code, below, has two rotations and
scalings (the constant V is related to the size of the square produced by
the transformation) to transform a square to circle without having things
rotated around.

This is a conformal map (preserves angles, shapes). In particular,
horizontal text reaches out perpendicularly to the sides of the original
square. That angle is 90 degrees. The resulting image will have text going
towards the edge of the disk approaching it perpendicularly (it will curve
towards the edge of the disk) so its horizontal nature is not preserved
(scaling horizontally may look a bit better ... and there are several other
transformations in the Gimp which will map an image to a cicular disk).

How many terms does the approximation (series) to the integral require?
About (less than) 25-30. The code here has a slider (it will appear as a
USER_VALUE in mathmap). Things may not look very good first you try it,
where the number of terms is only five. Slide it up to smooth out the edges
of the circle. You may want to hard-code the "count" value to 25 or 30
(instead of using the slider to see how the approximation effects the
results).


# Conformal map. SQUARE image with transparency to a circular
# disk using the standard Schwarz-Christoffel transformation.
# Mathmap 1.0.1 - Gimp 2.2.9

count=user_int("number of terms",5,100);
V=.92705;

if (r < X) then
rect=toXY(ra:[r,a-pi/4]);
z=(ri:[rect[0],rect[1]])/X;
term=z;w=term;n=0;
z4=z*z*z*z;
while (n < count)
do
term=z4*term*(2*n+1)/2/(n+1);w=w+term/(4*n+5);n=n+1;
end;
polar=toRA(xy:[w[0],w[1]]);
origVal(ra:[polar[0]*X/V,polar[1]+pi/4]);

else
rgba:[0,0,0,0];

end

Spamless

unread,
Nov 22, 2005, 1:02:00 PM11/22/05
to

Nice ... but ... a bit of a problem.

This maps the image to a sphere and you see half the sphere (half the
original image). One can duplicate the image (create a 2x1 rectangle with a
copy of the image next to the original). The result will have the center of
the combined image (the place where the original and the copy abut) at the
center. Setting the Y angle (orientation) to 90 degrees moves the original
image to the visible hemisphere. Applying the filter (for the 2x1 rectangle)
will (at least for me, gimp 2.2.9, Linux) result in an ellipse (one will
have to shorten the horizontal to get a circle) which contains, not all, but
most of the original image. This Map_Object filter is a three dimensional
view of the sphere, i.e. it views the sphere from some distance (the Z
coordinate of the position setting is the position of the sphere and you are
at a fixed postion - if z is large/positive, the sphere moves closer to you
and if z is large and negative, the sphere is further away) and the closer
you are (the larger the z coordinate) the more of the original image will be
beyond the horizon (is not part of the circular disk you get). The most
negative you can make that z value is -1 (and a bit of the original image
will be missing from the disk you get). Mathmap has a similar plugin but
that version uses a parallel projection (i.e. views the sphere from a great
distance so that one sees the full hemisphere with the circular version of
the original image). That is not so "realistic" as viewing from a real
(close in) position but you get the entire hemisphere (the entire original
image is distorted to fit the disk you get).

Spamless

unread,
Nov 22, 2005, 1:08:54 PM11/22/05
to
On 2005-11-21, Spamless <Spam...@Nil.nil> wrote:
> On 2005-11-20, Spamless <Spam...@Nil.nil> wrote:
>
>> What should be near the center hub of the label? The center of the album
>> cover image? In that case, probably the best is to use a conformal map of a
>> unit disk to a square using, say, the usual Schwarz-Christoffel
>> transformation (the complex variable z in the unit disk is mapped to the
>> variable w in a square with w=INTEGRAL(dz/SQRT(1-z^4)). I will pass on that
>> (for the moment, anyway) since it involves programming elliptic integrals
>> using complex numbers.
>
> Ah, heck. Why not be complete?

and one more (the last!) similar to the Filters->Map->Map_Object filter in
gimp (but showing the full hemisphere and with the image mapped to that
hemisphere, not to the sphere, so you see it all - if mapped to the sphere,
you would only see the half mapped onto the visible hemisphere).

(and some info on mathmap).


Suppose we consider the horizontal position coordinates as the longitude on
a hemisphere and the vertical position the latitude on the hemisphere and
back off and look at the hemisphere (which appears as a circle). This gives
a map from the interior of the square (SQUARE image with RGB_ALPHA_, with
transparency/alpha_channel) to a circle which we can use as the
transformation.

As constant latitude (vertical position) appears along a straight line when
looking at the sphere, horizontal text remains horizontal (text along the
top of the rectangle does not bend to follow the curve of the circle but is
squashed in to "fit" the smaller region) as in the code I posted which just
pulls in the sides from the left and right. This is similar in that prior
code, the horizontal middle of the square was not effected while in this
case it is wrapped around the middle of the sphere (half way - hemisphere)
so its edges (when looked at from afar) appear to be compressed.

Mathmap has a more general spherical mapping under:
Filters->Generic->Mathmap->Map->Sphere
which maps an image to a hemisphere (by mapping to a sphere twice, it
repeats the image to get the back of the sphere) and allows one to rotate
the sphere (the angles on the "user values" tab) however, for some reason,
its mapping results in a change of orientation (reflection) and text is
reversed (flipping the image horizontally, choosing values for the paramters
available of alpha=0,beta=1.57,gamma=0 - 1.57 being 90_degrees in radians to
look at the side of the sphere instead of its top) and using the "back"
(background) user value to choose a color which is transparent - move the
alpha value down to zero to give the backgroud zero opacity) gives the same
result as this code (below). That code allows you to rotate the sphere.

Mathmap also has a Sphere_With_Reflection which maps the image onto the
sphere, not hemisphere, so one only sees half the original image when
looking at the hemisphere (hint: make a 2x1 rectangle by putting two copies
of your original image side by side - the plugin built into mathmap does not
expect/require a square image). The "Reflection" refers to a
highlight/reflection one can add using a light source (position set on "user
values").
(This is similar to the Filters->Map->Map_Object and choosing to map to a
sphere with a transparent background and turning off the extra lighting.
You get the image on a sphere, not hemisphere, so you only see half the
image. If you duplicate the image, creating a 2x1 rectangle, map to the
sphere, the center is at the center of the 2x1 rectangle you created,
where the two images abut, not the center of the original image. Setting
the (Orientation tab) Y rotation to 90 (degrees) brings the original image
to the front and you have a circle with ... almost the full original
image. Not quite. The difference is that while the mathmap sphere filters
and the mathmap code below map to a hemisphere, they then view the
hemisphere with a parallel projection - moving far away so that the whole
hemisphere is visible while the Filters->Map->Map_Object filter views the
final sphere from close up where the "horizon" blocks out part of the view
of the hemisphere. You can get more of the original into the circle by
setting the Z value of the "position" to -1 (the most negative one can
make it). However, that also reduces the size of the resulting image
lowering the resolution of the final print. Also, for a 2x1 rectangle, the
result will be an ellipse and one will have to scale back the horizontal
size to get a circle.)


There is another Sphere transformation under
Filters->Generic->Mathmap->Distorts->Sphere
("distorts" instead of "map") where one can scale the original image so part
of it covers the whole (hemi)sphere (the rest moves around the back) or the
entire image does not quite cover it (the rest of the "circle" one sees has
no image).

[Oh ... mathmap's home page is at http://www.complang.tuwien.ac.at/schani/
When installed you will find it under Filters->Generic->Mathmap
There are several items one can choose for different effects.
Choosing one will show some tabs. On the Settings tab set "Auto Preview"
immediately (interactively) to see the effects of making changes to
user values available under the "User Values" tab.
Below the premade effects there is an entry for "Mathmap" itself.
Clicking that will provide a window with four tabs (settings and
"user values" of course and one where you can view the code of the
premade filters, "examples", and also a tab for "Expression".
Clicking the "Expression" tab will result in a text area where you
can enter any mathmap code. You can cut and paste, for example, the
code for the spherical mapping, below. Press the Preview button.
If the code has a user value one can change, click on the "User Values"
tab and use the sliders to see the effect and when it is "right"
click OK to modify the image.
I do not see a "load" or "save" option on the "expressions" tab.
One is not forced only to cut and paste code for one could add
code to the ~/.gimp-[version]/mathmap/mathmaprc file.]

(Now, let's see ... if one uses an inverse mercator projection or spherical
projection to map a square onto (almost all of) a hemisphere and does not
look at the hemisphere directly - a parallel projection as used in the code
below - but uses a stereographic projection of the hemisphere onto a circle
or perhaps a point projection from a different height rather than worrying
about the conformality provided by the stereographic projection - or uses
a user defined map for the radial distance instead of a projection - I wonder
how that would look instead ...
Perhaps also mapping not to a circular disk but to an annulus with a
selectable inner circle which is missed so that one does not lose material
for the hole in the center of a CD label whose size will depend on whether
one is using regular labels or "full face" labels ...)

There are tons of ways of converting to a circular disk - if these aren't
quite what you want ...


Here is the mathmap code to convert a square image (crop/scale first) to a
circle treating its rectangular coordinates as spherical coordinates for a
hemisphere (the resulting image looks "rounder" - more three dimensional -
than maps to a "flat" circle).

# Spherical
# Treat coordinates as longitude and latitude of a hemi-sphere
# and look in on the hemi-sphere.

if (r < X) then
v=asin(y/Y)*2*Y/pi;u=asin(x/X/cos(v*pi/2/Y))*2*X/pi;
origVal(xy:[u,v])
else
rgba:[0,0,0,0]
end

Spamless

unread,
Nov 22, 2005, 2:02:07 PM11/22/05
to
# Some mathmap 1.0.1 routines to turn a SQUARE (image/layer)
# WITH TRANSPARENCY into a circle.

# Types:
# ------
# 1: Simple scaling
# Pull in corners
# Pull in sides
# Pull in top/bottom
# 2: Polar coordinate type (top along circle, bottom at center)
# Polar coordinates (linear scale - vertical coord <-> radius)
# Polar coordinates: Equal area (quadratic)
# Polar coordinates: General power map ("user variable")
# Polar coordinates: Conformal (exponential)
# 3: Conformal (Schwarz-Christoffel transformation)
# 4: Spherical coordinates


# 1: Simple scaling
# ========================================================
# ========================================================

# Pull in corners
# ============ CODE ======================================


lin=max(abs(x),abs(y));
if (lin == 0 ) then lin=1 end;
if (r <= X) then origVal(xy*r/lin) else rgba:[0,0,0,0] end

# ========================================================

# Pull in sides
# ============ CODE ======================================


s=sqrt(Y^2-y^2)/Y; if (s == 0) then s=1 end;

if (r<=Y) then origVal(xy:[x/s,y]) else rgba:[0,0,0,0] end
# ========================================================

# Pull in top/bottom
# ============ CODE ======================================


s=sqrt(X^2-x^2)/X; if (s == 0) then s=1 end;

if (r<=Y) then origVal(xy:[x,y/s]) else rgba:[0,0,0,0] end
# ========================================================
# ========================================================


# 2: Polar coordinate type (top along circle, bottom at center)
# =============================================================
# =============================================================

# Polar Coordinates (linear scale - vertical coord <-> radius)
# ============ CODE ======================================
c=X/pi; A = 2;
if (r<=Y) then origVal(xy:[-c*a+X,-Y+A*r]) else rgba:[0,0,0,0] end
# ========================================================

# Polar coordinates: Equal area (quadratic)
# ============ CODE ======================================
c=X/pi; A = 2/Y;
if (r<=Y) then origVal(xy:[-c*a+X,-Y+A*r*r]) else rgba:[0,0,0,0] end
# ========================================================

# Polar coordinates: General power map ("user variable")
# ============ CODE ======================================


theexp=user_float("exponent",.25,4);
c=X/pi; A = 2*Y^(1-theexp);

if (r<=Y) then origVal(xy:[-c*a+X,-Y+A*r^theexp]) else rgba:[0,0,0,0] end
# ========================================================

# Polar coordinates: Conformal (exponential)
# ============ CODE ======================================
c=X/pi; A=exp(Y/c)/Y;
if (r <= Y) then origVal(xy:[(-c*a+X),c*log(A*r)]) else rgba:[0,0,0,0] end
# ========================================================
# ========================================================


# 3: Conformal (Schwarz-Christoffel transformation)
# Maps the interior of a unit circle with position
# z, a complex number, to a position in a square
# with position given by the complex number w
# by w = INTEGRAL(dt/sqrt(1-t^4): t=0 to z).
# The resulting square has size given by an integral
# and does not have horizontal and vertical sides
# so we need some rotating and scaling.
# Increase count to see the effect of more terms
# in the series expansion of the integral.
# ============ CODE ======================================


count=user_int("number of terms",5,100);
V=.92705;
if (r < X) then
rect=toXY(ra:[r,a-pi/4]);
z=(ri:[rect[0],rect[1]])/X;
term=z;w=term;n=0;
z4=z*z*z*z;
while (n < count)
do
term=z4*term*(2*n+1)/2/(n+1);w=w+term/(4*n+5);n=n+1;
end;
polar=toRA(xy:[w[0],w[1]]);

origVal(ra:[polar[0]*X/V,polar[1]+pi/4]);
else
rgba:[0,0,0,0];
end
# ========================================================
# ========================================================


# 4: Spherical coordinates


# Treat coordinates as longitude and latitude of a

# hemisphere and look at the hemisphere from afar.
# ============ CODE ======================================


if (r < X) then
v=asin(y/Y)*2*Y/pi;u=asin(x/X/cos(v*pi/2/Y))*2*X/pi;
origVal(xy:[u,v])
else
rgba:[0,0,0,0]
end

# ========================================================
# ========================================================

Animesh Kumar

unread,
Nov 22, 2005, 6:55:58 PM11/22/05
to
Spamless wrote:

> On 2005-11-15, Animesh Kumar <anime...@gmail.com> wrote:
>
>>Charlie wrote:
>>
>>
>>>Hi,
>>>
>>>I'm trying to change the shape of an image, my problem is this :
>>>
>>>I want to print on my CDs (printable CDs, Epson Printer)
>>>I have a load of square album images
>>>I would love to be able to distort the square image to a circlular
>>>image so it will fit on a CD
>>>I know it's going to squash/distort it but I thought it would be a cool
>>>look for my backup CDs of stuff I've purchased from iTunes. (using Gimp
>>>on a Mac if that makes a difference)
>>>
>>>Thanks
>>>Charlie
>>>
>>
>>Filter - > Map -> Object; with options "sphere" and "transparent
>>background" and "new image window"
>
>
> Nice ... but ... a bit of a problem.
>

What you suggested may work. Here is an easier method (to alleviate
centering etc). The tradeoff is -- some edge portion from the main image
is lost.

* Start with a square image, say 500 by 500 for example.
* Use crop-image. Set Origin X = -250 px, Origin Y = 0; width = 1000,
height = 500 (untouched).
* Crop and scale layer to image size.
* Do the Sphere map as I told before.
* Scale one axis by a factor of 2 to convert the ellipse to a circle.
(select cubic if you are enlarging).

You can see the square and circle image I get.

Before: www.eecs.berkeley.edu/~animesh/square.png

After: www.eecs.berkeley.edu/~animesh/label.png

Best regards,
Animesh

<snip>

Spamless

unread,
Nov 23, 2005, 12:38:45 AM11/23/05
to
On 2005-11-22, Animesh Kumar <anime...@gmail.com> wrote:
>
> What you suggested may work. Here is an easier method (to alleviate
> centering etc). The tradeoff is -- some edge portion from the main image
> is lost.

Yes - mapping to the hemisphere and using a "realistic" 3D view from a
somewhat nearby point loses part of the edges behind the horizon. The
mathmap sphere plugins view the sphere from "infinitely" far away to get the
whole hemisphere. Setting the position z value to the most negative possible
value (unfortunately that is only -1) gets as much of the image as this
plugin will provide.

> * Start with a square image, say 500 by 500 for example.
> * Use crop-image. Set Origin X = -250 px, Origin Y = 0; width = 1000,
> height = 500 (untouched).
> * Crop and scale layer to image size.

Yes - half the canvas/image contains the original, scaled, so when the
Filters->Map->Map_Object plugin is used, the original image only covers
a hemisphere and you have centered it so one does not have to rotate the
sphere to bring it to the front.

> * Do the Sphere map as I told before.
> * Scale one axis by a factor of 2 to convert the ellipse to a circle.
> (select cubic if you are enlarging).
>
> You can see the square and circle image I get.

North and south poles squashed in (like the simple scaling, pull in the
sides which is flat while this looks more three dimensional - often I
prefer the "flat" version). How about the east and west poles(!) squashed
in! Instead of something like taking an image and wrapping it around the
sphere (a vertical cylinder) and then squashing in the top and bottom (the
north and south poles), wrap the image around the sphere as a horizontal
cylinder and squash in the east and west poles! One could do it with a 90
rotation, sphere map and rotate back. Here is the code to do it directly
(it uses a spherical model with east and west poles instead of north and
south poles):

(Mathmap 1.0.1 code tested in gimp 2.2.9 for a square image with alpha
channel - map to a disk)

# Spherical Coordinates: Horizontal
# Treat coordinates as latitude and longitude.
# ============ CODE ======================================
if (r < Y) then
u=asin(x/X)*2*X/pi;v=asin(y/Y/cos(u*pi/2/X))*2*Y/pi;


origVal(xy:[u,v])
else
rgba:[0,0,0,0]
end

# ============ CODE ======================================


Oh ... and one more. The polar coordinate type maps vertical coordinates to
radial position and horizontal coordinates, linearly, to the angular
coordinate (scaled to 360 degrees). I had posted various functions for the
radial map - conformal, equal area, linear (plain "polar coordinates") and an
arbitrary power law. Mathmap lets you interactively define functions as a
curve (like the curves used in curve_bend) so here is code where one can
modify the curve however one likes. One can move the bottom left corner to
the right to map the entire square to an annulus (so none of it maps into
the inner disk which is cut out from the CD label). One can pull the left
corner to the top and to right to the bottom which maps with the top of the
image at the center and the bottom at the edge of the label (instead of the
top at the edge and bottom at the center) (that changes the orientation so
one would have to reflect the image, say flip horizontally, to get readable
text). If one has text across the image horizontally, using this code to map
it around the label, one can adjust the curve to emphasise that text (make
it larger and squash everything else!). Cute. One thing - making changes to
the curve does not immediately result in an updated preview; you have to hit
the preview button.

(Mathmap 1.0.1 code tested in gimp 2.2.9 for a square image with alpha
channel - map to a disk)

# Polar coordinates: General radial function ("user curve")
# ============ CODE =======================================
c=X/pi;
if (r<=Y) then origVal(xy:[-c*a+X,2*Y*user_curve("theshape",r/Y)-Y]) else rgba:[0,0,0,0] end
# =========================================================


> Before: www.eecs.berkeley.edu/~animesh/square.png
>
> After: www.eecs.berkeley.edu/~animesh/label.png

Yep ... A nice spherical map. Gimp does not come with too many maps of a
square to a disk. The spherical map and polar coordinates (just linear -
mapping the left and right edges to the center and edge of the disk)
apparently and a few others (for example the inverse Lambert Azimuthal in
mathmap, I believe). Mathmap has the spherical map (but viewed from afar to
see the entire hemisphere). Neither has the standard conformal map from the
disk to a square (Schwarz-Christoffel transformation) nor a "flat" version
of the spherical map (just pull in the sides or the top/bottom) nor a way to
modify the polar coordinate map.

Let me try my maps on your square.png image ...

Pull in the corners looks pretty strange (the kinks at 45 degrees)
Pull in the sides looks similar to the spherical map, but flatter.
Pull in top/bottom looks, I think just a bit better.

Polar coordinate formats are more for labels with text across it
(wrapped around the label) so I will skip those.

Conformal (Schwarz-Christoffel) looks quite good.

Spherical coordinates (the same as yours but showing the full hemishpere,
not missing edges due to the horizon) - well, like yours, but both look
"bulgy" in the middle.

Spherical coordinates (horizontal - with east and west poles) - that looks
pretty good. The face has a different proportion, but since it is a long
face to start with and this is similar to the "pull in top/bottom" code
it actually looks quite good. Due to the the "bulging" of the spherical map
the edges of the image are reduced and it emphasizes the face.

For this image, to keep it looking as close to the original as possible, I
think conformal (Schwarz Christoffel) and to get a more emphatic image the
horizontal spherical map (try rotating the image 90 degrees, using your
method, and rotating the circular disk back) would be what I would use.

I don't (currently) have a place where I could post these, but could send
you copies if you want to take a look at them (or you could just try
applying them to the square image if you have mathmap).
>
> Best regards,
> Animesh

Ditto ...
John.

Spamless

unread,
Nov 23, 2005, 1:44:51 AM11/23/05
to
On 2005-11-22, Spamless <Spam...@Nil.nil> wrote:
> # Some mathmap 1.0.1 routines to turn a SQUARE (image/layer)
> # WITH TRANSPARENCY into a circle.

Two more:

The new polar coordinate code allows the user interactively to modify the
map from the vertical coordinate to the radius (but one has to hit the
preview button to see the results) using a "user value" curve. One can move
the bottom left corner to the right to map to an annulus (none of the image
mapped into the center which will be cut out of a disk label). One can move
the bottom left corner to the top and the top right corner to the bottom to
have the top of the image at the center and the bottom at the edge of the
disk (this changes the orientation so one will have to flip the image,
horizontally say, to have readable text). If one has an image with
horizontal text and uses this to map around the disk, one can interactively
modify the result to emphasize just the text (reduce the size of stuff above
and below it)!

The new spherical code uses east and west poles instead of north and south.
The original is similar to the simple scaling, pull in sides. This is
similar to the simple scaling, pull in top/bottom (one could get this by
rotating 90 degrees, using a spherical map, and rotating back, but this
does it directly).

# 2: Polar coordinate type (top along circle, bottom at center)

# Polar coordinates: General radial function ("user curve") [new]
# 4: Spherical Coordinates
# Spherical Coordinates: Vertical [the original one]
# Spherical Coordinates: Horizontal [new: east and west poles!]

# Polar coordinates: General radial function ("user curve")
# ============ CODE =======================================
c=X/pi;

if (r<=Y) then origVal(xy:[-c*a+X,2*Y*user_curve("theshape",r/Y)-Y]) else rgba:[0,0,0,0] end
# =========================================================

# Spherical Coordinates: Horizontal
# Treat coordinates as latitude and longitude.

# ============ CODE ======================================
if (r < Y) then
u=asin(x/X)*2*X/pi;v=asin(y/Y/cos(u*pi/2/X))*2*Y/pi;


origVal(xy:[u,v])
else
rgba:[0,0,0,0]
end

# ============ CODE ======================================

Spamless

unread,
Nov 23, 2005, 5:01:22 AM11/23/05
to
On 2005-11-23, Spamless <Spam...@Nil.nil> wrote:
> On 2005-11-22, Spamless <Spam...@Nil.nil> wrote:
>> # Some mathmap 1.0.1 routines to turn a SQUARE (image/layer)
>> # WITH TRANSPARENCY into a circle.

This is almost perfect for some cases (square images to CD labels).
It is a polar type. This stretches the image round the circle.
The ability to modify the user_curve allows one to map to an annulus
and not put part of the image inside the hub, cut out in a CD label.
For some cover art, this is good. But one has to turn the disk around
to see the full cover art. Perhaps it would be better to put two
copies on the disk (not overwriting the hub), so one could look at the top
half of the disk and see a proper image. That might be stretched out too
much. Perhaps three copies ... or four (expanded less around the circle).

This is a modification of the polar coordinate map with a user modifiable
radial function including (now) the option (a "user value" slider) to set
the number of copies to be inserted around the edge of the disk.

The reason I say that this is "almost" perfect is that I haven't looked up
the ratio between the inner and outer radii of the bounding circles for CD
labels (standard and full face) or for printable CDs (are they full face?)
and hard coded that into the routine (with a user selectable value to choose
whether to design with the images going all the way into the center or only
in to a smaller circle - standard and full face labels being selectable) so
one would not have to make a manual adjustment of the curve to have the
copies of the cover descend only to the inner circle.


# 2: Polar coordinate type (top along circle, bottom at center)

# Polar coordinates: General radial function with repeat

# Polar coordinates: General radial function with repeat
# ============ CODE ====================================
c=user_int("number of copies",1,12)*X/pi;
if (r<=Y) then
origVal(xy:[-(c*a)%(2*X)+X,2*Y*user_curve("the shape",r/Y)-Y])

Spamless

unread,
Nov 23, 2005, 8:11:15 PM11/23/05
to
On 2005-11-23, Spamless <Spam...@Nil.nil> wrote:

> The reason I say that this is "almost" perfect is that I haven't looked up
> the ratio between the inner and outer radii of the bounding circles for CD
> labels (standard and full face)

I have now.

Here we go. Polar coordinate type. Multiple copies of the image placed
around the disk (between an outer and inner radius) with a user modifiable
function for mapping the radial data (changing the curve to a straight line
from the top left to bottom right will map with the top of the image at the
center, instead of edge, of the disk, for example - a result with the wrong
orientation so one will have to flip the image horizontally for readable
text). One selects the type of label (either a full disk, mapping in to the
center of the circle, "0"; a full face label with small inner disk to be
avoided, "1" or standard CD label with a large inner disk, "2").

I have seen the same CD brand list some different outer diameters for
standard CD labels (4.59", 4.5", 4.6", 4.625") with the same inner diameter
(1.6154") and seen full face labels listed with an inner radius of 18mm and
an outer radius of 117mm or 118mm. The code uses 18/118 as the ratio of the
diameters for full-face labels and 1.6/4.6 for standard labels and has a
slider one can use to adjust that (the default is to decrease the size of
the inner radius so as not to have any "white" paper on the final print, but
there is boolean input called "larger" one can use to change this to
increase the size of the inner circle). It will allow adjustments of the
inner circle's radius by up to 50% of that radius (smaller or larger)
in case you find that the size is not quite right (of course you could
just change the value in the "ratios" vector).

I have had some problems in the final results, sometimes very blocky,
sometimes some junk radial values, sometimes just poor. Often by making the
other settings, modifying the curve for the mapping (just pull the left
corner of the curve up, for example), hitting preview, then removing the
modification (pull the left end of the curve back), hitting preview and
using the code I get a good result - though sometimes I also have to turn on
supersampling (on the settings tab). Undoing a bad result and trying again
(perhaps "jiggling" things above) usually works. Sometimes the preview shows
nothing! Apparently when the current pixel position is no longer being drawn
to (when it was in the center and now one has decided to cut that out) it
might confuse things and the curve, instead of being linear from bottom left
to top right becomes just a horizontal line at the top (or bottom) (in which
case the top edge or the center is mapped to the whole image). Fixing the
curve and hitting preview should take care of that. Is it a result of the
discontinuous selections for the type of label (and the inner radius)?

While it gives a good (at least decent) result, you may have to "jiggle"
things (I came across another bug in mathmap where z4=z^4 works;
z2=z*z, z4=z2*z2 works; z4=z*z*z*z works, z4=z*z, z4=z4^2 works BUT
z4=z*z,z4=z4*z4 does NOT work - naturally I had started off using that last).

If the result is not quite good enough (or blocky or whatever) UNDO
and try jiggling things and changing some of the settings on the SETTINGS
tab (e.g. supersampling).


# Polar coordinates: CD labels: General radial function with repeat
# ============ CODE ===============================================
# Number of duplicate copies around the disk.


c=user_int("number of copies",1,12)*X/pi;

# Ratios for full disk (inner radius = 0), full face and standard.
ratios=[0,18/118,1.6/4.6];
# Choose a type of label - all the way to the center,
# Full face label or standard CD label.
inner=Y*ratios[user_int("label: 0=disk; 1=full face; 2=standard",0,2)];
# I have seen slightly different values for the inner radii so here
# is an adjustment for the inner radius with default to make it smaller
# but with adjustment amount set to zero.
# There is a boolean input to change this to increase the inner radius
# and a slider to adjust the size (by up to half the size listed in
# the "ratios" vector either making it smaller, the default, or larger).
inner=(1+(2*user_bool("larger")-1)*user_slider("inner radius adjust",0,.5))*inner;
# Create the image with duplicate images around the disk mapped to the
# annulus using a user defined radial function, "the shape."
if ((r<=Y) && (r>=inner)) then
origVal(xy:[-(c*a)%(2*X)+X,2*Y*user_curve("the shape",(r-inner)/(Y-inner))-Y])
else
rgba:[0,0,0,0]
end
# =================================================================

Animesh Kumar

unread,
Nov 23, 2005, 8:17:01 PM11/23/05
to
Spamless wrote:
> On 2005-11-23, Spamless <Spam...@Nil.nil> wrote:
>
>
>>The reason I say that this is "almost" perfect is that I haven't looked up
>>the ratio between the inner and outer radii of the bounding circles for CD
>>labels (standard and full face)
>
>
> I have now.
>

<snip>

I appreciate all your effort. However, I think mathmap only works in
Linux (or you need some sort of C-compiler). Is that true? I was a bit
apprehensive in installing mathmap because I use WinXp.

I would like to see the results you get. You can email me and I can host
them for you as well. Not a big issue.

To me, it appears, you use max function out from mathmap + gimp
together. I love to use filters on the other hand.

Best regards,
Animesh

Spamless

unread,
Nov 24, 2005, 11:17:11 AM11/24/05
to
On 2005-11-24, Animesh Kumar <anime...@gmail.com> wrote:
> Spamless wrote:
>> On 2005-11-23, Spamless <Spam...@Nil.nil> wrote:
>>
>>
>>>The reason I say that this is "almost" perfect is that I haven't looked up
>>>the ratio between the inner and outer radii of the bounding circles for CD
>>>labels (standard and full face)
>>
>>
>> I have now.
>
> I appreciate all your effort. However, I think mathmap only works in
> Linux (or you need some sort of C-compiler). Is that true? I was a bit
> apprehensive in installing mathmap because I use WinXp.

A google search on "mathmap gimp windows" got me some results

The mathmap home page is http://www.complang.tuwien.ac.at/schani/
Unfortunately, this is available as source which is fine for *nix users but
less useful for Windows users unless they use cygwin and compile and use
linux programmes.
A search on "mathmap gimp windows" shows precompiled windows versions at,
for example, http://wingimp.hp.infoseek.co.jp/files/plug-ins/, but that
page has plugins compiled back in 2002 so it will be an older version of
mathmap and one might have to modify the mathmap code. The older version
may or may not support loops and the CONFORMAL map uses a loop and
series expansion of an elliptic integral with complex numbers.
http://www.princeton.edu/~mplough/plugins_unsupported.html shows someone
working on compiling mathmap for gimp2 but not having finished at the time
the page was written.
Looking further may turn up something more usable :-)
I am using GIMP on linux and have no experience with working with it in
Windows so ... hopefully someone else can help out with that.
One could use a live CD linux distribution which has a compiler and GIMP
(or perhaps it might include mathmap) such as Knoppix (but not Damn Small
Linux) (it would be nice to have a small fat32 and ext2 or ext3 partition
- fat32 for being able to move things between windows and linux without
worrying about writing to NTFS and perhaps ext2/ext3 for saving linux
data to the hard disk with permissions, symbolic links, etc.).

> I would like to see the results you get. You can email me and I can host
> them for you as well. Not a big issue.

OK ... I have some samples ...

> To me, it appears, you use max function out from mathmap + gimp
> together. I love to use filters on the other hand.

Mathmap has a spherical map (like that already in gimp) which does not use
a perspective view (so one does not lose the data at the edge of the
original). I wanted to see how many different reasonable maps I could get
from a square to a circle - quite a few it appears - for different images
different maps give more interesting or "nicer" results.

I suppose I could try doing it all with perl (mathmap is not so powerful but
it has a nice simple syntax for doing what it does).

> Best regards,
> Animesh

Ditto,
John

Spamless

unread,
Dec 6, 2005, 11:45:50 AM12/6/05
to
On 2005-11-21, Spamless <Spam...@Nil.nil> wrote:
> On 2005-11-20, Spamless <Spam...@Nil.nil> wrote:
>
>> What should be near the center hub of the label? The center of the album
>> cover image? In that case, probably the best is to use a conformal map of a
>> unit disk to a square using, say, the usual Schwarz-Christoffel
>> transformation (the complex variable z in the unit disk is mapped to the
>> variable w in a square with w=INTEGRAL(dz/SQRT(1-z^4)). I will pass on that
>> (for the moment, anyway) since it involves programming elliptic integrals
>> using complex numbers.
>
> Ah, heck. Why not be complete? It is only an (elliptic) integral using
> complex numbers!
>
> Here is a map from a square (scale or crop first) with alpha channel to a
> circular disk which is conformal (it uses the Schwarz-Christoffel
> transformation - a point, z, in the unit disk is mapped to a point, w, in a
> square via:
> w = INTEGRAL[dt/sqrt(1-t^4): from 0 to z]
> where z and w are complex numbers).

That maps the center of the square to the center of the circle.
Why not be more complete?


The mathmaprc conformal (Schwarz-Christoffel) map is the only (except for
rotations, and reflections of course) conformal map from the square to the
unit disk which preserves the center. The Moebius transformation,
u=(v-v_0)/(1-v*v_0') maps the unit disk (complex number, v) to the unit disk
(complex number, w) and maps the point v_0 to the center (it is, up to
rotations, the only such conformal map). Composing this with the
Schwartz-Christoffel transformation gives the only conformal maps from the
square to the disk. The following code (mathmap 1.0.1, tested in gimp 2.2.9:
upon installing mathmap you will find it under Filters|Generic. You have the
option of using one of the premade filters or choosing the "mathmap" option
at the end. If you choose that, there are several tabs available, among them
one labelled "Expression" which provides a text box into which one can paste
code copied from below. The "User Values" tab allows one to adjust values.
One can modify one's mathmaprc to add the code to the menu list) is the
combination of the Moebius and the Schwarz-Christoffel transformations.

It is designed to work on a square (crop or scale first) RGBA (RGB format
with alpha channel) layer and conformally map this to a circular disk. Start
with such a layer, start up the mathmap plugin, add this code and click
PREVIEW. The edges are a bit rough. Click the "User Values" tab.

The "number of terms" value is the number of terms used in the series
approximation of the elliptic integral involved in the Schwarz-Christoffel
transformation. It starts at five (I should probably have raised that to a
higher value - raise it when you have set the rotation and center position -
it will be quicker for the preview to leave this low and only raise it for
the final result). This is a good map from the square to the disk (it is the
only conformal one, except for rotations, which maps the center to the
center), however you may want to adjust the position of where the center of
the square maps - it may be important and even using a full-face CD label it
may be cut out by the label's central hub. A large adjustment will cause
distortion, so use a full-face label and make whatever small adjustment is
necessary. You can adjust how far (center distance) and in what direction
(center angle) the center of the square moves (to what point the center of
the square is mapped). One can also set an overall rotation (rotation
angle). The initial values map the center of the square to the center of the
disk, so if you want to move the center, adjust these. When set, increase
the "number of terms" used in the integral approximation to get a good,
smooth boundary (result).


MATHMAP 1.0.1 code (conformal may of square to disk - center of square
need not be mapped to the disk's center.)
======================================================================
# Conformal (Schwarz-Christoffel transformation)
# and a conformal map of the disk to itself to
# modify the position of the center point's image.


# Maps the interior of a unit circle with position
# z, a complex number, to a position in a square
# with position given by the complex number w
# by w = INTEGRAL(dt/sqrt(1-t^4): t=0 to z).
# The resulting square has size given by an integral
# and does not have horizontal and vertical sides
# so we need some rotating and scaling.
# Increase count to see the effect of more terms
# in the series expansion of the integral.
#

# One can first apply the Moebius transformation
# z=exp(i*rotation)*(v-v_0)/(1-v*v_0')
# where v_0 is a point in the unit circle and '=complex conjugate.
# This conformal map of the unit disk to itself maps the point
# v_0 to the center of the resulting image. Applying this first,
# the point v_0 will be mapped to the center of the circle
# and pick up the image at the center of the square (the
# square's center maps to v_0).
# ============ CODE ======================================


count=user_int("number of terms",5,100);

rot=deg2rad(user_slider("rotation angle",0,360));
ctr=user_slider("center distance",0,1);
cta=deg2rad(user_slider("center angle",0,360));


V=.92705;
if (r < X) then
rect=toXY(ra:[r,a-pi/4]);

origpt=(ri:[rect[0],rect[1]])/X;
vpt=toXY(ra:[ctr,cta-pi/4]);v0=ri:[vpt[0],vpt[1]];
alpt=toXY(ra:[1,rot]);al=ri:[alpt[0],alpt[1]];
z=al*(origpt-v0)/(1-origpt*conj(v0));


term=z;w=term;n=0;
z4=z*z*z*z;
while (n < count)
do
term=z4*term*(2*n+1)/2/(n+1);w=w+term/(4*n+5);n=n+1;
end;
polar=toRA(xy:[w[0],w[1]]);
origVal(ra:[polar[0]*X/V,polar[1]+pi/4]);
else
rgba:[0,0,0,0];
end

# ========================================================
# ========================================================

bazec...@gmail.com

unread,
Aug 6, 2020, 3:03:07 PM8/6/20
to
just use warp transform.

John McCue

unread,
Aug 6, 2020, 4:44:50 PM8/6/20
to
bazec...@gmail.com wrote:
> On Monday, November 14, 2005 at 3:16:38 PM UTC-8, Charlie wrote:
--------------------------^^^^

>> Hi,
>>
>> I'm trying to change the shape of an image, my problem is this :
[snip]
>
> just use warp transform.

Well if Charlie still has this issue after 15 years,
he has more problems then using gimp.
0 new messages