Friday, August 17, 2007

I wish I had thought of that with my kids

Another way of doing a Droste with your children!

Monday, August 13, 2007

Conformal Cube: The Story of a Search

What you see here is the result of a long and complicated search, but with an enormous amount of help from Daniel M. German I've able to construct the conformal projection of the cube. If your first reaction is to mutter: "The what of the cube?" or just "So?", and if you are interested, please follow these explanations...

You may have seen before panoramas projected in a cube: in flickr for example, there is a "foldables" group and I have some myself (including other polyhedra). These panoramas have all in common the use of the gnomonic or perspective projection: in this type of projection straight lines stay straight. This is great for architectural photos, but as you can see for the model on the right, you get broken lines in the sides of the cube (the columns of the cathedral seem to be broken).

It is possible in theory to devise a conformal projection that would show the sphere as a cube. However it is very difficult to find information on such a projection. The usual internet cartography sources, if they mention this projection, give no clue at all how it can be constructed. The only reference is in this PDF file where a planisphere projected conformally in the cube is given, only quoting John Parr Snyder's personal software. John Parr Snyder is the most precious reference for mathematical cartography available on the web, and though he died in 1997 his personal BASIC program used to generate maps is the only trace left of how he constructed the conformal cube... mostly undocumented, and of course not portable at all. Furthermore, the formulas used in that program are all forward transformations, whereas the projection of an image needs the inverse formulas.

But a reference was there! a 1976 paper in Cartographica titled "Conformal Projections based on Elliptic Functions" by L.P. Lee (another incredibly talented cartographer, "who retired in 1974 as Chief Computer in the New Zealand Department of Lands and Survey") seemed to be the source for these polyhedral globes. Daniel German was very very helpful in locating this rather obscure publication (and others), and I have to thank him for that!

The conformal projection uses an incredible 1872 theorem by Hermann Schwarz who showed that "the spherical triangles into which the surface of the sphere is divided by the planes of symmetry of the regular polyhedra can be conformally represented on the infinite half-plane by algebraic transformations of the stereographic projection on the central plane so that the vertices are represented by the points 0, 1, infinity on the real axis". Unfortunately the paper is in german and is probably even harder to get, so I will able to look how Schwarz showed this...

(the source image for this shot is from the Notre-Dame-de-Reims Cathedral in Reims, France)

Saturday, August 11, 2007

Edit the Nadir and Zenith of an Equirectangular Panorama

Often the most difficult part of an equirectangular panorama (360° wide, 180° vertically) is the nadir, i.e. the bottom. This is where the tripod is, so no clear shot can be had without some sort of acrobatics to tilt the tripod away. So an important part of creating a nice equirectangular panorama is editing the nadir (and sometimes, the zenith).
The procedure I had been using so far is:
  1. Create the equirectangular image (in Gimp)
  2. Use hugin to create the rectilinear projection of the nadir, with a 90° field-of-view
  3. Edit this rectilinear image (in Gimp)
  4. Use hugin to output this edited rectilinear image into an equirectangular panorama
  5. Manually blend the extra nadir unto the equirectangular image (in Gimp).
As you can see, this needs going back and forth between Gimp and hugin, and is not very practical. Spurred by the Photoshop tool mentioned here I bring to you a Gimp/Mathmap script to create the zenith and nadir of an equirectangular panorama, edit in place and transform back.

You should first make a copy of the layer with the equirectangular image, since the transformation to and back from the zenith/nadir does not keep the part around the horizon.

Filter used to create the Zenith and Nadir:

filter ToNadirZenith (image in)
# Filter created by Seb Przd
# Licensed under the GPL

if x<0 then
sinphi1=1;
xx=x+X/2;
else
sinphi1=-1;
xx=x-X/2;
end;

yy=y;

rr=sqrt(xx^2+yy^2);

c=atan(rr/Y);

phi =
if rr == 0 then
0
else
asin(cos(c)*sinphi1)
end;

xxx=atan(xx,-yy*sinphi1)*X/pi;
yyy=phi*Y/(pi/2);

in(xy:[xxx,yyy])
end


Filter used to transform back the Zenith and Nadir:

filter FromNadirZenith (image in)
# Filter created by Seb Przd
# Licensed under the GPL

output=1;
if y>Y/4 then
sinphi1=1;
xc=-X/2;
else if y<-Y/4 then
sinphi1=-1;
xc=X/2;
else
output=0;
end;
end;

cosc=sinphi1*sin(y/Y*pi/2);
xx=cos(y/Y*pi/2)*sin(x/X*pi)/cosc;
yy=-sinphi1*cos(y/Y*pi/2)*cos(x/X*pi)/cosc;

if abs(xx)>1 then output=0; end;

if output then
in(xy:[xx*X/2+xc,yy*Y])
else
rgbaColor(0,0,0,0)
end

end

Tuesday, July 3, 2007

Miniville: The SimCity of the 2000s


Miniville
Originally uploaded by seb przd
You liked to play SimCity when you were young(er)... now let the others play it for you. It seems that every time somebody clicks on the link for a city, the population increases by one, or something else happens: you get links for the environment, industry, transportation, etc. So it's like SimBlogCity...

(if anybody is still reading this blog, go ahead and click! don't be afraid! may be the Schwarz be with you!)

Wednesday, November 1, 2006

What's going on in a recursive picture?

1. Start with an image showing the frame you want to use for your Escher "Print Gallery" photograph. The highest the resolution, the better.




2. Rotate and crop the source image so that the center frame is dead in the center, and the aspect ratio of the whole image is the same as the center frame. Also, now may be a good time to correct any problem in the source image, check levels and sharpen a bit, especially the center (where the "blowing out" will be highest).




3. This step is where the mathmap magic starts to come in. By using a complex logarithm on the pixels, the image is "unrolled" around the center.
4. The previous image is cut and pasted several times, so that the whole canvas is covered.

5. This step undoes what was done in Step 3. This is done by "rolling up" the image in Step 4 by using the inverse of the complex logarithm, i.e. the complex exponential.

You might have said, why bother? I could have easily gimped the source image to get this. And you would be right. But there is more to it...

6. If you rotate the image produced by Step 4 a bit, and then roll it up as in Step 5, you get this image. VoilĂ !

Thursday, October 26, 2006

Why you should correct for barrel distortion

All zoom lenses are prone to a type of distortion known as barrel distortion, where straight lines appear curved as if the center of the image had been inflated. This is especially the case with the less expensive zoom lenses; usually more expensive lenses, lenses with less zoom range and prime (fixed) lenses are corrected and are closer to a perfcet rectilinear lens. My new lens, the Nikkor 18-200mm, shows a lot of barrel distortion at 18mm.

Fortunately, quite a few tools are available to correct for this predictable type of distortion. I use clens, a command-line utility distributed with panotools, with the lens profiles that come with PTlens, a windows alternative to clens (you can find the database in panotools or here).

The top image above is a straight grid, as shot. You can see the curves that should be straight. The bottom image shows the automatic correction with clens, with the lens profile from PTlens.

clens is run like this:
clens -p profile.txt -s nona -l "Nikkor 18-200mm f/3.5-5.6 G ED-IF AF-S VR DX" image.jpg


If it run like this:
clens -p profile.txt -s nona --Lenses image.jpg

it outputs a list of possible lenses, according to the make of the camera and the focal length.
The correction is not perfect, since the Nikkor 18-200mm shows a more complicated (higher order) type of distortion that clens cannot correct for.

Wednesday, October 25, 2006

Turkish Delight


Turkish Delight
Originally uploaded by Seb Przd.
Having fun with conformal mappings.