@@ -99,16 +99,40 @@ def process_image(self, padded_src, dpi):
99
99
100
100
101
101
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
+ """
104
120
self .gauss_filter = GaussianFilter (sigma , alpha = 1 )
105
121
self .light_source = LightSource ()
106
122
self .fraction = fraction
123
+ self .shrink = shrink
107
124
108
125
def get_pad (self , dpi ):
109
126
return self .gauss_filter .get_pad (dpi )
110
127
111
128
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 )
112
136
t1 = self .gauss_filter .process_image (padded_src , dpi )
113
137
elevation = t1 [:, :, 3 ]
114
138
rgb = padded_src [:, :, :3 ]
@@ -261,7 +285,7 @@ def light_filter_pie(ax):
261
285
explode = (0 , 0.05 , 0 , 0 )
262
286
pies = ax .pie (fracs , explode = explode )
263
287
264
- light_filter = LightFilter (9 )
288
+ light_filter = LightFilter (9 , shrink = 5 )
265
289
for p in pies [0 ]:
266
290
p .set_agg_filter (light_filter )
267
291
p .set_rasterized (True ) # to support mixed-mode renderers
0 commit comments