From: Dominique O. <Dom...@po...> - 2004-04-02 23:22:10
|
When using imshow(), why does there always seem to be a blank zone along the southern and eastern edges of the figure? For instance: X = rand(10,10) imshow(X) plots a luminance image of X, which seems fine, except for the lower and rightmost edges, which are blank. I may be misunderstanding the purpose of imshow, but skimming through the code didn't give me an answer. I am using matplotlib 0.52 on WinXP with either GTKAgg or TkAgg. Thanks ! Dominique |
From: John H. <jdh...@ac...> - 2004-04-06 14:53:20
|
>>>>> "Dominique" == Dominique Orban <Dom...@po...> writes: Dominique> When using imshow(), why does there always seem to be a Dominique> blank zone along the southern and eastern edges of the Dominique> figure? For instance: Dominique> X = rand(10,10) imshow(X) Dominique> plots a luminance image of X, which seems fine, except Dominique> for the lower and rightmost edges, which are blank. I Dominique> may be misunderstanding the purpose of imshow, but Dominique> skimming through the code didn't give me an answer. I Dominique> am using matplotlib 0.52 on WinXP with either GTKAgg or Dominique> TkAgg. Hi Dominique, Your example did point me to a small bug in the image module, but it is mostly unrelated to what you are observing. In the axes.py function imshow, replace self.set_image_extent(0, numcols-1, 0, numrows-1) with self.set_image_extent(0, numcols, 0, numrows) This only affects the tick labeling (not the actual image display) but it was wrong before and should be changed. Now run this script from matplotlib.matlab import * X = rand(10,10) subplot(211) im = imshow(X) im.set_interpolation('nearest') subplot(212) im = imshow(X) show() The key thing is that the white border you are seeing arises from interpolation. The points on the bottom and right have no neighbors in those directions, and so they interpolate to the background color, which is white. You can set the axis limits so that these regions don't appear, or use nearest neighbor interpolation. Let me know if these suggestions don't work for you. JDH |
From: Dominique O. <Dom...@po...> - 2004-04-06 15:25:25
|
John Hunter wrote: >>>>>>"Dominique" == Dominique Orban <Dom...@po...> writes: > > > Dominique> When using imshow(), why does there always seem to be a > Dominique> blank zone along the southern and eastern edges of the > Dominique> figure? For instance: > > Dominique> X = rand(10,10) imshow(X) > > Dominique> plots a luminance image of X, which seems fine, except > Dominique> for the lower and rightmost edges, which are blank. I > Dominique> may be misunderstanding the purpose of imshow, but > Dominique> skimming through the code didn't give me an answer. I > Dominique> am using matplotlib 0.52 on WinXP with either GTKAgg or > Dominique> TkAgg. > > Hi Dominique, > > Your example did point me to a small bug in the image module, but it > is mostly unrelated to what you are observing. In the axes.py > function imshow, replace > > self.set_image_extent(0, numcols-1, 0, numrows-1) > with > self.set_image_extent(0, numcols, 0, numrows) > > > This only affects the tick labeling (not the actual image display) > but it was wrong before and should be changed. > > Now run this script > > from matplotlib.matlab import * > X = rand(10,10) > > subplot(211) > im = imshow(X) > im.set_interpolation('nearest') > > subplot(212) > im = imshow(X) > show() > > The key thing is that the white border you are seeing arises from > interpolation. The points on the bottom and right have no neighbors > in those directions, and so they interpolate to the background color, > which is white. > > You can set the axis limits so that these regions don't appear, or use > nearest neighbor interpolation. > > Let me know if these suggestions don't work for you. > > JDH John, Many thanks for your reply and suggestions. I see what is happening. Nearest neighbor interpolation has the colors right, but i was trying to get "more interpolation". I guess looking at the great pictures that imshow() produces i was hoping for a result such as that of X = rand(10) pcolor( X ) shading 'interp' in Matlab. The Matplotlib picture is just as good really, except for the border. Why are the other borders not white as well? Is the interpolation "directional"? Why aren't pixels on the border only interpolated with their neighbors inside the image, and not those outside (these have less neighbors than pixels in the middle)? Perhaps you can point me to the part of the code (c++ i assume) which does the interpolation? Should i grab the CVS repository for that? Then maybe i can play around and see if i can achieve the effect i am looking for. Thanks again ! Dominique |
From: John H. <jdh...@ac...> - 2004-04-06 16:12:53
|
>>>>> "Dominique" == Dominique Orban <Dom...@po...> writes: Dominique> Many thanks for your reply and suggestions. I see what Dominique> is happening. Nearest neighbor interpolation has the Dominique> colors right, but i was trying to get "more Dominique> interpolation". I guess looking at the great pictures Dominique> that imshow() produces i was hoping for a result such Dominique> as that of Dominique> X = rand(10) pcolor( X ) shading 'interp' As far as I recall, matlab's pcolor also loses an edge due to interpolation. Perhaps the main difference is that in matlab, the axes limits are set by default so that you don't see it. I remember being surprised by this many moons ago the first time I used pcolor in matlab. Dominique> in Matlab. The Matplotlib picture is just as good Dominique> really, except for the border. Why are the other Dominique> borders not white as well? Is the interpolation Dominique> "directional"? Why aren't pixels on the border only Dominique> interpolated with their neighbors inside the image, and Dominique> not those outside (these have less neighbors than Dominique> pixels in the middle)? I'll have to think about this some more. There is also something funny about how the tick labeling currently works for images, because the X[0,0] coord is upper left but is labeled as 0,10. Perhaps ticks should be off be default, or labeled with the y axis descending. Those who have opinions please weigh in. BTW, the developer of agg, Maxim, is fairly responsive, so if you want to pursue this issue after reading some of the code I point to below on the agg mailing list http://lists.sourceforge.net/lists/listinfo/vector-agg-general Maxim can probably provide some additional guidance. Dominique> Perhaps you can point me to the part of the code (c++ i Dominique> assume) which does the interpolation? Should i grab the Dominique> CVS repository for that? Then maybe i can play around Dominique> and see if i can achieve the effect i am looking for. The code is available in the matplotlib src distribution. The module is src/_image.cpp, which uses agg for image manipulation; see the function Image_resize. All the agg code is also in the matplotlib src distro, eg, agg2/include. agg2 doesn't have a lot of documentation - hence I spend a lot of time reading src files, eg agg_conv_transform.h agg_span_image_filter_rgb24.h agg_span_image_filter_rgba32.h agg_span_interpolator_linear.h The latest agg snapshot it http://www.antigrain.com/agg2.tar.gz which has lots of examples in the examples dir. Agg can do a lot with images, some of which would be nice to add to the matplotlib interface.... JDH |