<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277</link>
    <title>MATLAB Central Newsreader - Image rotation and NaNs...</title>
    <description>Feed for thread: Image rotation and NaNs...</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 27 May 2009 09:03:01 -0400</pubDate>
      <title>Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#652671</link>
      <author>Matman86 Di</author>
      <description>Hi everybody,I'm trying to rotate an image but,for some reason,when I make a 360? rotation I can't get the original image,but I got some NaNs too in image matrix and I don't know why...here is the code:&lt;br&gt;
&lt;br&gt;
[M N]=size(X);&lt;br&gt;
[n m]=meshgrid(-N/2:N/2-1,-M/2:M/2-1);&lt;br&gt;
np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
y=interp2(n,m,X,np,mp,'linear'); &lt;br&gt;
&lt;br&gt;
Thx in advance...</description>
    </item>
    <item>
      <pubDate>Sat, 06 Jun 2009 09:57:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655039</link>
      <author>Matman86 Di</author>
      <description>&quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;gvivk5$q0m$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everybody,I'm trying to rotate an image but,for some reason,when I make a 360? rotation I can't get the original image,but I got some NaNs too in image matrix and I don't know why...here is the code:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [M N]=size(X);&lt;br&gt;
&amp;gt; [n m]=meshgrid(-N/2:N/2-1,-M/2:M/2-1);&lt;br&gt;
&amp;gt; np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
&amp;gt; mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
&amp;gt; y=interp2(n,m,X,np,mp,'linear'); &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thx in advance...&lt;br&gt;
&lt;br&gt;
Anyone??T_T</description>
    </item>
    <item>
      <pubDate>Sat, 06 Jun 2009 10:37:00 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655047</link>
      <author>us</author>
      <description>&quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;h0dehc$8ui$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;gvivk5$q0m$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi everybody,I'm trying to rotate an image but,for some reason,when I make a 360? rotation I can't get the original image,but I got some NaNs too in image matrix and I don't know why...here is the code:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [M N]=size(X);&lt;br&gt;
&amp;gt; &amp;gt; [n m]=meshgrid(-N/2:N/2-1,-M/2:M/2-1);&lt;br&gt;
&amp;gt; &amp;gt; np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
&amp;gt; &amp;gt; mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
&amp;gt; &amp;gt; y=interp2(n,m,X,np,mp,'linear'); &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thx in advance...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Anyone??T_T&lt;br&gt;
&lt;br&gt;
well, yes: your results comply exactly with the rule...&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;help interp2;&lt;br&gt;
%{&lt;br&gt;
% note: EXTRAPVAL&lt;br&gt;
...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ZI = INTERP2(...,METHOD,EXTRAPVAL) specificies a method and a scalar &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value for ZI outside of the domain created by X and Y.  Thus, ZI will&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equal EXTRAPVAL for any value of YI or XI which is not spanned by Y &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;or X respectively. A method must be specified for EXTRAPVAL to be used,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;the default method is 'linear'.&lt;br&gt;
...&lt;br&gt;
%}&lt;br&gt;
% eg,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X=magic(3);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[M N]=size(X);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[n m]=meshgrid(-N/2:N/2-1,-M/2:M/2-1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;y=interp2(n,m,X,np,mp,'linear');&lt;br&gt;
% look at&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[n;nan(1,size(n,1));np]     % &amp;lt;- nan: separator...&lt;br&gt;
% -or-&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[m;nan(1,size(m,1));mp]&lt;br&gt;
&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Sat, 06 Jun 2009 17:31:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655086</link>
      <author>Matman86 Di</author>
      <description>&amp;gt; well, yes: your results comply exactly with the rule...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;      help interp2;&lt;br&gt;
&amp;gt; %{&lt;br&gt;
&amp;gt; % note: EXTRAPVAL&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt;     ZI = INTERP2(...,METHOD,EXTRAPVAL) specificies a method and a scalar &lt;br&gt;
&amp;gt;     value for ZI outside of the domain created by X and Y.  Thus, ZI will&lt;br&gt;
&amp;gt;     equal EXTRAPVAL for any value of YI or XI which is not spanned by Y &lt;br&gt;
&amp;gt;     or X respectively. A method must be specified for EXTRAPVAL to be used,&lt;br&gt;
&amp;gt;     the default method is 'linear'.&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; %}&lt;br&gt;
&amp;gt; % eg,&lt;br&gt;
&amp;gt;      X=magic(3);&lt;br&gt;
&amp;gt;      [M N]=size(X);&lt;br&gt;
&amp;gt;      [n m]=meshgrid(-N/2:N/2-1,-M/2:M/2-1);&lt;br&gt;
&amp;gt;      np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
&amp;gt;      mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
&amp;gt;      y=interp2(n,m,X,np,mp,'linear');&lt;br&gt;
&amp;gt; % look at&lt;br&gt;
&amp;gt;      [n;nan(1,size(n,1));np]     % &amp;lt;- nan: separator...&lt;br&gt;
&amp;gt; % -or-&lt;br&gt;
&amp;gt;      [m;nan(1,size(m,1));mp]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; us&lt;br&gt;
&lt;br&gt;
Mmmm...maybe I'm a little dumb today but I can't understand what you just said,could you be more clear please?&lt;br&gt;
I know how interp2 works,but I can't explain why if I make a 360? rotation I can't return with the original values...</description>
    </item>
    <item>
      <pubDate>Sat, 06 Jun 2009 18:45:04 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655091</link>
      <author>Bruno Luong</author>
      <description>&quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;h0e94l$h1a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; I know how interp2 works,but I can't explain why if I make a 360? rotation I can't return with the original values...&lt;br&gt;
&lt;br&gt;
Because when you rotate pi 2*pi, the points (after rotation) do not fall exactly where it is due to numerical error (try to see the value of sin(2*pi), it is not zero), and if it's outside the box, interp2 puts the value to NaN.&lt;br&gt;
&lt;br&gt;
And btw, why your point of rotation is not centered in the image? It's off by 1/2 pixel.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sun, 07 Jun 2009 08:06:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655149</link>
      <author>Matman86 Di</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;h0edfg$ld0$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;h0e94l$h1a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I know how interp2 works,but I can't explain why if I make a 360? rotation I can't return with the original values...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Because when you rotate pi 2*pi, the points (after rotation) do not fall exactly where it is due to numerical error (try to see the value of sin(2*pi), it is not zero), and if it's outside the box, interp2 puts the value to NaN.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And btw, why your point of rotation is not centered in the image? It's off by 1/2 pixel.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
I answer first to last question:it's because if I make a grid like -M/2:M/2 I don't get the exact number of pixels.&lt;br&gt;
You're right for the NaNs,so I can't do anything about it I guess...&lt;br&gt;
According to you is ok if I make&lt;br&gt;
X(isnan(X))=0;&lt;br&gt;
in order to allow elaborations on the image?</description>
    </item>
    <item>
      <pubDate>Sun, 07 Jun 2009 08:38:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655151</link>
      <author>Bruno Luong</author>
      <description>&quot;Matman86 Di&quot; &amp;lt;pasqui.squall@email.it&amp;gt; wrote in message &amp;lt;h0fsd9$ej3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I answer first to last question:it's because if I make a grid like -M/2:M/2 I don't get the exact number of pixels.&lt;br&gt;
&lt;br&gt;
Add 0.5 see below&lt;br&gt;
&lt;br&gt;
&amp;gt; You're right for the NaNs,so I can't do anything about it I guess...&lt;br&gt;
&amp;gt; According to you is ok if I make&lt;br&gt;
&amp;gt; X(isnan(X))=0;&lt;br&gt;
&lt;br&gt;
No, use extrap option (Jos gave a hint)&lt;br&gt;
&lt;br&gt;
X=peaks(40);&lt;br&gt;
[M N]=size(X);&lt;br&gt;
[n m]=meshgrid(-N/2+0.5:N/2-0.5,-M/2+0.5:M/2-0.5);&lt;br&gt;
np=n*cos(2*pi)-m*sin(2*pi);&lt;br&gt;
mp=n*sin(2*pi)+m*cos(2*pi);&lt;br&gt;
y=interp2(n,m,X,np,mp,'linear',0);&lt;br&gt;
imagesc(y)&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sun, 07 Jun 2009 09:02:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655154</link>
      <author>Bruno Luong</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;h0fu99$guq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No, use extrap option (Jos gave a hint)&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Sorry, it is us who gave a hint, not Jos.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sun, 07 Jun 2009 16:53:01 -0400</pubDate>
      <title>Re: Image rotation and NaNs...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252277#655204</link>
      <author>Matman86 Di</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;h0fvm8$gid$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;h0fu99$guq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; No, use extrap option (Jos gave a hint)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sorry, it is us who gave a hint, not Jos.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Thank you very much!:)</description>
    </item>
  </channel>
</rss>

