Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

matlab - increasing the resolution of a grayscale image

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...