A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan,
and allowing for center alignment if passed in.
322544
public static final @BetterImageSpanAlignment
  int normalizeAlignment(int alignment) {
    switch (alignment) {
      case DynamicDrawableSpan.ALIGN_BOTTOM:
        return ALIGN_BOTTOM;
      case ALIGN_CENTER:
        return ALIGN_CENTER;
      case DynamicDrawableSpan.ALIGN_BASELINE:
      default:
        return ALIGN_BASELINE;
    }
  }
769926
def kp_pan_px_center(self, viewer, event, data_x, data_y, msg=True):
        """"""
        if not self.canpan:
            return False
        self.pan_center_px(viewer)
        return True
684400
def normalize(x:TensorImage, mean:FloatTensor,std:FloatTensor)->TensorImage:
    ""
    return (x-mean[...,None,None]) / std[...,None,None]
428702
def standardize_images(x):
  """"""
  with tf.name_scope("standardize_images", values=[x]):
    x_shape = shape_list(x)
    x = to_float(tf.reshape(x, [-1] + x_shape[-3:]))
    x_mean = tf.reduce_mean(x, axis=[1, 2], keepdims=True)
    x_variance = tf.reduce_mean(
        tf.squared_difference(x, x_mean), axis=[1, 2], keepdims=True)
    num_pixels = to_float(x_shape[-2] * x_shape[-3])
    x = (x - x_mean) / tf.maximum(tf.sqrt(x_variance), tf.rsqrt(num_pixels))
    return tf.reshape(x, x_shape)
6214
def make_canonical_path(
        image_identifier, image_width, image_height,
        region, size, rotation, quality, format_str
):
    
    original_aspect_ratio = float(image_width) / image_height

    if (
        region == 'full' or
        # Use 'full' if 'square' is requested for an already square image
        (region == 'square' and image_width == image_height) or
        # Use 'full' if region exactly matches image dimensions
        (region == (0, 0, image_width, image_height))
    ):
        canonical_region = 'full'
    else:
        # Use explicit x,y,width,height region settings
        canonical_region = ','.join(map(str, region))

    if size in ['full', 'max']:
        canonical_size = 'full'
    elif (region[2:] == size and (image_width, image_height) == size):
        # Use 'full' if result image dimensions are unchanged from original
        # and are also unchanged from the region operation's output
        canonical_size = 'full'
    elif float(size[0]) / size[1] == original_aspect_ratio:
        # w, syntax for images scaled to maintain the aspect ratio
        canonical_size = '%d,' % size[0]
    else:
        # Full with,height size if aspect ratio is changed
        canonical_size = ','.join(map(str, size))

    canonical_rotation = ''
    if rotation[0]:
        # Image is mirrored
        canonical_rotation += '!'
    canonical_rotation += '%d' % rotation[1]

    canonical_quality = quality

    canonical_format = format_str

    return reverse(
        'iiif_image_api',
        args=[image_identifier, canonical_region, canonical_size,
              canonical_rotation, canonical_quality, canonical_format]
    )
871270
def centerize(src, dst_shape, margin_color=None):
    
    if src.shape[:2] == dst_shape[:2]:
        return src
    centerized = np.zeros(dst_shape, dtype=src.dtype)
    if margin_color:
        centerized[:, :] = margin_color
    pad_vertical, pad_horizontal = 0, 0
    h, w = src.shape[:2]
    dst_h, dst_w = dst_shape[:2]
    if h < dst_h:
        pad_vertical = (dst_h - h) // 2
    if w < dst_w:
        pad_horizontal = (dst_w - w) // 2
    centerized[pad_vertical:pad_vertical + h,
               pad_horizontal:pad_horizontal + w] = src
    return centerized
285477
function _reduceImageOptimFunc(prev, next) {
        return prev.then(function (res) {
            return Q.all(next.map(function (filename) {
                return modes[mode](new File(filename), algorithms, opts);
            }))
            .then(function (stepRes) {
                return res.concat(stepRes);
            });
        });
    }
1176964
def prepare_image(self, image):
        
        from decaf.util import transform  # soft dep
        _JEFFNET_FLIP = True

        # first, extract the 256x256 center.
        image = transform.scale_and_extract(transform.as_rgb(image), 256)
        # convert to [0,255] float32
        image = image.astype(np.float32) * 255.
        if _JEFFNET_FLIP:
            # Flip the image if necessary, maintaining the c_contiguous order
            image = image[::-1, :].copy()
        # subtract the mean
        image -= self.net_._data_mean
        return image
785643
def scale_images_0to1(slice1, slice2):
    """"""

    min_value = max(slice1.min(), slice2.min())
    max_value = max(slice1.max(), slice2.max())

    slice1 = (slice1 - min_value) / max_value
    slice2 = (slice2 - min_value) / max_value

    return slice1, slice2
1172454
function(imageIdentifier, callback) {
        this.headImage(imageIdentifier, function(err, res) {
            if (err) {
                return callback(err);
            }

            var headers = res.headers,
                prefix = 'x-imbo-original';

            callback(err, {
                width: parseInt(headers[prefix + 'width'], 10),
                height: parseInt(headers[prefix + 'height'], 10),
                filesize: parseInt(headers[prefix + 'filesize'], 10),
                extension: headers[prefix + 'extension'],
                mimetype: headers[prefix + 'mimetype']
            });
        });

        return this;
    }
1129577
def oneImageNLF(img, img2=None, signal=None):
    '''
    
    '''
    x, y, weights, signal = calcNLF(img, img2, signal)
    _, fn, _ = _evaluate(x, y, weights)
    return fn, signal
2453
private void fitImageToView() {
        Drawable drawable = getDrawable();
        if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
            return;
        }
        if (matrix == null || prevMatrix == null) {
            return;
        }

        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();

        //
        // Scale image for view
        //
        float scaleX = (float) viewWidth / drawableWidth;
        float scaleY = (float) viewHeight / drawableHeight;

        switch (mScaleType) {
            case CENTER:
                scaleX = scaleY = 1;
                break;

            case CENTER_CROP:
                scaleX = scaleY = Math.max(scaleX, scaleY);
                break;

            case CENTER_INSIDE:
                scaleX = scaleY = Math.min(1, Math.min(scaleX, scaleY));

            case FIT_CENTER:
                scaleX = scaleY = Math.min(scaleX, scaleY);
                break;

            case FIT_XY:
                break;

            default:
                //
                // FIT_START and FIT_END not supported
                //
                throw new UnsupportedOperationException("TouchImageView does not support FIT_START or FIT_END");

        }

        //
        // Center the image
        //
        float redundantXSpace = viewWidth - (scaleX * drawableWidth);
        float redundantYSpace = viewHeight - (scaleY * drawableHeight);
        matchViewWidth = viewWidth - redundantXSpace;
        matchViewHeight = viewHeight - redundantYSpace;
        if (!isZoomed() && !imageRenderedAtLeastOnce) {
            //
            // Stretch and center image to fit view
            //
            matrix.setScale(scaleX, scaleY);
            matrix.postTranslate(redundantXSpace / 2, redundantYSpace / 2);
            normalizedScale = 1;

        } else {
            //
            // These values should never be 0 or we will set viewWidth and viewHeight
            // to NaN in translateMatrixAfterRotate. To avoid this, call savePreviousImageValues
            // to set them equal to the current values.
            //
            if (prevMatchViewWidth == 0 || prevMatchViewHeight == 0) {
                savePreviousImageValues();
            }

            prevMatrix.getValues(m);

            //
            // Rescale Matrix after rotation
            //
            m[Matrix.MSCALE_X] = matchViewWidth / drawableWidth * normalizedScale;
            m[Matrix.MSCALE_Y] = matchViewHeight / drawableHeight * normalizedScale;

            //
            // TransX and TransY from previous matrix
            //
            float transX = m[Matrix.MTRANS_X];
            float transY = m[Matrix.MTRANS_Y];

            //
            // Width
            //
            float prevActualWidth = prevMatchViewWidth * normalizedScale;
            float actualWidth = getImageWidth();
            translateMatrixAfterRotate(Matrix.MTRANS_X, transX, prevActualWidth, actualWidth, prevViewWidth, viewWidth, drawableWidth);

            //
            // Height
            //
            float prevActualHeight = prevMatchViewHeight * normalizedScale;
            float actualHeight = getImageHeight();
            translateMatrixAfterRotate(Matrix.MTRANS_Y, transY, prevActualHeight, actualHeight, prevViewHeight, viewHeight, drawableHeight);

            //
            // Set the matrix to the adjusted scale and translate values.
            //
            matrix.setValues(m);
        }
        fixTrans();
        setImageMatrix(matrix);
    }
890443
function recolorImageWithCanvasContext(context, img, colorFunc) {
  if (!defined(context)) {
    throw new DeveloperError("No context for image recoloring.");
  }

  // Copy the image contents to the canvas
  context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  context.drawImage(img, 0, 0);
  var image = context.getImageData(
    0,
    0,
    context.canvas.width,
    context.canvas.height
  );
  image = ImageryProviderHooks.recolorImage(image, colorFunc);
  return image;
}
673505
function resetImage(/*evt*/) {
        if (currentScale == 1) return;
        var node = zoomNode, left, top, trans, w, h, pos, start, end, parent, flowTag;
        trans = getComputedTranslate(node);
        parent = node.parentNode;
        w = node.clientWidth * trans.scaleX;
        h = node.clientHeight * trans.scaleX;
        pos = getPosition(node);
        start = {
            left: (1 - trans.scaleX) * trans.offsetX + pos.left + trans.translateX,
            top: (1 - trans.scaleX) * trans.offsetY + pos.top + trans.translateY
        };
        end = {
            left: start.left + w,
            top: start.top + h
        };
        left = start.left;
        top = start.top;

        flowTag = overFlow(parent, {start: start, end: end});
        switch (flowTag) {
            case 1:
                left = viewScope.start.left;
                top = viewScope.end.top - h;
                break;
            case 2:
                left = viewScope.start.left;
                top = viewScope.start.top;
                break;
            case 3:
                left = viewScope.end.left - w;
                top = viewScope.end.top - h;
                break;
            case 4:
                left = viewScope.end.left - w;
                top = viewScope.start.top;
                break;
            case 5:
                top = viewScope.end.top - h;
                break;
            case 6:
                top = viewScope.start.top;
                break;
            case 7:
                left = viewScope.end.left - w;
                break;
            case 8:
                left = viewScope.start.left;
                break;
        }
        if (w < parent.clientWidth) {
            left = pos.left - (trans.scaleX - 1) * node.clientWidth / 2;
        }
        if (h < parent.clientHeight) {
            top = pos.top - (trans.scaleX - 1) * node.clientHeight / 2;
        }
        node.style.webkitTransitionDuration = '100ms';
        node.style.webkitTransform = generateTranslate(trans.translateX + left - start.left, trans.translateY + top - start.top, 0, trans.scaleX);

    }
1317877
function (image, old) {
        var data1 = old.data,
            data2 = image.data,
            w1 = old.width,
            w2 = image.width,
            px1 = old.globalOffset.x,
            py1 = old.globalOffset.y,
            px2 = image.globalOffset.x,
            py2 = image.globalOffset.y,
            b1 = old.bounds,
            b2 = image.bounds,
            px = Math.min(b1.minX + px1, b2.minX + px2), // global offset for new image (by min in bounds)
            py = Math.min(b1.minY + py1, b2.minY + py2),
            b = { // bounds for new image include all of the pixels [0,0,width,height] (reduce to bounds)
                minX: 0,
                minY: 0,
                maxX: Math.max(b1.maxX + px1, b2.maxX + px2) - px,
                maxY: Math.max(b1.maxY + py1, b2.maxY + py2) - py,
            },
            w = b.maxX + 1, // size for new image
            h = b.maxY + 1,
            i, j, k, k1, k2, len;

        var result = new Uint8Array(w * h);

        // copy all old image
        len = b1.maxX - b1.minX + 1;
        i = (py1 - py + b1.minY) * w + (px1 - px + b1.minX);
        k1 = b1.minY * w1 + b1.minX;
        k2 = b1.maxY * w1 + b1.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w1) {
            result.set(data1.subarray(k, k + len), i); // copy row
            i += w;
        }

        // copy new image (only "black" pixels)
        len = b2.maxX - b2.minX + 1;
        i = (py2 - py + b2.minY) * w + (px2 - px + b2.minX);
        k1 = b2.minY * w2 + b2.minX;
        k2 = b2.maxY * w2 + b2.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w2) {
            // walk through cols (X)
            for (j = 0; j < len; j++) {
                if (data2[k + j] === 1) result[i + j] = 1;
            }
            i += w;
        }

        return {
            data: result,
            width: w,
            height: h,
            bounds: b,
            globalOffset: {
                x: px,
                y: py,
            }
        };
    }
184960
function getBackgroundSize(image) {
	var x = image.properties.width / image.ratio;
	var y = image.properties.height / image.ratio;
	var template = _.template('<%= x %>px <%= y %>px');

	return template({x: x, y: y});
}
954687
function normalize(property, value, prefix){
  var result = value.toString(),
      args;

  /* Fixing the gradients */
  if (~result.indexOf('gradient(')) {

    /* Normalize color stops */
    result = result.replace(RE_GRADIENT_STOPS,'$1$4$3$2');

    /* Normalize legacy gradients */
    result = result.replace(RE_GRADIENT_VAL, function(){
        args = [].slice.call(arguments, 1);
        return normalizeGradient(args, prefix);
    });

    /* Adding prefixes to the legacy gradients */
    if (prefix) result = result.replace(RE_GRADIENT_TYPE, '-' + prefix + '-$1');
  }

  /* Adding prefixes to the `transform` values of legacy `transition` property */
  if (prefix && (property == "'transition'" || property == "'transition-property'")) {
    result = result.replace(RE_TRANSFORM, '-' + prefix + '-$1');
  }

  /* Removing `fill` keyword from the legacy `border-image` property */
  if (prefix && (property == "'border-image'" || property == "'border-image-slice'")) {
    result = result.replace(RE_FILL_KEYWORD, ' ');
  }

  return result;
}