Skip to content

Commit 74c016d

Browse files
committed
add shirnk parmater to demo_agg_filter.LightFilter
1 parent 0216290 commit 74c016d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

examples/misc/demo_agg_filter.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,40 @@ def process_image(self, padded_src, dpi):
9999

100100

101101
class LightFilter(BaseFilter):
102-
103-
def __init__(self, sigma, fraction=1):
102+
"""Apply LightSource filter"""
103+
104+
def __init__(self, sigma, fraction=1, shrink=None):
105+
"""
106+
Parameters
107+
----------
108+
sigma : float
109+
sigma for gaussian filter
110+
shrink: int or None: default None
111+
kernel size of the grey_erosion filter. This will
112+
effectively shrink the size of the base image, which
113+
can compansate the increased image footprint due to
114+
the gaussian filter.
115+
fraction: number: deault 1
116+
Increases or decreases the contrast of the hillshade.
117+
See `matplotlib.colors.LightSource`
118+
119+
"""
104120
self.gauss_filter = GaussianFilter(sigma, alpha=1)
105121
self.light_source = LightSource()
106122
self.fraction = fraction
123+
self.shrink = shrink
107124

108125
def get_pad(self, dpi):
109126
return self.gauss_filter.get_pad(dpi)
110127

111128
def process_image(self, padded_src, dpi):
129+
if self.shrink is not None:
130+
import scipy.ndimage as NI
131+
# we shrink the image a bit.
132+
padded_src = np.stack([NI.grey_erosion(padded_src[:, :, i],
133+
[self.shrink, self.shrink])
134+
for i in range(padded_src.shape[-1])],
135+
axis=-1)
112136
t1 = self.gauss_filter.process_image(padded_src, dpi)
113137
elevation = t1[:, :, 3]
114138
rgb = padded_src[:, :, :3]
@@ -261,7 +285,7 @@ def light_filter_pie(ax):
261285
explode = (0, 0.05, 0, 0)
262286
pies = ax.pie(fracs, explode=explode)
263287

264-
light_filter = LightFilter(9)
288+
light_filter = LightFilter(9, shrink=5)
265289
for p in pies[0]:
266290
p.set_agg_filter(light_filter)
267291
p.set_rasterized(True) # to support mixed-mode renderers

0 commit comments

Comments
 (0)