I have a grayscale image, and need to increase its resolution. How can this be done in MATLAB? Would it mainly be done by multiplying the dimensions of the image for instance?
3 Answers
You need to perform interpolation. There are many ways to do this. Use imresize
(e.g. imgOut=imresize(img,scale,method);
), or if you do not have the Image Processing Toolbox, consider the following code:
function imres = resizeim(I,outsize,interpalg)
if nargin<3 || isempty(interpalg),
interpalg='cubic';
end
rows=outsize(1);
cols=outsize(2);
vscale = size(I,1) / rows;
hscale = size(I,2) / cols;
imgClass = class(I);
imres = interp2(double(I), (1:cols)*hscale + 0.5 * (1 - hscale), ...
(1:rows)'*vscale + 0.5 * (1 - vscale), ...
interpalg);
imres = cast(imres,imgClass);
Note: This is a rough start. You many need to perform pre-filtering, or other transformations. Also, this example only supports 2D (grayscale) images. For RGB, adapt this to process each color plane, or simple process each plane in a loop. Again, this is just an example.
Aside from edge handling, this gives the same results as imresize
with anti-aliasing turned off (i.e. imresize(...,'Antialiasing',false)
).
Regarding edge handling, see the documentation for interp2
for information on the extrapval
parameter. The code gets ugly, but you can either patch the min/max elements in the interpolation points (interp2
inputs) to simply map exactly to the edges, or you can use NaN
for extrapval
, and post-process imres
to replace the NaN
s with its neighbor, etc. Note that simply interpolating at points such as linspace(1,size(I,1),rows)
will not give the expected scale change.

- 30,359
- 6
- 75
- 132
You can also perform sinc interpolation by Fourier transforming the image, zero-padding it, inverse Fourier transforming it, and taking the absolute value.
im_rz = abs(ifft2(padarray(fft2(im),[row_pad, col_pad])))

- 1,271
- 1
- 10
- 29
You can "hallucinate" high resolution details. See for example Glasner et al "Single image Super resolution" ICCV 2009.
An implementation of that algorithm can be found here

- 111,146
- 38
- 238
- 371