<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Image rotation with bilinear interpolation</title>
	<atom:link href="http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/feed/" rel="self" type="application/rss+xml" />
	<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/</link>
	<description>Mathematics. Programming. Entrepreneurship.</description>
	<lastBuildDate>Fri, 27 Jan 2012 12:15:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-23509</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Sun, 04 Apr 2010 02:46:13 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-23509</guid>
		<description>You&#039;re welcome, Jahn.</description>
		<content:encoded><![CDATA[<p>You&#8217;re welcome, Jahn.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jahn</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-23119</link>
		<dc:creator>Jahn</dc:creator>
		<pubDate>Fri, 02 Apr 2010 16:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-23119</guid>
		<description>Thanks a lot.  I understand completely.  Very cool stuff!</description>
		<content:encoded><![CDATA[<p>Thanks a lot.  I understand completely.  Very cool stuff!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-23112</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Fri, 02 Apr 2010 15:59:18 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-23112</guid>
		<description>Hi Jahn, I&#039;m assuming the pixel loss you&#039;re referring to is not due to the bilinear interpolation, because interpolation, by nature, is lossy. I&#039;m assuming you&#039;re referring to the clipping of the destination image.

So, a few minor changes to the original code. First, add 3 new variables:

int iCentreX, iCentreY;
int iDestCentreX, iDestCentreY;
int iWidth, iHeight;
int iDiagonal;

iDestCentreX, iDestCentreY and iDiagonal.

Next assign them as follows:

iWidth = bm.Width;
iHeight = bm.Height;
iDiagonal = (int)(Math.Ceiling(Math.Sqrt((double)(bm.Width * bm.Width + bm.Height * bm.Height)))) + 20;

iCentreX = iWidth / 2;
iCentreY = iHeight / 2;
iDestCentreX = iDestCentreY = iDiagonal / 2;

iDiagonal basically is the diagonal size of the source image. I added 20 pixels for buffer.

Then create the destination image as follows:

Bitmap bmBilinearInterpolation = new Bitmap(iDiagonal, iDiagonal);

Then initialise the destination image:

for (i = 0; i &lt; iDiagonal; ++i)
{
	for (j = 0; j &lt; iDiagonal; ++j)
	{
		bmBilinearInterpolation.SetPixel(j, i, Color.Black);
	}
}

Then with the assignment nested for loops, use this (note the end condition of the for loop):

for (i = 0; i &lt; iDiagonal; ++i)
{
	for (j = 0; j &lt; iDiagonal; ++j)
	{
		// convert raster to Cartesian
		x = j - iDestCentreX;
		y = iDestCentreY - i;

...

The last change is when it&#039;s the centre of the source image. Then use this:

// centre of image, no rotation needed
bmBilinearInterpolation.SetPixel(j, i, bm.GetPixel(iCentreX, iCentreY));
continue;


That&#039;s it. You should get a destination image with no missing pixels. The edges will be a little jagged, because it&#039;s interpolated with black pixels. I think I&#039;ll write up a post with the full code. It&#039;s hard to put code in comments.</description>
		<content:encoded><![CDATA[<p>Hi Jahn, I&#8217;m assuming the pixel loss you&#8217;re referring to is not due to the bilinear interpolation, because interpolation, by nature, is lossy. I&#8217;m assuming you&#8217;re referring to the clipping of the destination image.</p>
<p>So, a few minor changes to the original code. First, add 3 new variables:</p>
<p>int iCentreX, iCentreY;<br />
int iDestCentreX, iDestCentreY;<br />
int iWidth, iHeight;<br />
int iDiagonal;</p>
<p>iDestCentreX, iDestCentreY and iDiagonal.</p>
<p>Next assign them as follows:</p>
<p>iWidth = bm.Width;<br />
iHeight = bm.Height;<br />
iDiagonal = (int)(Math.Ceiling(Math.Sqrt((double)(bm.Width * bm.Width + bm.Height * bm.Height)))) + 20;</p>
<p>iCentreX = iWidth / 2;<br />
iCentreY = iHeight / 2;<br />
iDestCentreX = iDestCentreY = iDiagonal / 2;</p>
<p>iDiagonal basically is the diagonal size of the source image. I added 20 pixels for buffer.</p>
<p>Then create the destination image as follows:</p>
<p>Bitmap bmBilinearInterpolation = new Bitmap(iDiagonal, iDiagonal);</p>
<p>Then initialise the destination image:</p>
<p>for (i = 0; i &lt; iDiagonal; ++i)<br />
{<br />
	for (j = 0; j &lt; iDiagonal; ++j)<br />
	{<br />
		bmBilinearInterpolation.SetPixel(j, i, Color.Black);<br />
	}<br />
}</p>
<p>Then with the assignment nested for loops, use this (note the end condition of the for loop):</p>
<p>for (i = 0; i < iDiagonal; ++i)<br />
{<br />
	for (j = 0; j < iDiagonal; ++j)<br />
	{<br />
		// convert raster to Cartesian<br />
		x = j &#8211; iDestCentreX;<br />
		y = iDestCentreY &#8211; i;</p>
<p>&#8230;</p>
<p>The last change is when it&#039;s the centre of the source image. Then use this:</p>
<p>// centre of image, no rotation needed<br />
bmBilinearInterpolation.SetPixel(j, i, bm.GetPixel(iCentreX, iCentreY));<br />
continue;</p>
<p>That&#039;s it. You should get a destination image with no missing pixels. The edges will be a little jagged, because it&#039;s interpolated with black pixels. I think I&#039;ll write up a post with the full code. It&#039;s hard to put code in comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jahn</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-22870</link>
		<dc:creator>Jahn</dc:creator>
		<pubDate>Thu, 01 Apr 2010 17:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-22870</guid>
		<description>Very helpful...I was wondering, however, how you would go about preventing the pixel loss.(for the bi-linear algorithm)  Obviously your new destination bitmap (bmBilinearInterpolation) would just use the diagonal size of the source image for it&#039;s width and height.  However, what would you have to do  to get it to map to the center of the new destination image? Changing the for loops for i and j to have both have the condition i &lt; diagonal, j &lt; diagonal prevents some loss of pixels but one or two sides will still get clipped.</description>
		<content:encoded><![CDATA[<p>Very helpful&#8230;I was wondering, however, how you would go about preventing the pixel loss.(for the bi-linear algorithm)  Obviously your new destination bitmap (bmBilinearInterpolation) would just use the diagonal size of the source image for it&#8217;s width and height.  However, what would you have to do  to get it to map to the center of the new destination image? Changing the for loops for i and j to have both have the condition i &lt; diagonal, j &lt; diagonal prevents some loss of pixels but one or two sides will still get clipped.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-21034</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Fri, 26 Mar 2010 13:39:59 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-21034</guid>
		<description>Hi Dale, I believe I started out trying to guard against atan where x could be 0. Then I used atan2 instead. Which as you mentioned, works correctly even for x=0.

The more important point, is that I want to determine when (x,y) = (0,0), the centre of the image. Since I had an if clause to check for x=0, I might as well do some form of guarding.

Thank you for pointing that out.</description>
		<content:encoded><![CDATA[<p>Hi Dale, I believe I started out trying to guard against atan where x could be 0. Then I used atan2 instead. Which as you mentioned, works correctly even for x=0.</p>
<p>The more important point, is that I want to determine when (x,y) = (0,0), the centre of the image. Since I had an if clause to check for x=0, I might as well do some form of guarding.</p>
<p>Thank you for pointing that out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dale</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-20538</link>
		<dc:creator>Dale</dc:creator>
		<pubDate>Wed, 24 Mar 2010 17:50:44 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-20538</guid>
		<description>I&#039;m confused by the guards you have around Atan2. Atan2(y,x), as far as I can tell, works correctly even when x is 0.

Atan(y/x) doesn&#039;t, granted, but Atan has a whole other host of problems. To wit, Atan(1/1) = Atan(-1/-1).</description>
		<content:encoded><![CDATA[<p>I&#8217;m confused by the guards you have around Atan2. Atan2(y,x), as far as I can tell, works correctly even when x is 0.</p>
<p>Atan(y/x) doesn&#8217;t, granted, but Atan has a whole other host of problems. To wit, Atan(1/1) = Atan(-1/-1).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-18898</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Mon, 15 Mar 2010 12:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-18898</guid>
		<description>Hi William, I&#039;m glad you got something useful from the bilinear interpolation explanation.</description>
		<content:encoded><![CDATA[<p>Hi William, I&#8217;m glad you got something useful from the bilinear interpolation explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Milberry</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-18889</link>
		<dc:creator>William Milberry</dc:creator>
		<pubDate>Mon, 15 Mar 2010 11:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-18889</guid>
		<description>Thank you for your brilliantly simple and easy to understand diagram showing bilinear interpolation!  With one look I understood it and was able to code it in a little program I&#039;m working on.

Excellent work.

William Milberry</description>
		<content:encoded><![CDATA[<p>Thank you for your brilliantly simple and easy to understand diagram showing bilinear interpolation!  With one look I understood it and was able to code it in a little program I&#8217;m working on.</p>
<p>Excellent work.</p>
<p>William Milberry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Convert 360 degree fisheye image to landscape mode &#124; Polymath Programmer</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-5958</link>
		<dc:creator>Convert 360 degree fisheye image to landscape mode &#124; Polymath Programmer</dc:creator>
		<pubDate>Thu, 15 Oct 2009 09:04:39 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-5958</guid>
		<description>[...] plagiarising my own code from the image rotation with bilinear interpolation article for the bilinear interpolating parts. There are 2 resulting images, one with and one [...]</description>
		<content:encoded><![CDATA[<p>[...] plagiarising my own code from the image rotation with bilinear interpolation article for the bilinear interpolating parts. There are 2 resulting images, one with and one [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent Tan</title>
		<link>http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/comment-page-1/#comment-5482</link>
		<dc:creator>Vincent Tan</dc:creator>
		<pubDate>Tue, 24 Mar 2009 06:57:25 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=575#comment-5482</guid>
		<description>Hi A Khan, what a coincidence, the article was based on what I did using MATLAB to implement image rotation too!

I was in university then, and I knew only C and MATLAB college work. So yeah, obvious choice of language...</description>
		<content:encoded><![CDATA[<p>Hi A Khan, what a coincidence, the article was based on what I did using MATLAB to implement image rotation too!</p>
<p>I was in university then, and I knew only C and MATLAB college work. So yeah, obvious choice of language&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

