Reduce the image to the final size
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;
    }
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);
	}
501617
def draw_final_outputs(img, results):
    
    if len(results) == 0:
        return img

    # Display in largest to smallest order to reduce occlusion
    boxes = np.asarray([r.box for r in results])
    areas = np_area(boxes)
    sorted_inds = np.argsort(-areas)

    ret = img
    tags = []

    for result_id in sorted_inds:
        r = results[result_id]
        if r.mask is not None:
            ret = draw_mask(ret, r.mask)

    for r in results:
        tags.append(
            "{},{:.2f}".format(cfg.DATA.CLASS_NAMES[r.class_id], r.score))
    ret = viz.draw_boxes(ret, boxes, tags)
    return ret
1284610
def iMath_truncate_intensity(image, lower_q, upper_q, n_bins=64):
    
    return iMath(image, 'TruncateIntensity', lower_q, upper_q, n_bins )
445849
def resize(fname, basewidth, opFilename):
    
    if basewidth == 0:
        basewidth = 300
    img = Image.open(fname)
    wpercent = (basewidth/float(img.size[0]))
    hsize = int((float(img.size[1])*float(wpercent)))
    img = img.resize((basewidth,hsize), Image.ANTIALIAS)
    img.save(opFilename)
710989
public void trimToSize() {
		modCount++;
		while ((bucketDepth > 0) && (bucketSize << ((bucketDepth-1)*bucketExp) >= size)) {
			bucket = (Object[]) bucket[0];
		}
	}
244553
public void truncate(int size) {

        m_buffer.truncate(size);
        m_position = Math.min(size, m_position);
    }
273137
def removeSinglePixels(img):
    '''
    
    '''

    gx = img.shape[0]
    gy = img.shape[1]

    for i in range(gx):
        for j in range(gy):

            if img[i, j]:

                found_neighbour = False
                for ii in range(max(0, i - 1), min(gx, i + 2)):
                    for jj in range(max(0, j - 1), min(gy, j + 2)):

                        if ii == i and jj == j:
                            continue

                        if img[ii, jj]:
                            found_neighbour = True
                            break
                    if found_neighbour:
                        break

                if not found_neighbour:
                    img[i, j] = 0
758960
def image_coarsen(xlevel=0, ylevel=0, image="auto", method='average'):
    
    if image == "auto": image = _pylab.gca().images[0]

    Z = _n.array(image.get_array())

    # store this image in the undo list
    global image_undo_list
    image_undo_list.append([image, Z])
    if len(image_undo_list) > 10: image_undo_list.pop(0)

    # images have transposed data
    image.set_array(_fun.coarsen_matrix(Z, ylevel, xlevel, method))

    # update the plot
    _pylab.draw()
288021
public void trimToSize() {
        modCount++;
        int oldCapacity = elementData.length;
        if (size < oldCapacity) {
            elementData = Arrays.copyOf(elementData, size);
        }
    }
561803
def crop_3dimage(img, beg_coords, end_coords):
    """"""

    cropped_img = img[
                  beg_coords[0]:end_coords[0],
                  beg_coords[1]:end_coords[1],
                  beg_coords[2]:end_coords[2]
                  ]

    return cropped_img
771044
def crop_to_fit(self, image_size, view_size):
        
        self.blipFill.crop(self._fill_cropping(image_size, view_size))
25957
def _decrease(self, resource):
        
        original_width, original_height = resource.size

        if original_width > self.value and original_height > self.value:
            target_width = original_width - self.value
            target_height = original_height - self.value

            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)

            return resource
        else:
            raise ValueError('Image dimensions less than or equal to filter value.')
1020877
private void scaleToOutputResolution(Image image) {

        float factor = m_sharedContext.getDotsPerPixel();
        if (factor != 1.0f) {
            image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor);
        }
    }
23471
def crop_2dimage(img, beg_coords, end_coords):
    """"""

    cropped_img = img[
                  beg_coords[0]:end_coords[0],
                  beg_coords[1]:end_coords[1],
                  ]

    return cropped_img
1216955
function shrinkImage(base64Image, targetSize) {

  return new Promise( (resolve, reject) => {

    let canvas  = document.createElement('canvas');
    let image   = new Image();

    image.onload = _ => {

      canvas.height = image.naturalHeight;
      canvas.width  = image.naturalWidth;

      canvas.getContext('2d').drawImage(image, 0, 0);

      return resolve(shrink(95));

      function shrink(quality) {
        let redrawnImage = canvas.toDataURL('image/jpeg', quality/100);

        // 1. Stop at zero because quality can't get any worse!
        // 2. Base64 encoded images are 1.33 times larger than once they are converted back to a blob.
        return quality !== 0 && redrawnImage.length / 1.33 > targetSize ? shrink(quality - 5) : redrawnImage;
      }

    };

    image.src = base64Image;

  });
}
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);
            });
        });
    }