Skip to content

Make the filternorm prop of Images a boolean rather than a {0,1} scalar. #10442

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5170,9 +5170,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
shape : scalars (columns, rows), optional, default: None
For raw buffer images

filternorm : scalar, optional, default: 1
A parameter for the antigrain image resize filter. From the
antigrain documentation, if `filternorm` = 1, the filter
filternorm : bool, optional, default: True
Copy link
Member

Choose a reason for hiding this comment

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

OK, so filternorm was either 1 or zero?

The rest of this docstring doesn't make a lick of sense to me. I think they are trying to say the sum of the filter should be one, but???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to propose a better wording :-) (it doesn't make sense to me either)
At least since #10383 matplotlib._image.resample also documents norm as a bool.

A parameter for the antigrain image resize filter (see the
antigrain documentation). If *filternorm* is set, the filter
normalizes integer values and corrects the rounding errors. It
doesn't do anything with the source floating point values, it
corrects only integers according to the rule of 1.0 which means
Expand Down
23 changes: 10 additions & 13 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __init__(self, ax,
norm=None,
interpolation=None,
origin=None,
filternorm=1,
filternorm=True,
filterrad=4.0,
resample=False,
**kwargs
Expand Down Expand Up @@ -424,7 +424,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
_interpd_[self.get_interpolation()],
self.get_resample(), 1.0,
self.get_filternorm(),
self.get_filterrad() or 0.0)
self.get_filterrad())

# we are done with A_scaled now, remove from namespace
# to be sure!
Expand Down Expand Up @@ -459,7 +459,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
_interpd_[self.get_interpolation()],
True, 1,
self.get_filternorm(),
self.get_filterrad() or 0.0)
self.get_filterrad())
# we are done with the mask, delete from namespace to be sure!
del mask
# Agg updates the out_mask in place. If the pixel has
Expand Down Expand Up @@ -492,7 +492,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm(), self.get_filterrad() or 0.0)
self.get_filternorm(), self.get_filterrad())

# at this point output is either a 2D array of normed data
# (of int or float)
Expand Down Expand Up @@ -735,20 +735,17 @@ def get_resample(self):

def set_filternorm(self, filternorm):
"""
Set whether the resize filter norms the weights -- see
help for imshow
Set whether the resize filter normalizes the weights.

ACCEPTS: 0 or 1
"""
if filternorm:
self._filternorm = 1
else:
self._filternorm = 0
See help for `~.Axes.imshow`.

.. ACCEPTS: bool
"""
self._filternorm = bool(filternorm)
self.stale = True

def get_filternorm(self):
"""Return the filternorm setting."""
"""Return whether the resize filter normalizes the weights."""
return self._filternorm

def set_filterrad(self, filterrad):
Expand Down