增加灰度图像的分辨率 [英] increasing the resolution of a grayscale image

查看:193
本文介绍了增加灰度图像的分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个灰度图像,需要提高其分辨率.如何在MATLAB中完成?例如,是否主要通过乘以图像尺寸来完成?

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?

推荐答案

您需要执行插值.有很多方法可以做到这一点.使用 imresize (例如,imgOut=imresize(img,scale,method);),或者没有图像处理工具箱,请考虑以下代码:

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

注意:这是一个粗略的开始.您许多人需要执行预过滤或其他转换.另外,此示例仅支持2D(灰度)图像.对于RGB,请使其适应于处理每个颜色平面,或者简单地循环处理每个平面.同样,这只是一个例子.

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.

除边缘处理外,它的结果与imresize相同,但关闭了抗锯齿功能(即imresize(...,'Antialiasing',false)).

Aside from edge handling, this gives the same results as imresize with anti-aliasing turned off (i.e. imresize(...,'Antialiasing',false)).

关于边缘处理,请参阅 interp2 的文档有关extrapval参数的信息.代码很丑陋,但是您可以在插值点(interp2输入)中修补最小/最大元素以简单地精确映射到边缘,或者可以对extrapval使用NaN并进行后处理imres替换其邻居的NaN等.请注意,仅在诸如linspace(1,size(I,1),rows) 的点进行插值不会给出预期的比例变化.

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.

这篇关于增加灰度图像的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆