108
111
selections = None
109
112
return points, selections
116
def apply_selection_fade(mapped_image, mask, fade_alpha, fade_background):
117
'''Apply a selection fade to a colormapped image.
121
mapped_image : ndarray of uint8, shape (N,M,4)
122
The digitized rgba values
123
mask : ndarray of bool, shape (N,M,4)
124
The array of masked pixels
126
The alpha value for the fade
127
fade_background : rgb888 tuple
133
mapped_image[imask,0:3] = fade_background
135
ialpha = (1.0 - fade_alpha)
136
background = tuple(ialpha * x for x in fade_background)
137
image_region = mapped_image[imask,0:3]
138
image_region *= fade_alpha
139
image_region += background
140
mapped_image[imask,0:3] = image_region
143
def map_colors(data_array, steps, low, high, red_lut, green_lut, blue_lut,
145
'''Map colors from color lookup tables to a data array.
147
This is used in ColorMapper.map_screen
154
The number of steps in the color map (depth)
156
The low end of the data range
158
The high end of the data range
159
red_lut : ndarray of float32
160
The red channel lookup table
161
green_lut : ndarray of float32
162
The green channel lookup table
163
blue_lut : ndarray of float32
164
The blue channel lookup table
165
alpha_lut : ndarray of float32
166
The alpha channel lookup table
170
rgba: ndarray of float32
171
The rgba values of data_array according to the lookup tables. The shape
172
of this array is equal to data_array.shape + (4,).
175
range_diff = high - low
177
if range_diff == 0.0 or isinf(range_diff):
178
# Handle null range, or infinite range (which can happen during
179
# initialization before range is connected to a data source).
180
norm_data = 0.5*ones_like(data_array)
182
norm_data = clip((data_array - low) / range_diff, 0.0, 1.0)
185
nanmask = isnan(norm_data)
186
norm_data = where(nanmask, 0, (norm_data * (steps-1)).astype(int))
187
rgba = zeros(norm_data.shape+(4,), float32)
188
rgba[...,0] = where(nanmask, 0, take(red_lut, norm_data))
189
rgba[...,1] = where(nanmask, 0, take(green_lut, norm_data))
190
rgba[...,2] = where(nanmask, 0, take(blue_lut, norm_data))
191
rgba[...,3] = where(nanmask, 0, take(alpha_lut, norm_data))
195
def map_colors_uint8(data_array, steps, low, high, red_lut, green_lut, blue_lut,
197
'''Map colors from color lookup tables to a data array.
199
This is used in ColorMapper.map_screen
206
The number of steps in the color map (depth)
208
The low end of the data range
210
The high end of the data range
211
red_lut : ndarray of uint8
212
The red channel lookup table
213
green_lut : ndarray of uint8
214
The green channel lookup table
215
blue_lut : ndarray of uint8
216
The blue channel lookup table
217
alpha_lut : ndarray of uint8
218
The alpha channel lookup table
222
rgba: ndarray of uint8
223
The rgba values of data_array according to the lookup tables. The shape
224
of this array is equal to data_array.shape + (4,).
227
range_diff = high - low
229
if range_diff == 0.0 or isinf(range_diff):
230
# Handle null range, or infinite range (which can happen during
231
# initialization before range is connected to a data source).
232
norm_data = 0.5*ones_like(data_array)
234
norm_data = clip((data_array - low) / range_diff, 0.0, 1.0)
237
nanmask = isnan(norm_data)
238
norm_data = where(nanmask, 0, (norm_data * (steps-1)).astype('uint8'))
239
rgba = zeros(norm_data.shape+(4,), dtype='uint8')
240
rgba[...,0] = where(nanmask, 0, take(red_lut, norm_data))
241
rgba[...,1] = where(nanmask, 0, take(green_lut, norm_data))
242
rgba[...,2] = where(nanmask, 0, take(blue_lut, norm_data))
243
rgba[...,3] = where(nanmask, 0, take(alpha_lut, norm_data))