Gravitational Lensing With Adobe Photoshop

Original image

Original image Lensed image
This is the original image, the galaxy M 33 taken from the STScI Digitized Sky Survey and placed on a painted starry background. Click on a blue button of the bar to apply the gravitational lens (buttons below the galaxy's center give the most dramatic results) or scroll down to find more about what the individual frames show and how they were created.

A great thing with the Adobe Photoshop, a powerful software for editing electronic images, is that its capability can be enormously expanded by adding new plug-in filters. To a quantitatively-oriented user and amateur astronomer like me, Filter Factory plug-in by Joseph Ternasky and Dave Corboy is of special interest. It lets users to create their own filters with a simple internal programming language and compile them as separate files.

Gravitational Lenser 1.3, a photorealistic simulator of a point mass, weak and thin gravitational lens, is such a plug-in filter.

The plugin should be also accepted by these graphical programs: Adobe PhotoDeluxe, Ulead PhotoImpact, Animator Studio, Corel PhotoPaint 7.0+, Freehand 7, Macromedia xRes 2.0, Macromedia Director 5.0, Painter 4.0, Paint Shop Pro 4.0 for Windows 95 and Micrografx Picture Publisher. See Installation for details.

I haven't been able to compile Gravitational Lenser 1.3 for Mac users yet, but they can try a gravitational lensing filter created by Pete Kernan (Case Western Reserve University).

Gravitational Lenser 1.3


DownloadCopyright and DisclaimerInstallationLet's Go For ItUnderlying Geometry and PhysicsSource CodeFuture DevelopmentGravitational Lensing on the WebThanks!


If you want your own copy of Gravitational Lenser 1.3 for Windows, just download the file (about 24k) from this page.

Copyright and Disclaimer

Distribution of Gravitational Lenser 1.3 is allowed as long as the file grlens13.8bf is left intact and free for ultimate users. Commercial redistribution without prior consent of the author is forbidden. No warranties are given.


Extract from the zip archive the plug-in itself, the file grlens13.8bf, and copy it into your plug-in directory (usually C:\PHOTOSHP\PLUGINS). Next time you run Adobe Photoshop, it will recognize a new category in the Filter menu, Astronomy, with Gravitational Lenser 1.3 in it. Note that the filter is available only if you have a RGB (16.7-million-color) image opened, since it doesn't work with other types (in particular grayscale images or indexed color GIFs).

Visit PC Resources for Photoshop to learn how Gravitational Lenser 1.3 should be installed in Adobe PhotoDeluxe, Ulead PhotoImpact, Animator Studio, Corel PhotoPaint 7.0+, Freehand 7, Macromedia xRes 2.0, Macromedia Director 5.0, Painter 4.0 and Paint Shop Pro 4.0 for Windows 95 (be patient, info is at the very bottom of the page). Go first to Webattitude if you wish to use the plugin with Micrografx Picture Publisher.

Let's Go For It

This is the menu of Gravitational Lenser 1.3:

Gravitational Lenser 1.3 menu
On its left side you can see the preview window, while the right part of the menu shows six sliders. Through them, you can change the lens settings. One of Filter Factory drawbacks is that sliders always show values between 0 and 255, no matter what values are actually returned to a filter. In Gravitational Lenser 1.3 they control (from the top):
Position of the lens within the image

The actual range is [0,X] and [Y,0], where X is the width and Y is the height of the image in pixels. Note the reversed limits of the vertical shift slider – the origin of the coordinate system (x=0, y=0) is in the top left-hand corner of the image. The default value for the first two sliders is 128, understood by the filter as X/2 and Y/2, respectively, that is the image's center.

Einstein radius

The basic characteristic of a gravitational lens with circular symmetry (see below). The slider changes it from 0 to the minimum of X/2 and Y/2. For example, when the image you are lensing have width (X) 1000 and height (Y) 1200 pixels, and the slider shows 51, the Einstein radius of the applied gravitational lens is 100 pixels, because (51/255)*(1000/2) equals 100.

RGB Color

Since Gravitational Lenser 1.3 is intended first of all as an educational tool, it adds a circle of the Einstein radius to the lensed image. Its RGB color can be changed by the last three sliders. The default color is R=255, G=255, B=255, nothing else than pure white. The same color applies also to a strangely shaped area around the lens. This is an undefined area where the filter tries to map pixels from outside the image. Curiously enough, these sliders shows the actual values!

Underlying Geometry and Physics

An attempt to model with Filter Factory the appearance of the starry skies during a fall into a black hole would give you a pretty hard time, but a typical gravitational lens is fortunately much easier to code. Under most circumstances, we can take advantage of several considerable simplifications (not independent of each other):

Thin screen (lens) approximation

Makes use of the fact that most of the light deflection occurs within a distance from the lens which is comparable to the impact parameter and much smaller than the total length of the light path from the source to the observer. The lens is no longer considered a three-dimensional object. Instead, it is approximated by a thin mass sheet perpendicular to the optical axis, referred to as the lens plane (yellow in the Figure 1 below). The effect of the lens depends only on projection of its mass to this plane. The light ray consists of two straight lines which meet at the lens plane.

Geometry of a gravitational lens system
Fig.1. Basic geometry of a typical gravitational lens system in the thin screen approximation. Light from the source S (here the center of a spiral galaxy) is deflected by the angle a when it arrives at the plane of the lens L, so it finally reaches an observer's telescope at the point O. She then sees an image of the source at the angular distance h from the optical axis (here conveniently – but not necessarily – chosen as the line joining the observer and the lens). Without the lens, she would see the source at the angular distance b from the optical axis. The distances between the observer and the source, the observer and the source, and the lens and the source are D1, D2, and D3, respectively. The diagram is not drawn to scale.

Gravitational lens configuration which gives rise to the
Einstein ring

Fig. 2. Special configuration when the observer, the lens and the source are perfectly aligned and lie on a straight line. Because of the circular symmetry of the problem in this case, the source is imaged as a narrow ring centered on the lens. Its radius e is referred to as the Einstein radius.


Small angles approximation

Assumes that the angles b, h, and the deflection angle a are very small and their tangents can be replaced by the angles themselves (measured in radians). Note this condition is intimately related to the thin screen approximation – given the distances between the observer and the lens, and the lens and the source are required to be much greater than the impact parameter, the light ray can reach the observer only if the deflection angle is small enough.

Weak field approximation

Requires that the light passes through a weak field with the absolute value of the Newtonian gravitational potential much smaller than the square of the speed of light c. In addition, the relative (peculiar) velocities of the observer, the lens and the source must be much smaller than c.

Again, this is related to the small angles approximation because the weak field implies the small deflection angle.


Considering the above simplifications, and the fact that the first version of Gravitational Lenser models a point mass lens, we can derive the following relation between the angles b, h, and a called the lens equation (see the Derivation of the Lens Equation page for details):

b = h – aD3/D1

Sometimes you can meet a slightly different form of this equation

b = h – â

where â = aD3/D1 is called the reduced deflection angle.

Perhaps the most elegant form of the (point mass) lens equation is this one:

b = h – e2/h

where we introduced the Einstein radius

e = (4GMD3/c2D1D2)1/2

In a general case, the lens equation has two different solutions corresponding to two images of the source:

h1 = (b + (b2 + 4e2)1/2) / 2

h2 = (b – (b2 + 4e2)1/2) / 2

If the lens and the source are perfectly aligned (b = 0), we still formally get two images at the same distance from the lens

h1 = h2 = e ,

but in reality the source is imaged as a light ring of the Einstein radius (called the Einstein ring) because the problem is now circularly symmetric and no position angle is preferred.

Fig. 3. In the sky, the lens equation is nothing but a simple transformation of the polar coordinates with the lens as their origin. Left: General case when the lens creates two images on either side of the source, one inside the Einstein ring and the other outside. Note the images, the source and the lens lie on a straight line. Right: Perfect alignment of the lens and the source visualizes the Einstein ring dramatically.


Source Code

The lens equation is surprisingly easy to code with the Filter Factory programming language. If the lens characterized by the Einstein radius of 100 pixels is situated in the middle of the image, the entire code reads as follows:

R: rad(d,m–100*100/m,z)

G: rad(d,m–100*100/m,z)

B: rad(d,m–100*100/m,z)

(Note that since gravitational lenses are achromatic, the code is identical for all three colors R, G, and B.)

Mathematically speaking, the Filter Factory statement

performs the following transformation of the polar coordinates r and phi:
phiold = function1(phinew)

rold = function2(rnew)

In particular, the statement


leaves the image as it is, while the statement


enlarges it twice.

For those familiar with Filter Factory programming, here is the complete source code of Gravitational Lenser 1.3:


put(sqr(get(2))==get(6) || get(2)==0 || (x-get(3) > X)
|| (x-get(3) < 0) || (y-get(4) > Y) || (y-get(4) < 0),5),
get(5) ? ctl(3+z) : src(x-get(3),y-get(4),z)


get(5) ? ctl(3+z) : src(x-get(3),y-get(4),z)


get(5) ? ctl(3+z) : src(x-get(3),y-get(4),z)

If you wish to modify the filter to satisfy your curiosity or needs, feel free to do it. To save you from having to type the lengthy code, I have included the source file grlens13.afs in the zip archive.

Future Development

I am trying to model with Filter Factory more complicate lenses. Despite limitations of this programming tool, in particular its integer mathematics, I believe it can accomodate a code for a good simulator of elliptical lenses described by equations of R. D. Blandford and C. S. Kochanek (Astrophys. J 321, 658, 1987). Stay tuned.

Gravitational Lensing on the Web

Here is what I found with Alta Vista about interplay between light and gravity. Needless to say, the list is quite incomplete and your suggestions will be welcome.

Pete Kernan's Gravitational Lensing with Java

If your browser supports Java (not JavaScript), visit this interactive webpage to lens an astrophysicist's portrait or an image anywhere on the Web. Cool!

STScI Gravitational Lensing Page

Hosted at the University of Liège, this site offers among other things bibliography of lensing papers (available in PostScript or Latex format), list of gravitational lens systems and gallery of their images. Unfortunately, the Didactical Experiments page seems to be under permanent construction and contains nothing but an abstract.

CASTLe (CfA-Arizona Space Telescope Lens) Survey

Detailed tables of observational and model parameters of gravitational lens candidates (and binary quasars as well) plus images from the HST.

MPA Gravitational Lensing Group

Web home of the gravitational lensers at the Max-Planck-Institut für Astrophysik. Miscellaneous stuff, including on-line articles and preprints, links to other sites (try a microlensed kangaroo by Joachim Wambsganss), and the interactive search form for lensing literature.

Virtual Trips To Black Holes and Neutron Stars

Amazing travel beyond the weak field and small angles approximations by Robert Nemiroff (Michigan Technological University). Short movies (in mpeg format) show the starry skies from an orbit around a neutron star and a black hole. An on-line article by the same author, originally published in the American Journal of Physics, gives background information.

Photographing Black Holes

Chapter #10, Illuminations, of Jean-Pierre Luminet's popular book Black Holes (Cambridge University Press, 1992). What happens when light approaches these relativistic beasts.

Jerusalem Lectures on Gravitational Lensing (in PostScript, over 4 Mb!)

Cool introductory course by Ramesh Narayan (Harvard-Smithsonian Center for Astrophysics) and Matthias Bartelmann (Max-Planck-Institut für Astrophysik). Technical, but approachable.

The Web is also full of sites about what is called microlensing, when the lens is a star rather than a galaxy or a galaxy cluster, and the observer detects brightening of the unresolved source rather than its multiple images:
Project MACHO (MAssive Compact Halo Object)
Project OGLE (Optical Gravitational Lensing Experiment)
Project EROS (Experience pour la Recherche d'Objets Sombres)
Project PLANET (Probing Lensing Anomalies NETwork)
And last, but not least, links to the HST spectacular images of gravitational lenses:
Lensing By the Galaxy Cluster Abell 2218
Cross-shaped Gravitational Lenses
Image of Primeval Galaxy (Lensed by the Cluster ZwCl 0024.0+1652)
The Farthest Galaxy In the Universe (Lensed by the Cluster ZwCl 1358.1+6245)


I am indebted to Werner D. Streidt for his writting Filter Factory FAQ. I knew nothing about this programming tool before I accidentally found his FAQ on the Web. They were the source of general information on Filter Factory on this page. The version 1.3 is much faster then the previous one (1.2) thanks to code improvements made by Kangaroo and Mario Klingemann. Thanks!

Go to Leos Ondra's Home Page.
Leos Ondra
May 1, 2000