Apply value of quality parameter.

        For PIL docs see
        <http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.convert>
970838
def do_quality(self, quality):
        
        if (quality == 'grey' or quality == 'gray'):
            # Checking for 1.1 gray or 20.0 grey elsewhere
            self.logger.debug("quality: converting to gray")
            self.image = self.image.convert('L')
        elif (quality == 'bitonal'):
            self.logger.debug("quality: converting to bitonal")
            self.image = self.image.convert('1')
        else:  # color or default/native (which we take as color)
            # Deal first with conversions from I;16* formats which Pillow
            # appears not to handle properly, resulting in mostly white images
            # if we convert directly. See:
            # <http://stackoverflow.com/questions/7247371/python-and-16-bit-tiff>
            if (self.image.mode.startswith('I;16')):
                self.logger.debug("quality: fudged conversion from mode %s to I"
                                  % (self.image.mode))
                self.image = self.image.convert('I')
                self.image = self.image.point(lambda i: i * (1.0 / 256.0))
            if (self.image.mode not in ('1', 'L', 'RGB', 'RGBA')):
                # Need to convert from palette etc. in order to write out
                self.logger.debug("quality: converting from mode %s to RGB"
                                  % (self.image.mode))
                self.image = self.image.convert('RGB')
            else:
                self.logger.debug("quality: quality (nop)")
737381
def img_opacity(image, opacity):
    
    # Validate parameters
    assert 0 <= opacity <= 1, 'Opacity must be a float between 0 and 1'
    assert os.path.isfile(image), 'Image is not a file'

    # Open image in RGBA mode if not already in RGBA
    im = Image.open(image)
    if im.mode != 'RGBA':
        im = im.convert('RGBA')
    else:
        im = im.copy()

    # Adjust opacity
    alpha = im.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    im.putalpha(alpha)

    # Save modified image file
    dst = _add_suffix(image, str(str(int(opacity * 100)) + '%'), ext='.png')
    im.save(dst)
    return dst
69290
def image_postprocess(imagefile, output, size, crop, render):
    
    try:
        from PIL import Image
    except ImportError:
        import Image

    img = Image.open(imagefile)
    size_crop = None
    img_resized = img
    if size and crop and crop.lower() == 'true':
        width_raw, height_raw = img.size
        width, height = size
        height_better = int(height_raw * (float(width) / width_raw))
        if height < height_better:
            size_crop = (0, 0, width, height)

    try:
        if size_crop:
            size_better = width, height_better
            img_better = img.resize(size_better, Image.ANTIALIAS)
            img_resized = img_better.crop(size_crop)
        elif size:
            img_resized = img.resize(size, Image.ANTIALIAS)

        # If save with 'bmp' use default mode('RGBA'), it will raise:
        # "IOError: cannot write mode RGBA as BMP".
        # So, we need convert image mode
        # from 'RGBA' to 'RGB' for 'bmp' format.
        if render == 'bmp':
            img_resized = img_resized.convert('RGB')
        # Fix IOError: cannot write mode RGBA as XBM
        elif render == 'xbm':
            img_resized = img_resized.convert('1')
        # Works with either filename or file-like object
        img_resized.save(output, render)
    except KeyError:
        raise UnsupportedImageFormat
    except IOError as e:
        raise CaptureError(e)
1280251
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        resource_format = resource.format
        resource = resource.rotate(self.angle, expand=True)
        resource.format = resource_format

        return resource
259924
def convert_thumbnail_to_pil(thumbnail, mode='RGB'):
    """"""
    from PIL import Image
    if thumbnail.fmt == 0:
        size = (thumbnail.width, thumbnail.height)
        stride = thumbnail.widthbytes
        return Image.frombytes('RGBX', size, thumbnail.data, 'raw', mode,
                                stride)
    elif thumbnail.fmt == 1:
        return Image.open(io.BytesIO(thumbnail.data))
    else:
        raise ValueError('Unknown thumbnail format %d' % (thumbnail.fmt))
16043
def _normalize_params(image, width, height, crop):
    
    if width is None and height is None:
        raise ValueError("Either width or height must be set. Otherwise "
                         "resizing is useless.")

    if width is None or height is None:
        aspect = float(image.width) / float(image.height)

        if crop:
            raise ValueError("Cropping the image would be useless since only "
                             "one dimention is give to resize along.")

        if width is None:
            width = int(round(height * aspect))
        else:
            height = int(round(width / aspect))

    return (width, height, crop)
783012
def convertImagesToPIL(self, images, dither, nq=0):
        

        # Convert to PIL images
        images2 = []
        for im in images:
            if isinstance(im, Image.Image):
                images2.append(im)
            elif np and isinstance(im, np.ndarray):
                if im.ndim == 3 and im.shape[2] == 3:
                    im = Image.fromarray(im, 'RGB')
                elif im.ndim == 3 and im.shape[2] == 4:
                    im = Image.fromarray(im[:, :, :3], 'RGB')
                elif im.ndim == 2:
                    im = Image.fromarray(im, 'L')
                images2.append(im)

        # Convert to paletted PIL images
        images, images2 = images2, []

        # Adaptive PIL algorithm
        AD = Image.ADAPTIVE
        for im in images:
            im = im.convert('P', palette=AD, dither=dither)
            images2.append(im)

        # Done
        return images2
416258
def resize_image(image_str_tensor):
  """"""

  image = decode_and_resize(image_str_tensor)
  image = tf.image.encode_jpeg(image, quality=100)
  return image
1013865
def image_to_texture(image):
    """"""
    vtex = vtk.vtkTexture()
    vtex.SetInputDataObject(image)
    vtex.Update()
    return vtex
171060
public static <T extends ImageGray<T>>
	void scaleImageUp(T input , T output , int scale, InterpolatePixelS<T> interp ) {
		if( scale <= 1 )
			throw new IllegalArgumentException("Scale must be >= 2");
		if( input instanceof GrayF32) {
			ImplPyramidOps.scaleImageUp((GrayF32)input,(GrayF32)output,scale,(InterpolatePixelS)interp);
		} else if( input instanceof GrayU8) {
			ImplPyramidOps.scaleImageUp((GrayU8)input,(GrayU8)output,scale,(InterpolatePixelS)interp);
		} else {
			throw new IllegalArgumentException("Image type not yet supported");
		}
	}
974294
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        original_width, original_height = resource.size

        if self.start[0] < original_width or self.start[1] < original_height:
            left = self.start[0]
            upper = self.start[1]
        else:
            left = 0
            upper = 0

        right = self.start[0] + self.size[0]
        lower = self.start[1] + self.size[1]

        resource_format = resource.format
        resource = resource.crop(
            (
                left,
                upper,
                right if right < original_width else original_width,
                lower if lower < original_height else original_height
            )
        )
        resource.format = resource_format

        return resource
1012114
def convert(self, image, output=None):
        
        return self._convert(image, image.replace(Path(image).suffix, '.pdf') if not output else output)
62341
private void processParameters() throws IOException {
        type = JPEG2000;
        originalType = ORIGINAL_JPEG2000;
        inp = null;
        try {
            if (rawData == null){
                inp = url.openStream();
            }
            else{
                inp = new java.io.ByteArrayInputStream(rawData);
            }
            boxLength = cio_read(4);
            if (boxLength == 0x0000000c) {
                boxType = cio_read(4);
                if (JP2_JP != boxType) {
                    throw new IOException("Expected JP Marker");
                }
                if (0x0d0a870a != cio_read(4)) {
                    throw new IOException("Error with JP Marker");
                }

                jp2_read_boxhdr();
                if (JP2_FTYP != boxType) {
                    throw new IOException("Expected FTYP Marker");
                }
                Utilities.skip(inp, boxLength - 8);
                jp2_read_boxhdr();
                do {
                    if (JP2_JP2H != boxType) {
                        if (boxType == JP2_JP2C) {
                            throw new IOException("Expected JP2H Marker");
                        }
                        Utilities.skip(inp, boxLength - 8);
                        jp2_read_boxhdr();
                    }
                } while(JP2_JP2H != boxType);
                jp2_read_boxhdr();
                if (JP2_IHDR != boxType) {
                    throw new IOException("Expected IHDR Marker");
                }
                scaledHeight = cio_read(4);
                setTop(scaledHeight);
                scaledWidth = cio_read(4);
                setRight(scaledWidth);
                bpc = -1;
            }
            else if (boxLength == 0xff4fff51) {
                Utilities.skip(inp, 4);
                int x1 = cio_read(4);
                int y1 = cio_read(4);
                int x0 = cio_read(4);
                int y0 = cio_read(4);
                Utilities.skip(inp, 16);
                colorspace = cio_read(2);
                bpc = 8;
                scaledHeight = y1 - y0;
                setTop(scaledHeight);
                scaledWidth = x1 - x0;
                setRight(scaledWidth);
            }
            else {
                throw new IOException("Not a valid Jpeg2000 file");
            }
        }
        finally {
            if (inp != null) {
                try{inp.close();}catch(Exception e){}
                inp = null;
            }
        }
        plainWidth = getWidth();
        plainHeight = getHeight();
    }
1021736
def image_to_tf_summary_value(image, tag):
  
  curr_image = np.asarray(image, dtype=np.uint8)
  height, width, n_channels = curr_image.shape
  # If monochrome image, then reshape to [height, width]
  if n_channels == 1:
    curr_image = np.reshape(curr_image, [height, width])
  s = io.BytesIO()
  matplotlib_pyplot().imsave(s, curr_image, format="png")
  img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
                             height=height, width=width,
                             colorspace=n_channels)
  return tf.Summary.Value(tag=tag, image=img_sum)
236926
def apply (self, img):

        
        yup,uup,vup = self.getUpLimit()
        ydwn,udwn,vdwn = self.getDownLimit()

        ''' '''

        yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
        
        minValues = np.array([ydwn,udwn,vdwn],dtype=np.uint8)
        maxValues = np.array([yup,uup,vup], dtype=np.uint8)

        mask = cv2.inRange(yuv, minValues, maxValues)

        res = cv2.bitwise_and(img,img, mask= mask)


        return res
967533
def set_quality(self, quality):
        
        if isinstance(quality, *six.string_types):
            quality = int(quality)
        elif isinstance(quality, float):
            quality = int(quality)

        self._quality = validate_type(quality, type(None), *six.integer_types)
896952
function getSizeInPixels(el, value) {
    if (/px$/i.test(value)) return parseFloat(value);
    var style = el.style.left, runtimeStyle = el.runtimeStyle.left;
    el.runtimeStyle.left = el.currentStyle.left;
    el.style.left = value;
    var result = el.style.pixelLeft;
    el.style.left = style;
    el.runtimeStyle.left = runtimeStyle;
    return result;
  }