increasing the resolution of a grayscale image

有些话、适合烂在心里 提交于 2019-11-28 14:53:35

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 NaNs 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.

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]))) 

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!