SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Eric E. <ems...@ob...> - 2006年07月30日 20:38:00
Hi,
this is a question I have posted earlier, but unfortunately I didn't get
any answer.
if anybody has any hint on how to do this, I would be most graceful!!
Thanks in advance!
I would like to visualize an image after a rotation:
==> this means to view each squared pixels as "rotated" (seen as an
rotated square). I have in fact several images which I need to plot on
the same figure (with subplot), each of these having different "rotation
angles".
The rough solution would be to rotate the data itself (x and y) and use
imshow after some rebinning on a squared grid. But this would not be
showing the original data, which is what I wish to do.
Is it possible to do this in mpl?
thanks!
Eric
From: Eric F. <ef...@ha...> - 2006年07月31日 01:16:46
I think you can get the effect you describe using pcolor or pcolormesh; 
the latter is faster but due to a bug it doesn't handle alpha values 
other than 1. You will have to generate arrays with the pixel corners 
(not centers) as you want them to be after your rotation. You will want 
to use the shading='flat' kwarg.
Eric
Eric Emsellem wrote:
> Hi,
> 
> this is a question I have posted earlier, but unfortunately I didn't get
> any answer.
> if anybody has any hint on how to do this, I would be most graceful!!
> Thanks in advance!
> 
> I would like to visualize an image after a rotation:
> ==> this means to view each squared pixels as "rotated" (seen as an
> rotated square). I have in fact several images which I need to plot on
> the same figure (with subplot), each of these having different "rotation
> angles".
> 
> The rough solution would be to rotate the data itself (x and y) and use
> imshow after some rebinning on a squared grid. But this would not be
> showing the original data, which is what I wish to do.
> Is it possible to do this in mpl?
> 
> thanks!
> 
> Eric
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: John H. <jdh...@ac...> - 2006年07月31日 13:36:15
>>>>> "Eric" == Eric Emsellem <ems...@ob...> writes:
 Eric> Hi, this is a question I have posted earlier, but
 Eric> unfortunately I didn't get any answer. if anybody has any
 Eric> hint on how to do this, I would be most graceful!! Thanks
 Eric> in advance!
I looked at this a bit -- the underlying image extension code handles
image rotations but it is not exposed at the python level. I spent
some time working on an image class that would handle rotations (in
this test code below I just hardcoded the rotation for testing). The
missing part is to get the extent and image placement algorithms to do
the layout properly in the presence of rotation (eg handling extent
and corners properly below). But this should give the enterprising
developer a head start if they want to run with with. Basically, I
just copied the guts out of the axes.image.AxesImage.make_image code
to experiment with adding a rotation
from matplotlib.image import AxesImage
from pylab import subplot, show, nx
class RotatedImage(AxesImage):
 def make_image(self):
 from matplotlib.colors import normalize, colorConverter
 from matplotlib.numerix import arange, asarray, UInt8, Float32, repeat, NewAxis, typecode
 import matplotlib._image as _image
 if self._A is not None:
 if self._imcache is None:
 if typecode(self._A) == UInt8:
 im = _image.frombyte(self._A, 0)
 im.is_grayscale = False
 else:
 x = self.to_rgba(self._A, self._alpha)
 im = _image.fromarray(x, 0)
 if len(self._A.shape) == 2:
 im.is_grayscale = self.cmap.is_gray()
 else:
 im.is_grayscale = False
 self._imcache = im
 else:
 im = self._imcache
 else:
 raise RuntimeError('You must first set the image array or the image attribute')
 bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)
 if self.origin=='upper':
 im.flipud_in()
 im.set_bg( *bg)
 im.set_interpolation(self._interpd[self._interpolation])
 # image input dimensions
 numrows, numcols = im.get_size()
 im.reset_matrix()
 xmin, xmax, ymin, ymax = self.get_extent()
 dxintv = xmax-xmin
 dyintv = ymax-ymin
 # the viewport scale factor
 sx = dxintv/self.axes.viewLim.width()
 sy = dyintv/self.axes.viewLim.height()
 if im.get_interpolation()!=_image.NEAREST:
 im.apply_translation(-1, -1)
 # the viewport translation
 tx = (xmin-self.axes.viewLim.xmin())/dxintv * numcols
 #if flipy:
 # ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
 #else:
 # ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
 ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
 l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
 im.apply_translation(tx, ty)
 im.apply_scaling(sx, sy)
 # resize viewport to display
 rx = widthDisplay / numcols
 ry = heightDisplay / numrows
 im.apply_scaling(rx, ry)
 im.apply_rotation(45.)
 #print tx, ty, sx, sy, rx, ry, widthDisplay, heightDisplay
 im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
 norm=self._filternorm, radius=self._filterrad)
 if self.origin=='upper':
 im.flipud_in()
 return im
ax = subplot(111)
im = RotatedImage(ax, interpolation='nearest')
im.set_data(nx.mlab.rand(10,10))
xmin, xmax, ymin, ymax = im.get_extent()
corners = (xmin, ymin), (xmax, ymax)
ax.update_datalim(corners)
ax.set_xlim((xmin, xmax))
ax.set_ylim((ymin, ymax))
ax.images.append(im)
show()
From: Eric E. <ems...@ob...> - 2006年07月31日 13:51:29
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
beautiful!<br>
I was in the meantime working out something using the suggestion Eric
sent me (e.g. via pcolormesh) and I could work most of things I wanted
out, but at the price of a rather stupidly looking management of the
axis and rotation (maybe there is a way for improvement here too...). <br>
Your solution may indeed be a cleaner way forward! I'll try both ways
and see how I manage to get things done (the main problem being my
rather poor ability in writing advanced codes in python...<br>
<br>
thanks &amp;<br>
cheers!<br>
Eric<br>
<br>
John Hunter wrote:
<blockquote cite="mid...@pe..."
 type="cite">
 <blockquote type="cite">
 <blockquote type="cite">
 <blockquote type="cite">
 <blockquote type="cite">
 <blockquote type="cite">
 <pre wrap="">"Eric" == Eric Emsellem <a class="moz-txt-link-rfc2396E" href="mailto:ems...@ob...">&lt;ems...@ob...&gt;</a> writes:
 </pre>
 </blockquote>
 </blockquote>
 </blockquote>
 </blockquote>
 </blockquote>
 <pre wrap=""><!---->
 Eric&gt; Hi, this is a question I have posted earlier, but
 Eric&gt; unfortunately I didn't get any answer. if anybody has any
 Eric&gt; hint on how to do this, I would be most graceful!! Thanks
 Eric&gt; in advance!
I looked at this a bit -- the underlying image extension code handles
image rotations but it is not exposed at the python level. I spent
some time working on an image class that would handle rotations (in
this test code below I just hardcoded the rotation for testing). The
missing part is to get the extent and image placement algorithms to do
the layout properly in the presence of rotation (eg handling extent
and corners properly below). But this should give the enterprising
developer a head start if they want to run with with. Basically, I
just copied the guts out of the axes.image.AxesImage.make_image code
to experiment with adding a rotation
from matplotlib.image import AxesImage
from pylab import subplot, show, nx
...
 </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
====================================================================
Eric Emsellem <a class="moz-txt-link-abbreviated" href="mailto:ems...@ob...">ems...@ob...</a>
 Centre de Recherche Astrophysique de Lyon
9 av. Charles-Andre tel: +33 (0)4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 (0)4 78 86 83 86
France <a class="moz-txt-link-freetext" href="http://www-obs.univ-lyon1.fr/eric.emsellem">http://www-obs.univ-lyon1.fr/eric.emsellem</a>
====================================================================
</pre>
</body>
</html>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /