enhance contrast levels, or use full data range
        according to value of self.panel.conf.contrast_level
978454
def set_contrast_levels(self, contrast_level=None):
        
        if contrast_level is None:
            clevel = self.contrast_panel.choice.GetStringSelection()
            if clevel == 'None':
                contrast_level = 0
            else:
                contrast_level = float(clevel)

        conf = self.panel.conf
        img  = self.panel.conf.data
        if contrast_level is None:
            contrast_level = 0
        conf.contrast_level = contrast_level
        clevels = [contrast_level, 100.0-contrast_level]

        if len(img.shape) == 2: # intensity map
            col = 0
            jmin = imin = img.min()
            jmax = imax = img.max()
            self.cmap_panels[col].imin_val.SetValue('%.4g' % imin)
            self.cmap_panels[col].imax_val.SetValue('%.4g' % imax)

            jmin, jmax = np.percentile(img, clevels)
            if imax == imin:
                imax = imin + 0.5
            conf.cmap_lo[col] = xlo = (jmin-imin)*conf.cmap_range/(imax-imin)
            conf.cmap_hi[col] = xhi = (jmax-imin)*conf.cmap_range/(imax-imin)


            self.cmap_panels[col].cmap_hi.SetValue(xhi)
            self.cmap_panels[col].cmap_lo.SetValue(xlo)
            self.cmap_panels[col].islider_range.SetLabel('Shown: [ %.4g :  %.4g ]' % (jmin, jmax))
            self.cmap_panels[col].redraw_cmap()

        if len(img.shape) == 3: # rgb map
            for ix in range(3):
                jmin = imin = img[:,:,ix].min()
                jmax = imax = img[:,:,ix].max()
                self.cmap_panels[ix].imin_val.SetValue('%.4g' % imin)
                self.cmap_panels[ix].imax_val.SetValue('%.4g' % imax)

                jmin, jmax = np.percentile(img[:,:,ix], clevels)
                if imax == imin:
                    imax = imin + 0.5
                conf.cmap_lo[ix] = xlo = (jmin-imin)*conf.cmap_range/(imax-imin)
                conf.cmap_hi[ix] = xhi = (jmax-imin)*conf.cmap_range/(imax-imin)
                self.cmap_panels[ix].cmap_hi.SetValue(xhi)
                self.cmap_panels[ix].cmap_lo.SetValue(xlo)

                self.cmap_panels[ix].islider_range.SetLabel('Shown: [ %.4g :  %.4g ]' % (jmin, jmax))
                self.cmap_panels[ix].redraw_cmap()
        self.panel.redraw()
951449
def fill_opacity(value):
        
        if value.value:
            _assert_is_type('fill_opacity.value', value.value,
                            (float, int))
            if value.value < 0 or value.value > 1:
                raise ValueError(
                    'fill_opacity must be between 0 and 1')
1086315
def pixels(self, value: float) -> 'Size':
        """"""
        raise_not_number(value)
        self.maximum = '{}px'.format(value)
        return self
1351935
def configure_singlecolor_image(self, scale=False):
        
        # determine which channel to use
        self.image = self.data[self.singlecolorvar.get()]

        # scale the image by requested power
        self.image = np.power(self.image, self.singlecolorpower.get())

        # adjust the percentile thresholds
        lower = np.nanpercentile(self.image, self.singlecolormin.get())
        upper = np.nanpercentile(self.image, self.singlecolormax.get())
        self.image[self.image < lower] = lower
        self.image[self.image > upper] = upper

        # image values must be between (0,1) so scale image
        self.image /= np.nanmax(self.image)
781757
def _norm_kwargs(self, element, ranges, opts, vdim, values=None, prefix=''):
        
        dim_name = dim_range_key(vdim)
        if values is None:
            if isinstance(vdim, dim):
                values = vdim.apply(element, flat=True)
            else:
                expanded = not (
                    isinstance(element, Dataset) and
                    element.interface.multi and
                    (getattr(element, 'level', None) is not None or
                     element.interface.isscalar(element, vdim.name))
                )
                values = np.asarray(element.dimension_values(vdim, expanded=expanded))

        # Store dimension being colormapped for colorbars
        if prefix+'color_dim' not in self.handles:
            self.handles[prefix+'color_dim'] = vdim

        clim = opts.pop(prefix+'clims', None)

        # check if there's an actual value (not np.nan)
        if clim is None and util.isfinite(self.clim).all():
            clim = self.clim

        if clim is None:
            if not len(values):
                clim = (0, 0)
                categorical = False
            elif values.dtype.kind in 'uif':
                if dim_name in ranges:
                    clim = ranges[dim_name]['combined']
                elif isinstance(vdim, dim):
                    if values.dtype.kind == 'M':
                        clim = values.min(), values.max()
                    elif len(values) == 0:
                        clim = np.NaN, np.NaN
                    else:
                        try:
                            with warnings.catch_warnings():
                                warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
                                clim = (np.nanmin(values), np.nanmax(values))
                        except:
                            clim = np.NaN, np.NaN
                else:
                    clim = element.range(vdim)
                if self.logz:
                    # Lower clim must be >0 when logz=True
                    # Choose the maximum between the lowest non-zero value
                    # and the overall range
                    if clim[0] == 0:
                        clim = (values[values!=0].min(), clim[1])
                if self.symmetric:
                    clim = -np.abs(clim).max(), np.abs(clim).max()
                categorical = False
            else:
                range_key = dim_range_key(vdim)
                if range_key in ranges and 'factors' in ranges[range_key]:
                    factors = ranges[range_key]['factors']
                else:
                    factors = util.unique_array(values)
                clim = (0, len(factors)-1)
                categorical = True
        else:
            categorical = values.dtype.kind not in 'uif'

        if self.logz:
            if self.symmetric:
                norm = mpl_colors.SymLogNorm(vmin=clim[0], vmax=clim[1],
                                             linthresh=clim[1]/np.e)
            else:
                norm = mpl_colors.LogNorm(vmin=clim[0], vmax=clim[1])
            opts[prefix+'norm'] = norm
        opts[prefix+'vmin'] = clim[0]
        opts[prefix+'vmax'] = clim[1]

        cmap = opts.get(prefix+'cmap', opts.get('cmap', 'viridis'))
        if values.dtype.kind not in 'OSUM':
            ncolors = None
            if isinstance(self.color_levels, int):
                ncolors = self.color_levels
            elif isinstance(self.color_levels, list):
                ncolors = len(self.color_levels) - 1
                if isinstance(cmap, list) and len(cmap) != ncolors:
                    raise ValueError('The number of colors in the colormap '
                                     'must match the intervals defined in the '
                                     'color_levels, expected %d colors found %d.'
                                     % (ncolors, len(cmap)))
            try:
                el_min, el_max = np.nanmin(values), np.nanmax(values)
            except ValueError:
                el_min, el_max = -np.inf, np.inf
        else:
            ncolors = clim[-1]+1
            el_min, el_max = -np.inf, np.inf
        vmin = -np.inf if opts[prefix+'vmin'] is None else opts[prefix+'vmin']
        vmax = np.inf if opts[prefix+'vmax'] is None else opts[prefix+'vmax']
        if el_min < vmin and el_max > vmax:
            self._cbar_extend = 'both'
        elif el_min < vmin:
            self._cbar_extend = 'min'
        elif el_max > vmax:
            self._cbar_extend = 'max'

        # Define special out-of-range colors on colormap
        colors = {}
        for k, val in self.clipping_colors.items():
            if val == 'transparent':
                colors[k] = {'color': 'w', 'alpha': 0}
            elif isinstance(val, tuple):
                colors[k] = {'color': val[:3],
                             'alpha': val[3] if len(val) > 3 else 1}
            elif isinstance(val, util.basestring):
                color = val
                alpha = 1
                if color.startswith('#') and len(color) == 9:
                    alpha = int(color[-2:], 16)/255.
                    color = color[:-2]
                colors[k] = {'color': color, 'alpha': alpha}

        if not isinstance(cmap, mpl_colors.Colormap):
            if isinstance(cmap, dict):
                factors = util.unique_array(values)
                palette = [cmap.get(f, colors.get('NaN', {'color': self._default_nan})['color'])
                           for f in factors]
            else:
                palette = process_cmap(cmap, ncolors, categorical=categorical)
                if isinstance(self.color_levels, list):
                    palette, (vmin, vmax) = color_intervals(palette, self.color_levels, clip=(vmin, vmax))
            cmap = mpl_colors.ListedColormap(palette)
        if 'max' in colors: cmap.set_over(**colors['max'])
        if 'min' in colors: cmap.set_under(**colors['min'])
        if 'NaN' in colors: cmap.set_bad(**colors['NaN'])
        opts[prefix+'cmap'] = cmap
1012653
def adjust_brightness_contrast(image, brightness=0., contrast=0.):
    
    beta = 0
    # See the OpenCV docs for more info on the `beta` parameter to addWeighted
    # https://docs.opencv.org/3.4.2/d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19
    return cv2.addWeighted(image,
                           1 + float(contrast) / 100.,
                           image,
                           beta,
                           float(brightness))
61768
private void link(Range range, MinMaxPanel panel) {
		controlToData.put(panel, range);
		panel.setMax((int) range.getMax());
		panel.setMin((int) range.getMin());
		panel.setEnabledValue(range.isEnabled());
	}
106766
def set_pixel(self, x, y, value):
        
        if x < 0 or x > 7 or y < 0 or y > 15:
            # Ignore out of bounds pixels.
            return
        self.set_led((7 - x) * 16 + y, value)
81921
protected void findLocalScaleSpaceMax(PyramidFloat<T> ss, int layerID) {
		int index0 = spaceIndex;
		int index1 = (spaceIndex + 1) % 3;
		int index2 = (spaceIndex + 2) % 3;

		List<Point2D_I16> candidates = maximums[index1];
		ImageBorder_F32 inten0 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index0], 0);
		GrayF32 inten1 = intensities[index1];
		ImageBorder_F32 inten2 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index2], 0);

		float scale0 = (float) ss.scale[layerID - 1];
		float scale1 = (float) ss.scale[layerID];
		float scale2 = (float) ss.scale[layerID + 1];

		float sigma0 = (float) ss.getSigma(layerID - 1);
		float sigma1 = (float) ss.getSigma(layerID);
		float sigma2 = (float) ss.getSigma(layerID + 1);

		// not sure if this is the correct way to handle the change in scale
		float ss0 = (float) (Math.pow(sigma0, scalePower)/scale0);
		float ss1 = (float) (Math.pow(sigma1, scalePower)/scale1);
		float ss2 = (float) (Math.pow(sigma2, scalePower)/scale2);

		for (Point2D_I16 c : candidates) {
			float val = ss1 * inten1.get(c.x, c.y);

			// find pixel location in each image's local coordinate
			int x0 = (int) (c.x * scale1 / scale0);
			int y0 = (int) (c.y * scale1 / scale0);

			int x2 = (int) (c.x * scale1 / scale2);
			int y2 = (int) (c.y * scale1 / scale2);

			if (checkMax(inten0, val / ss0, x0, y0) && checkMax(inten2, val / ss2, x2, y2)) {
				// put features into the scale of the upper image
				foundPoints.add(new ScalePoint(c.x * scale1, c.y * scale1, sigma1));
			}
		}
	}
31686
def _panel_settings(setting, value, validate_value):
        """"""
        if validate_value:
            if (setting == CONST.SETTING_CAMERA_RESOLUTION
                    and value not in CONST.SETTING_ALL_CAMERA_RES):
                raise AbodeException(ERROR.INVALID_SETTING_VALUE,
                                     CONST.SETTING_ALL_CAMERA_RES)
            elif (setting in
                  [CONST.SETTING_CAMERA_GRAYSCALE,
                   CONST.SETTING_SILENCE_SOUNDS]
                  and value not in
                  CONST.SETTING_DISABLE_ENABLE):
                raise AbodeException(ERROR.INVALID_SETTING_VALUE,
                                     CONST.SETTING_DISABLE_ENABLE)

        return {setting: value}
954574
def pixel_intensity(pixel)
      (306 * (pixel.red & MAX_QUANTUM) + 601 * (pixel.green & MAX_QUANTUM) + 117 * (pixel.blue & MAX_QUANTUM)) / 1024
    end
559094
def enhance2dataset(dset):
    """"""
    attrs = dset.attrs
    img = get_enhanced_image(dset)
    # Clip image data to interval [0.0, 1.0]
    data = img.data.clip(0.0, 1.0)
    data.attrs = attrs

    return data
114151
public BlurBuilder contrast(float contrast) {
        data.preProcessors.add(new ContrastProcessor(data.contextWrapper.getRenderScript(), Math.max(Math.min(1500.f, contrast), -1500.f)));
        return this;
    }
243677
def adjust(colors, light):
    """"""
    raw_colors = colors[:1] + colors[8:16] + colors[8:-1]

    # Manually adjust colors.
    if light:
        for color in raw_colors:
            color = util.saturate_color(color, 0.5)

        raw_colors[0] = util.lighten_color(colors[-1], 0.85)
        raw_colors[7] = colors[0]
        raw_colors[8] = util.darken_color(colors[-1], 0.4)
        raw_colors[15] = colors[0]

    else:
        # Darken the background color slightly.
        if raw_colors[0][1] != "0":
            raw_colors[0] = util.darken_color(raw_colors[0], 0.40)

        raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE")
        raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
        raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")

    return raw_colors
1193346
def set_contrast(self, contrast):
        """"""
        if contrast < 0 or contrast > 255:
            raise ValueError('Contrast must be a value from 0 to 255 (inclusive).')
        self.command(SSD1306_SETCONTRAST)
        self.command(contrast)
913587
def setFullscreen(self, fullscreen):
        """"""
        if not fullscreen:
            self.ckBox_fullscreen.setChecked(False)
            self.parent().showNormal()
        else:
            self.ckBox_fullscreen.setChecked(True)
            self.parent().showFullScreen()
614645
def generic_adjust(colors, light):
    """"""
    if light:
        for color in colors:
            color = util.saturate_color(color, 0.60)
            color = util.darken_color(color, 0.5)

        colors[0] = util.lighten_color(colors[0], 0.95)
        colors[7] = util.darken_color(colors[0], 0.75)
        colors[8] = util.darken_color(colors[0], 0.25)
        colors[15] = colors[7]

    else:
        colors[0] = util.darken_color(colors[0], 0.80)
        colors[7] = util.lighten_color(colors[0], 0.75)
        colors[8] = util.lighten_color(colors[0], 0.25)
        colors[15] = colors[7]

    return colors