Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0 

    @param float_img_buff: ROS Image to translate

    @type img: ros image

    @return a Opencv RGB image
8939
def depthToRGB8(float_img_buff, encoding):
    '''
    

    '''
    gray_image = None
    if (encoding[-3:-2]== "U"):
        gray_image = float_img_buff
    else:    
        float_img = np.zeros((float_img_buff.shape[0], float_img_buff.shape[1], 1), dtype = "float32")
        float_img.data = float_img_buff.data
        gray_image=cv2.convertScaleAbs(float_img, alpha=255/MAXRANGE)


    cv_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2RGB)

    return cv_image
896676
def copy_image_to_context(self, context, position, rotation=0, zoom=None):
        
        if not zoom:
            zoom = self.__zoom
        zoom_multiplicator = zoom * self.multiplicator
        context.save()
        context.scale(1. / zoom_multiplicator, 1. / zoom_multiplicator)

        image_position = round(position[0] * zoom_multiplicator), round(position[1] * zoom_multiplicator)
        context.translate(*image_position)
        context.rotate(rotation)
        context.set_source_surface(self.__image, 0, 0)

        context.paint()
        context.restore()
1129577
def oneImageNLF(img, img2=None, signal=None):
    '''
    
    '''
    x, y, weights, signal = calcNLF(img, img2, signal)
    _, fn, _ = _evaluate(x, y, weights)
    return fn, signal
336396
def uint8sc(im):
    
    im = np.asarray(im)
    immin = im.min()
    immax = im.max()
    imrange = immax - immin
    return cv2.convertScaleAbs(im - immin, alpha=255 / imrange)
482927
function getFloatScale( values, min, max, error ) {
	var mid = (min + max) / 2, range = mid - min,
		norm_8 = (range / INT8_MAX),
		norm_16 = (range / INT16_MAX),
		ok_8 = true, ok_16 = true,
		er_8 = 0, er_16 = 0,
		v, uv, er;

	// For the values given, check if 8-bit or 16-bit
	// scaling brings smaller error value
	for (var i=0, l=values.length; i<l; ++i) {

		// Test 8-bit scaling
		if (ok_8) {
			v = Math.round((values[i] - mid) / norm_8);
			uv = v * norm_8 + mid;
			er = (uv-v)/v;
			if (er > er_8) er_8 = er;
			if (er >= error) {
				ok_8 = false;
			}
		}

		// Test 16-bit scaling
		if (ok_16) {
			v = Math.round((values[i] - mid) / norm_16);
			uv = v * norm_16 + mid;
			er = (uv-v)/v;
			if (er > er_16) er_16 = er;
			if (er >= error) {
				ok_16 = false;
			}
		}

		if (!ok_8 && !ok_16)
			return [ 0, NUMTYPE.UNKNOWN ];
	}

	// Pick most appropriate normalization factor
	if (ok_8 && ok_16) {
		if (er_8 < er_16) {
			return [ norm_8, NUMTYPE.INT8 ];
		} else {
			return [ norm_16, NUMTYPE.INT16 ];
		}
	} else if (ok_8) {
		return [ norm_8, NUMTYPE.INT8 ];
	} else if (ok_16) {
		return [ norm_16, NUMTYPE.INT16 ];
	} else {
		return [ 0, NUMTYPE.UNKNOWN ];
	}

}
228880
def fastMean(img, f=10, inplace=False):
    '''
    
    '''
    s0,s1 = img.shape[:2]
    ss0 = int(round(s0/f))
    ss1 = int(round(s1/f))

    small = cv2.resize(img,(ss1,ss0), interpolation=cv2.INTER_AREA)
        #bigger
    k = {'interpolation':cv2.INTER_LINEAR}
    if inplace:
        k['dst']=img
    return cv2.resize(small,(s1,s0), **k)
1170144
def convert(self):
        
        (width, height) = self.img.size
        bgcolor = utils.term.bgcolor
        self.img.load()
        for y in range(height):
            for x in range(width):
                rgba = self.img.getpixel((x, y))
                if len(rgba) == 4 and rgba[3] == 0:
                    yield None
                elif len(rgba) == 3 or rgba[3] == 255:
                    yield xterm256.rgb_to_xterm(*rgba[:3])
                else:
                    color = grapefruit.Color.NewFromRgb(
                        *[c / 255.0 for c in rgba])
                    rgba = grapefruit.Color.AlphaBlend(color, bgcolor).rgb
                    yield xterm256.rgb_to_xterm(
                        *[int(c * 255.0) for c in rgba])
            yield "EOL"
944888
def to_grayscale(cv2im):
    """"""
    # How strongly does each position activate the output
    grayscale_im = np.sum(np.abs(cv2im), axis=0)

    # Normalize between min and 99th percentile
    im_max = np.percentile(grayscale_im, 99)
    im_min = np.min(grayscale_im)
    grayscale_im = np.clip((grayscale_im - im_min) / (im_max - im_min), 0, 1)

    grayscale_im = np.expand_dims(grayscale_im, axis=0)
    return grayscale_im
427887
def img(self):
        ''''''
        if self._img is not None:
            return self._img 
        self._img = cv2.cvtColor(self.original_img, cv2.COLOR_BGR2RGB)
        if self.border_width and self.border_colour is not None:
            cv2.rectangle(self._img, (0, 0), (self.width-1, self.height-1),
                          self.border_colour, self.border_width)
        return self._img
620404
def reduce_opacity(img, opacity):
    
    assert opacity >= 0 and opacity <= 1

    if img.mode != 'RGBA':
        img = img.convert('RGBA')
    else:
        img = img.copy()

    alpha = img.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    img.putalpha(alpha)

    return img
620709
def __scale_image(image, scale: float):
        
        height, width, _ = image.shape

        width_scaled = int(np.ceil(width * scale))
        height_scaled = int(np.ceil(height * scale))

        im_data = cv2.resize(image, (width_scaled, height_scaled), interpolation=cv2.INTER_AREA)

        # Normalize the image's pixels
        im_data_normalized = (im_data - 127.5) * 0.0078125

        return im_data_normalized
45482
def _clamp_rgb_coordinate(self, coord):
        
        if not self.is_upscaled:
            return min(max(coord, 0.0), 1.0)
        else:
            return min(max(coord, 1), 255)
845747
def get_image(roi_rec, short, max_size, mean, std):
    
    im = imdecode(roi_rec['image'])
    if roi_rec["flipped"]:
        im = im[:, ::-1, :]
    im, im_scale = resize(im, short, max_size)
    height, width = im.shape[:2]
    im_info = np.array([height, width, im_scale], dtype=np.float32)
    im_tensor = transform(im, mean, std)

    # gt boxes: (x1, y1, x2, y2, cls)
    if roi_rec['gt_classes'].size > 0:
        gt_inds = np.where(roi_rec['gt_classes'] != 0)[0]
        gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)
        gt_boxes[:, 0:4] = roi_rec['boxes'][gt_inds, :]
        gt_boxes[:, 4] = roi_rec['gt_classes'][gt_inds]
        # scale gt_boxes
        gt_boxes[:, 0:4] *= im_scale
    else:
        gt_boxes = np.empty((0, 5), dtype=np.float32)

    return im_tensor, im_info, gt_boxes
772899
def set_fg(self, r, g, b):
        
        self.img_fg = (r, g, b)
        self.redraw(whence=3)
113962
public static BufferedImage roate90(BufferedImage src) {
		int width = src.getWidth();
		int height = src.getHeight();

		BufferedImage bRotate = new BufferedImage(height, width, src.getType());
		for (int x = 0; x < width; x++)
			for (int y = 0; y < height; y++)
				bRotate.setRGB(height - 1 - y, x, src.getRGB(x, y));
		return bRotate;
	}
1249360
def intensity(image):
    '''
    '''
    if len(image.shape) > 2:
        # Convert to grayscale
        image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) / 255
    elif issubclass(image.dtype.type, np.integer):
        image /= 255
    return float(np.sum(image) / np.prod(image.shape))
1171140
def toint(number):
    
    if isinstance(number, float):
        if number > 1:
            number = round(number, 0)
        else:
            # The following solves when image has small dimensions (like 1x54)
            # then scale factor 1 * 0.296296 and `number` will store `0`
            # that will later raise ZeroDivisionError.
            number = round(math.ceil(number), 0)
    return int(number)