Questions tagged [image-resizing]

Image resizing is the downscaling or upscaling of an image. Dozens of algorithms exist, all with performance vs. quality tradeoffs.

Image resizing (also called image scaling) is the downsampling or up-sampling of an image using an interpolation algorithm. Common downscaling algorithms are Lanczos, Bicubic Sharper, Bicubic Smoother, Fant, Bicubic, Bilinear, and NearestNeighbor (listed in order of average result quality). Fractal algorithms often produce better results for upscaling photos, while there are many algorithms optimized for upscaling pixel art.

Due to algorithmic complexity, most developers use library implementations of these algorithms.

FreeImage

Offers CatmullRom, Lanczos3, bspline, box, bicubic, and bilinear filters. FreeImage focuses on implementation simplicity, and doesn't use hardware accelerations or SIMD extensions, so these speeds may not be acceptable for real-time display of images.

Windows GDI+

While loathed by many, GDI+ does include an excellent 2-pass Bicubic filter. It offers: 2-pass Bicubic, 1-pass bicubic, bilinear, and nearest neighbor. Those using it should be aware that it may add rings to images unless WrapMode is set to TileXY, as otherwise the algorithm samples data from outside the image bounds.

WIC (Windows Imaging Components)

The IWICBitmapScaler class offers Fant, 1-pass bicubic, bilinear, and nearest neighbor. Implementations are optimized for performance, and can be 2-4x faster than their GDI counterparts, although there isn't currently a 2-pass bicubic filter such as offered by GDI+

2188 questions
17
votes
2 answers

Python: How to resize an image using PIL module

I'm trying to resize an image to 500x500px but got this error: File "C:\Python27\lib\site-packages\PIL\Image.py", line 1681, in save save_handler = SAVE[format.upper()] KeyError: 'JPG' This is the code: from PIL import Image img =…
Doromi
  • 173
  • 1
  • 1
  • 5
17
votes
2 answers

Gnuplot: add key outside plot without resizing plot

In gnuplot, I can put the key outside the plots using this command: set key outside; set key right top; But as this page indicates, the placement of the key will automatically resize the plot area such that the size of the resulting image remains…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
16
votes
3 answers

Best Image Scaling Library

I have searched and found a few image scaling libraries for Java. But not sure which one to go with. I need to generate thumbnails from the image uploaded by server. It would be great if you can tell which one's good and bad. The list I have…
Mukun
  • 1,756
  • 10
  • 30
  • 57
16
votes
4 answers

Python: Image resizing: keep proportion - add white background

I would like to create a Python script to resize images, but not changing its proportions, just by adding a white background (So, a : 500*700 px image would transform to a 700*700 px image by adding 100 px of a white band on each side) The three…
Eli O.
  • 1,543
  • 3
  • 18
  • 27
16
votes
1 answer

How to resize SVG in Inkscape from A1 to A0

I am making a poster using Inkscape in SVG format. I have designed the poster in A1 but need to rescale it to A0 format. How can I perform the up-scaling?
Aeronaelius
  • 1,291
  • 3
  • 12
  • 31
15
votes
4 answers

MVC3/Razor thumbnail/resize image ideas?

Is there an easy and dynamic way to create thumbnails and resize images in MVC3/Razor? A helper, libary, anything? It would be nice, if I somehow could manage the size of the images from the controller. Or even in razorview. Example: In the index…
Kasper Skov
  • 1,954
  • 10
  • 32
  • 53
15
votes
5 answers

Resize an image to a square but keep aspect ratio c++ opencv

Is there a way of resizing images of any shape or size to say [500x500] but have the image's aspect ratio be maintained, levaing the empty space be filled with white/black filler? So say the image is [2000x1000], after getting resized to [500x500]…
MLMLTL
  • 1,519
  • 5
  • 21
  • 35
14
votes
6 answers

Resize images in PHP without using third-party libraries?

In one of my applications, I'm using the code snippet below to copy uploaded images to a directory. It works fine but copying large images (> 2MB) takes more time than ideal and I really don't need images this big, so, I'm looking for a way to…
Mateus
  • 2,640
  • 5
  • 44
  • 62
14
votes
4 answers

decrease image resolution in java

I need to reduce the size of image(not the width and height) using Java program. Is their any good API available for this? I need to reduce the size from 1MB to about 50kb - 100 kb's. Of-course the resolution will decrease but that doesn't matter.
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
14
votes
2 answers

How to resize a PyTorch tensor?

I have a PyTorch tensor of size (5, 1, 44, 44) (batch, channel, height, width), and I want to 'resize' it to (5, 1, 224, 224) How can I do that? What functions should I use?
Gerwe1s_Ji
  • 159
  • 1
  • 1
  • 5
14
votes
7 answers

how to fix "cannot import name 'imresize' error while this function importing from scipy.misc?

I'm using google colab for running python code and trying to downscale images. from keras.layers import Lambda import tensorflow as tf from skimage import data, io, filters import numpy as np from numpy import array from numpy.random import…
star123
  • 323
  • 2
  • 3
  • 9
14
votes
1 answer

why OpenCV cv2.resize gives different answer than MATLAB imresize?

I'm transferring a MATLAB code into python and trying to downscale an image using OpenCV function cv2.resize, But I get a different results from what MATLAB outputs. To make sure that my code is not doing anything wrong before the resize, I used a…
mxy
  • 331
  • 2
  • 9
13
votes
3 answers

download image from remote source and resize then save

Do any of you know of a good php class I can use to download an image from a remote source, re-size it to 120x120 and save it with a file name of my choosing? So basically I would have an image at "http://www.site.com/image.jpg" save to my web…
Ivar
  • 786
  • 2
  • 11
  • 21
13
votes
5 answers

Resize image without distortion keeping aspect ratio then crop excess using WideImage

I have an area on a site that I am working on that will display a users profile image that is pulled from an external source (therefore no control on its original size). What I am looking to do is take an image (in this example 1000px x 800px and…
lethalMango
  • 4,433
  • 13
  • 54
  • 92
13
votes
1 answer

Skimage - Weird results of resize function

I am trying to resize a .jpg image with skimage.transform.resize function. Function returns me weird result (see image below). I am not sure if it is a bug or just wrong use of the function. import numpy as np from skimage import io, color from…
Primoz
  • 1,324
  • 2
  • 16
  • 34