seems to be a more precise (but slower)
    way to down-scale an image
165763
def _coarsenImage(image, f):
    '''
    
    '''
    from skimage.morphology import square
    from skimage.filters import rank
    from skimage.transform._warps import rescale
    selem = square(f)
    arri = rank.mean(image, selem=selem)
    return rescale(arri, 1 / f, order=0)
144364
def linearize(wcsim, wcsima, wcsref, imcrpix, f, shift, hx=1.0, hy=1.0):
    
    x0 = imcrpix[0]
    y0 = imcrpix[1]
    p = np.asarray([[x0, y0],
                    [x0 - hx, y0],
                    [x0 - hx * 0.5, y0],
                    [x0 + hx * 0.5, y0],
                    [x0 + hx, y0],
                    [x0, y0 - hy],
                    [x0, y0 - hy * 0.5],
                    [x0, y0 + hy * 0.5],
                    [x0, y0 + hy]],
                   dtype=np.float64)
    # convert image coordinates to reference image coordinates:
    p = wcsref.wcs_world2pix(wcsim.wcs_pix2world(p, 1), 1).astype(ndfloat128)
    # apply linear fit transformation:
    p = np.dot(f, (p - shift).T).T
    # convert back to image coordinate system:
    p = wcsima.wcs_world2pix(
        wcsref.wcs_pix2world(p.astype(np.float64), 1), 1).astype(ndfloat128)

    # derivative with regard to x:
    u1 = ((p[1] - p[4]) + 8 * (p[3] - p[2])) / (6*hx)
    # derivative with regard to y:
    u2 = ((p[5] - p[8]) + 8 * (p[7] - p[6])) / (6*hy)

    return (np.asarray([u1, u2]).T, p[0])
1026007
def reduce_to_image(dimensions)
      {
        width: [dimensions[:width], image_file_width].min,
        height: [dimensions[:height], image_file_height].min
      }
    end
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
618992
def upscale(inputs, f, method=tf.image.ResizeMethod.NEAREST_NEIGHBOR):
  """"""
  height, width = shape_list(inputs)[1:3]  # pylint: disable=unbalanced-tuple-unpacking
  return tf.image.resize_images(inputs, (height * f, width * f), method)
40137
public void decreaseFontSize() {
        // move INTO range if we have just moved OUT of upper virtual
        if (inRange() || (atMax() && atUpperBoundary())) {
            currentFontIndex--;
        } else if (atMin()) {
            lowerVirtualCount--;
        } else if (atMax() && inUpper()) {
            upperVirtualCount--;
        }
    }
117578
def resetScale(self):
        """"""
        self.img.scale(1./self.imgScale[0], 1./self.imgScale[1])
        self.imgScale = (1.,1.)
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});
}
655445
def set_scale(self):
        """"""

        f_min = float(self.lower_freq)
        f_max = float(self.higher_freq)
        y_min = f_min
        y_max = f_max
        for y in range(self.image_height):
            freq = y_min + y / (self.image_height - 1.0) * (y_max - y_min)
            fft_bin = freq / f_max * (self.fft_size / 2 + 1)
            if fft_bin < self.fft_size / 2:
                alpha = fft_bin - int(fft_bin)
                self.y_to_bin.append((int(fft_bin), alpha * 255))
247165
def ReduceOpacity(im, opacity):
    
    assert opacity >= 0 and opacity <= 1
    if isalpha(im):
        im = im.copy()
    else:
        im = im.convert('RGBA')

    alpha = im.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    im.putalpha(alpha)
    return im
766531
protected function reduceImage()
    {
        $imResampled = imagecreatetruecolor($this->width, $this->height);
        imagecopyresampled($imResampled, $this->im,
            0, 0, 0, 0,
            $this->width, $this->height,
            $this->width*$this->scale, $this->height*$this->scale
        );
        imagedestroy($this->im);
        $this->im = $imResampled;
    }
1165773
public Bitmap approximateTileFromLowerZoom(final long pMapTileIndex) {
        for (int zoomDiff = 1; MapTileIndex.getZoom(pMapTileIndex) - zoomDiff >= OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL ; zoomDiff ++) {
            final Bitmap bitmap = approximateTileFromLowerZoom(pMapTileIndex, zoomDiff);
            if (bitmap != null) {
                return bitmap;
            }
        }
        return null;
    }
826651
function shrink(s,scale=1,square=false) {
       var btop =[],bbottom =[],bleft=[],bright=[];
       //var s = document.getElementsByTagName('svg')[3];
       var swidth = s.clientWidth;
       var sheight = s.clientHeight;


       s.removeAttribute('viewBox');


       [...s.children].forEach(c =>{
       var val = c.getBoundingClientRect();
       // filter points not on image
       if (isFinite(val.top)){btop.push(val.top)};
       if (isFinite(val.bottom)){bbottom.push(val.bottom)};
       if (isFinite(val.left)){bleft.push(val.left)};
       if (isFinite(val.right)){bright.push(val.right)};
       })
console.log(bleft)

       btop = Math.min(...btop)/sheight;
       bbottom = Math.max(...bbottom)/sheight;
       bleft = Math.min(...bleft)/swidth
       bright = Math.max(...bright)/swidth;

       var by= Math.abs(btop-bbottom)*sheight;
       var bx= Math.abs(bleft-bright)*swidth ;
              //btop = (btop <0)?0:btop;
              //bleft = (bleft <0)?0:bleft;
console.log(bleft,bright,bbottom,btop,bx,by,'cw',swidth,sheight)

       s.setAttribute('preserveAspectRatio',"none");
       scale += .5e-4
       console.log(''+ (bleft)*scale+' '+(btop)*scale+
        ' '+bx+' '+by)


       s.setAttribute('viewBox',''+

         (bleft)*scale*swidth+' '+(btop)*scale*sheight+
         ' '+bx+' '+by);
       scale += .5e-4
       s.setAttribute('preserveAspectRatio',"xMinYMin meet");


         s.style.width = bx*scale;
         s.style.height = by*scale;
       if (square){
         s.style.width = square;
         s.style.height = square;
       }

    /*if (loop >0 ){
      loop += 1
      shrink(s,scale=1,loop=loop)
    }  else{
       return s
    }*/
    return s
 }
382860
private BufferedImage scaleBuffered( BufferedImage input ) {
		int m = Math.max(input.getWidth(),input.getHeight());
		if( m <= controls.maxImageSize )
			return input;
		else {
			double scale = controls.maxImageSize/(double)m;
			int w = (int)(scale*input.getWidth()+0.5);
			int h = (int)(scale*input.getHeight()+0.5);

			// Use BoofCV to down sample since Graphics2D introduced too many aliasing artifacts
			BufferedImage output = new BufferedImage(w,h,input.getType());
			Planar<GrayU8> a = new Planar<>(GrayU8.class,input.getWidth(),input.getHeight(),3);
			Planar<GrayU8> b = new Planar<>(GrayU8.class,w,h,3);
			ConvertBufferedImage.convertFrom(input,a,true);
			AverageDownSampleOps.down(a,b);
			ConvertBufferedImage.convertTo(b,output,true);
			return output;
		}
	}
233995
def stretch(image, mask=None):
    '''
    '''
    image = np.array(image, float)
    if np.product(image.shape) == 0:
        return image
    if mask is None:
        minval = np.min(image)
        maxval = np.max(image)
        if minval == maxval:
            if minval < 0:
                return np.zeros_like(image)
            elif minval > 1:
                return np.ones_like(image)
            return image
        else:
            return (image - minval) / (maxval - minval)
    else:
        significant_pixels = image[mask]
        if significant_pixels.size == 0:
            return image
        minval = np.min(significant_pixels)
        maxval = np.max(significant_pixels)
        if minval == maxval:
            transformed_image = minval
        else:
            transformed_image = ((significant_pixels - minval) /
                                 (maxval - minval))
        result = image.copy()
        image[mask] = transformed_image
        return image
1163317
public static void reshapeDown(ImageBase image, int inputWidth, int inputHeight, int squareWidth) {
		int w = downSampleSize(inputWidth,squareWidth);
		int h = downSampleSize(inputHeight,squareWidth);

		image.reshape(w,h);
	}
405902
function _imageCopyResampledWorkaround(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        /*
        for ($i = 0; $i < imagecolorstotal($src_img); $i++)
        {
            $colors = ImageColorsForIndex ($src_img, $i);
            ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
        }
        */
        $scaleX = ($src_w - 1) / $dst_w;
        $scaleY = ($src_h - 1) / $dst_h;

        $scaleX2 = $scaleX / 2.0;
        $scaleY2 = $scaleY / 2.0;

        for ($j = $src_y; $j < $src_y + $dst_h; $j++)
        {
            $sY = $j * $scaleY;
            for ($i = $src_x; $i < $src_x + $dst_w; $i++)
            {
                $sX = $i * $scaleX;

                $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY + $scaleY2));
                $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY));
                $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY + $scaleY2));
                $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY));

                $red = (integer)(($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
                $green = (integer)(($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
                $blue = (integer)(($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);

                $color = ImageColorClosest($dst_img, $red, $green, $blue);
                ImageSetPixel($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y, $color);
            }
        }
    }