Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rewrite of image infrastructure#5718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 65 commits intomatplotlib:masterfrommdboom:image-interpolation
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
65 commits
Select commitHold shift + click to select a range
cf11aea
Remove Image class. Replace with resample func
mdboomDec 22, 2015
3b7d1bb
Agg backend shouldn't do its own image interp
mdboomDec 22, 2015
c9cae50
Update interpolation_methods.py to use viridis
mdboomDec 22, 2015
4a05302
Remove svg.image_noscale rcParam
mdboomDec 22, 2015
0aa222a
Rewrite image classes
mdboomDec 22, 2015
0793aa2
Update backends for new API
mdboomDec 22, 2015
1384c7c
Use transforms to rotate image, not hack
mdboomDec 22, 2015
9148c7f
Update tests
mdboomDec 22, 2015
820479e
Decrease generated code size
mdboomDec 22, 2015
fad84c8
Remove explicit LICENSE.
mdboomDec 22, 2015
64e84ea
Numpy 1.6 compatibility
mdboomDec 30, 2015
0be04c0
Add Agg filter test
mdboomDec 30, 2015
a8643f1
Fix formatting
mdboomDec 30, 2015
5df79f0
Mark test as known fail on Numpy 1.6
mdboomDec 30, 2015
b436f1a
Update draw_image API doc
mdboomDec 30, 2015
dfbc39d
Fix reference counting
mdboomDec 30, 2015
9d3b468
[skip-ci] PEP8
mdboomDec 30, 2015
f9d8534
Update what's new
mdboomDec 30, 2015
7b32cd8
Fix demo_annotation_box.py
mdboomDec 30, 2015
6e60ebf
Fix #3057: Don't composite when interpolation == 'none'
mdboomDec 30, 2015
dc66ed0
Remove broken example
mdboomDec 30, 2015
7cccfb3
Support 16-bit grayscale
mdboomDec 30, 2015
5073f6e
Fix permissions on demo_image_affine.py
mdboomDec 31, 2015
625e80a
Fix alpha handling for interpolation == 'none'
mdboomDec 31, 2015
c778cfc
Use `kind` instead of `issubclass`
mdboomDec 31, 2015
9fe6658
Update docstring
mdboomDec 31, 2015
d61ac2a
Revert change
mdboomDec 31, 2015
b3318fd
Make demo_text_path.py work again
mdboomDec 31, 2015
ffbbf05
Remove extraneous space
mdboomDec 31, 2015
fbb55c8
Privatize self._images
mdboomDec 31, 2015
34d6cc8
Simplify expression
mdboomJan 1, 2016
4c5a3bf
Update docstring
mdboomJan 1, 2016
9448208
Fix #5520: Don't round up if already rounded
mdboomJan 5, 2016
83f4bc9
Merge pull request #17 from tacaswell/image-interpolation
mdboomJan 4, 2016
d5030a4
Use abs() for NEAREST check
mdboomJan 5, 2016
55c1abb
Image composite respecting z-order
mdboomJan 5, 2016
fe376c4
Fix #4280: Preserve size when saving images
mdboomJan 5, 2016
5266fde
Python 2.x fix
mdboomJan 5, 2016
9285c3a
Update composite_images docstring
mdboomJan 7, 2016
e2b2bbe
Refine can_composite
mdboomJan 7, 2016
b894683
Improve make_image docstring
mdboomJan 7, 2016
4e43c8b
Use X.ndim over len(X.shape)
mdboomJan 7, 2016
8665697
Use float32 when applying alpha
mdboomJan 7, 2016
d21a6ed
Use output.shape
mdboomJan 7, 2016
2d2a126
Add unsampled kwarg everywhere
mdboomJan 7, 2016
6d3518a
PEP8
mdboomJan 7, 2016
0b8d693
Use super()
mdboomJan 7, 2016
0f43f68
Put shape in exception
mdboomJan 7, 2016
cd0e7e0
Case insensitive check for PNG extension
mdboomJan 7, 2016
e62832f
Fix Numpy version check
mdboomJan 7, 2016
e7d54d5
@cleanup unnecessary here
mdboomJan 7, 2016
3e532e1
Make BboxImage work
mdboomJan 7, 2016
cfad8d9
Reinstate strictness of test_imsave_color_alpha
mdboomJan 7, 2016
e52c26f
PEP8
mdboomJan 7, 2016
0469ab7
Fix has image test in Axes
mdboomJan 7, 2016
b391f08
Refactor image compositing logic into a single function
mdboomJan 7, 2016
89365c1
Properly handle NULL composite image
mdboomJan 11, 2016
7f2f375
PEP8
mdboomJan 11, 2016
9827d1f
Consistent handling of empty composite images
mdboomJan 11, 2016
5be66de
Rename lena variable
mdboomJan 29, 2016
bd521cd
Update docstring to reflect reality
mdboomJan 29, 2016
d6b22a5
Address more minor comments in the PR
mdboomFeb 2, 2016
fff1d66
Increase tolerance on Windows
mdboomFeb 17, 2016
da6c00b
Increase tolerance of png_suite test
mdboomFeb 17, 2016
c9b2425
PEP8
mdboomFeb 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Rewrite image classes
  • Loading branch information
@mdboom
mdboom committedFeb 17, 2016
commit0aa222a647e9b5f2ed882afb7fe78fab3eebb28b
24 changes: 6 additions & 18 deletionslib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2360,33 +2360,21 @@ def draw(self, renderer=None, inframe=False):
# make a composite image, blending alpha
# list of (mimage.Image, ox, oy)

zorder_images = [(im.zorder, im) for im in self.images
if im.get_visible()]
zorder_images.sort(key=lambda x: x[0])

mag = renderer.get_image_magnification()
ims = [(im.make_image(mag), 0, 0, im.get_alpha())
for z, im in zorder_images]

l, b, r, t = self.bbox.extents
width = int(mag * ((np.round(r) + 0.5) - (np.round(l) - 0.5)))
height = int(mag * ((np.round(t) + 0.5) - (np.round(b) - 0.5)))
im = mimage.from_images(height,
width,
ims)

im.is_grayscale = False
l, b, w, h = self.bbox.bounds
# composite images need special args so they will not
# respect z-order for now
zorder_images = [im for im in self.images if im.get_visible()]
zorder_images.sort(key=lambda x: x.zorder)

data, l, b = mimage.composite_images(
zorder_images, renderer, renderer.get_image_magnification())

gc = renderer.new_gc()
gc.set_clip_rectangle(self.bbox)
gc.set_clip_path(mtransforms.TransformedPath(
self.patch.get_path(),
self.patch.get_transform()))

renderer.draw_image(gc, round(l), round(b),im)
renderer.draw_image(gc, round(l), round(b),data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just curious, at what zorder does the composed image end up at?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It ends up at the zorder of the first image in the list. You can seeFigure.draw orAxes.draw for where that actually happens. It's not perfect (and in fact is sort of a long-standing bug in zorder), but zorder is a mess in general in matplotlib, I don't think we'll fix it at this juncture ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

maybe draw it at the average zorder? This is the time to break that sort of thing.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Alternatively, I was thinking that we should only composite images at thesame zorder. In the normal case (where the zorder didn't change from the default) that will be the case. In the case of tinkering with zorder, the user will really care about getting it right and we can either (1) create multiple composites for each zorder "grouping" or (2) just turn off compositing if the images are at different zorders.

gc.restore()

if dsu_rasterized:
Expand Down
13 changes: 9 additions & 4 deletionslib/matplotlib/cm.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -203,7 +203,7 @@ def __init__(self, norm=None, cmap=None):
self.colorbar = None
self.update_dict = {'array': False}

def to_rgba(self, x, alpha=None, bytes=False):
def to_rgba(self, x, alpha=None, bytes=False, norm=True):
"""
Return a normalized rgba array corresponding to *x*.

Expand DownExpand Up@@ -258,9 +258,14 @@ def to_rgba(self, x, alpha=None, bytes=False):

# This is the normal case, mapping a scalar array:
x = ma.asarray(x)
x = self.norm(x)
x = self.cmap(x, alpha=alpha, bytes=bytes)
return x
if norm:
x = self.norm(x)
rgba = self.cmap(x, alpha=alpha, bytes=bytes)
# For floating-point greyscale images, we treat negative as
# transparent so we copy that over to the alpha channel
if x.ndim == 2 and issubclass(x.dtype.type, np.floating):
rgba[:, :, 3] = np.where(x < 0.0, 0, rgba[:, :, 3])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There has got to be a clearer way to write this, but I am not sure of the numpy indexing rules are when mixing boolean indexes and integer indexes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks identical torgba[:, :, 3][x < 0] = 0. No fancy indexing is required, and it is much faster than using where:

In [9]: xx = np.random.randn(1000, 1000, 4)In [10]: x = xx[:, :, 0]In [12]: timeit xx[:, :, 3][x < 0] = 0100 loops, best of 3: 2.08 ms per loopIn [13]: timeit xx[:, :, 3] = np.where(x < 0, 0, xx[:, :, 3])100 loops, best of 3: 9.65 ms per loop

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks -- I'll change that. Those crazy indexing tricks in Numpy always evade me.

return rgba

def set_array(self, A):
'Set the image array from numpy array *A*'
Expand Down
14 changes: 3 additions & 11 deletionslib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,7 @@

from matplotlib.cbook import Stack, iterable

from matplotlib import_image
from matplotlib importimage as mimage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actually, it might make sense to keep it as_image because__all__ isn't used in this file. Therefore, we probably don't want to further pollute the namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

eh, people should not be bulk importing fromfigure....right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well, then__all__ would never be needed in python, right?

On Wed, Jan 6, 2016 at 1:53 PM, Thomas A Caswellnotifications@github.com
wrote:

In lib/matplotlib/figure.py
#5718 (comment):

@@ -32,7 +32,7 @@

from matplotlib.cbook import Stack, iterable

-from matplotlib import _image
+from matplotlib import image as mimage

eh, people should not be bulk importing from figure....right?


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5718/files#r48993652.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I sometimes have thoughts that__all__ = [] should be added to all python files 😈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

" lib/matplotlib/tests/baseline_images/test_backend_svg/noscale.png"
doesn't look right to me.

On Wed, Jan 6, 2016 at 2:11 PM, Thomas A Caswellnotifications@github.com
wrote:

In lib/matplotlib/figure.py
#5718 (comment):

@@ -32,7 +32,7 @@

from matplotlib.cbook import Stack, iterable

-from matplotlib import _image
+from matplotlib import image as mimage

I sometimes have thoughts thatall = [] should be added to all python
files [image: 😈]


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5718/files#r48995898.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's best to use ourmFOO convention here. I thought the import to a private name here was really confusing. We could go through at some point and make__all__ for the major modules with sane stuff, but I think that's a separate task that probably needs its own discussion about backward compatiblity/best practice etc.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

" lib/matplotlib/tests/baseline_images/test_backend_svg/noscale.png" doesn't look right to me.

The change is due to the fact that the backend-specificsvg.image-noscale rcParam was removed in favor of the backend-agnosticinterpolation='none' feature and its default in rcParamimage.interpolation. Therefore, in the test, all three backends exhibit theinterpolation == 'none' behavior rather than just SVG. The svg-specific feature was removed because (a) it would require significant additional effort to maintain and (b) it's better to be backend-generic IMHO. I think the SVG-specific feature predates the support for the feature in all relevant backends.

from matplotlib.image import FigureImage

import matplotlib.colorbar as cbar
Expand DownExpand Up@@ -1255,21 +1255,13 @@ def draw(self, renderer):
# make a composite image blending alpha
# list of (_image.Image, ox, oy)
mag = renderer.get_image_magnification()
ims = [(im.make_image(mag), im.ox, im.oy, im.get_alpha())
for im in self.images]

im = _image.from_images(int(self.bbox.height * mag),
int(self.bbox.width * mag),
ims)

im.is_grayscale = False
l, b, w, h = self.bbox.bounds
data, l, b = mimage.composite_images(self.images, renderer, mag)

def draw_composite():
gc = renderer.new_gc()
gc.set_clip_rectangle(self.bbox)
gc.set_clip_path(self.get_clip_path())
renderer.draw_image(gc, l, b,im)
renderer.draw_image(gc, l, b,data)
gc.restore()

dsu.append((self.images[0].get_zorder(), self.images[0],
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp