<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scott builds Software &#187; fisheye imagemagick obama</title>
	<atom:link href="http://scottpenberthy.com/tag/fisheye-imagemagick-obama/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottpenberthy.com</link>
	<description>Musings on iPhone, Flash and the Cloud</description>
	<lastBuildDate>Tue, 28 Jun 2011 05:02:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fisheye effect in ImageMagick</title>
		<link>http://scottpenberthy.com/2008/09/05/fisheye-effect-in-imagemagick/</link>
		<comments>http://scottpenberthy.com/2008/09/05/fisheye-effect-in-imagemagick/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 18:25:32 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[fisheye imagemagick obama]]></category>

		<guid isPermaLink="false">http://scottpenberthy.com/?p=7</guid>
		<description><![CDATA[ImageMagick is my favorite tool for messing around with images.  At PhotoBucket, we dedicated dozens of machines to &#8220;mogrify&#8221; uploaded images into thumbnails and appropriate sizes for user accounts.  I use it on my pet projects like an image zoomer and a youtube clipper.

Recently I discovered the &#8220;-fx&#8221; or special effects options of the ImageMagick [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption aligncenter" style="width: 310px"><img alt="A fisheye view of Obama" src="http://i33.tinypic.com/2lx9emq.jpg" title="Fisheye Obama" width="300" height="348" /><p class="wp-caption-text">A fisheye view of Obama</p></div>
<p><a href="http://imagemagick.org">ImageMagick</a> is my favorite tool for messing around with images.  At PhotoBucket, we dedicated dozens of machines to &#8220;mogrify&#8221; uploaded images into thumbnails and appropriate sizes for user accounts.  I use it on my pet projects like an <a href="http://izoomr.com">image zoomer</a> and a <a href="http://tubechopper.com">youtube clipper.<br />
</a></p>
<p>Recently I discovered the &#8220;-fx&#8221; or special effects options of the ImageMagick toolset.  This was written in 1996 as probably a neat hack.  The code interprets a calculator-like FX language for each channel of every pixel.   This is painfully slow and screams for optimization.  Yet its so much fun. Take the following snippet of FX:</p>
<pre lang="c">kk=w*0.5;
ll=h*0.5;
dx=(i-kk);
dy=(j-ll);
aa=atan2(dy,dx);
rr=hypot(dy,dx);
rs=rr*rr/hypot(kk,ll);
px=kk+rs*cos(aa);
py=ll+rs*sin(aa);
p{px,py}</pre>
<p>Variable names are tricky.  Several characters are reserved to represent pixels (p), various channels (r, g, b), locations (i,j), sizes (w,h) and more.</p>
<p>Lines 1 and 2 of the FX code calculates the center of an image in x,y coordinates as (kk,ll).</p>
<p>Lines 3 through 6 compute the polar coordinates of the current pixel i,j as a radius rr and angle aa.  The internal function hypot() is a shortcut for hypotenuse of a triangle, which is the Euclidean distance between points (kk,ll) and the current pixel (i,j).</p>
<p>Now comes the silly part.  I take the radius of the polar coordinates and square it, then divide by maximum radius of the image, for a new radius RS for &#8220;radius scaled&#8221; in Line 7.  From there, I calculate the cartesian coordinate that correponds to a pixel at radius RS from the center, at the original angle AA, in lines 8 and 9. This creates a 2d bell-shaped surface that is flat at the edges curves up toward infinity at the center.  Finally, Line 10 stores the pixel located at (px,py) in the current pixel (i,j) using the &#8220;p&#8221; operator.</p>
<p>I store this equation in a file, &#8220;effect.fx&#8221;.  I downloaded a picture of Obama as obama.jpg:</p>
<div class="wp-caption aligncenter" style="width: 310px"><img alt="Obama as we all see him" src="http://i33.tinypic.com/2q8c4mo.jpg" title="Obama smiling" width="300" height="348" /><p class="wp-caption-text">Obama as we all see him</p></div>
<p>Next I applied convert using the fx operator:</p>
<pre lang="c">convert -fx @effect.fx obama.jpg fish.jpg</pre>
<p>This takes a few minutes on my MacBook pro. The result is a fisheye view of Obama!  Fun hack, with apologies to Obama.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottpenberthy.com/2008/09/05/fisheye-effect-in-imagemagick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

