資源簡介
圖像插值算法有三種:最近鄰插值、雙線性插值和雙三次插值,這里有前兩種插值算法的matlab程序。

代碼片段和文件信息
%?THIS?PROGRAMME?IS?WRITTEN?BY?Rockins
%?THE?FEATURE?IS?BILINEAR-INTERPLOT?THE?SOUCE-IMAGE?TO?GET?A?DESTINATE-IMAGE
%?THE?MAXIMUM?SCALOR?==?5.0?THE?MINIMUM?SCALOR?==?0.2
%?Copyright?2006All?Copyrights?Reserved?by?Rockins
%?You?can?redistibute?this?programme?under?the?GNU?Less?GPL?license
%?If?you?have?any?question?about?this?programmeplease?contact?to?ybc2084@163.com
%?read?source?image?into?memoryand?get?the?primitive?rows?and?cols
I=imread(‘lena.jpg‘);
[nrowsncols]=size(I);
%?Next?line?is?the?scale-factorthe?range?is?0.2-5.0
K?=?str2double(inputdlg(‘please?input?scale?factor?(must?between?0.2?-?5.0)‘?‘INPUT?scale?factor‘?1?{‘0.5‘}));
%?Validating
if?(K?0.2)?|?(K?>?5.0)
????errordlg(‘scale?factor?beyond?permitted?range(0.2?-?5.0)‘?‘ERROR‘);
????error(‘please?input?scale?factor?(must?between?0.2?-?5.0)‘);
end
%?display?source?image
imshow(I);
%?output?image?width?and?height?are?both?scaled?by?factor?K
width?=?K?*?nrows;??????????????????????????????%?well512x512?is?just?for?convenienceyou?can?let?it?to?be?300x300400x400or?even?512x1024etc.
height?=?K?*?ncols;
J?=?uint8(zeros(widthheight));
%?width?scalor?and?height?scalor
widthScale?=?nrows/width;
heightScale?=?ncols/height;
%?bilinear?interplot
for?x?=?5:width?-?5?????????????????????????????%?this?index?range?is?to?avoid?exceeding?the?permitted?matrix?index
???for?y?=?5:height?-?5
???????xx?=?x?*?widthScale;?????????????????????%?xx?and?yy?are?the?source?ordinatewhile?x?and?y?are?the?destinate?ordinate
???????yy?=?y?*?heightScale;
???????if?(xx/double(uint16(xx))?==?1.0)?&?(yy/double(uint16(yy))?==?1.0)???????%?if?a?and?b?is?integerthen?J(xy)?<-?I(xy)
???????????J(xy)?=?I(int16(xx)int16(yy));
???????else?????????????????????????????????????%?a?or?b?is?not?integer
???????????a?=?double(uint16(xx));??????????????%?(ab)?is?the?base-dot
???????????b?=?double(uint16(yy));
???????????x11?=?double(I(ab));????????????????%?x11?<-?I(ab)
???????????x12?=?double(I(ab+1));??????????????%?x12?<-?I(ab+1)
???????????x21?=?double(I(a+1b));??????????????%?x21?<-?I(a+1b)
???????????x22?=?double(I(a+1b+1));????????????%?x22?<-?I(a+1b+1)??????????
???????????J(xy)?=?uint8(?(b+1-yy)?*?((xx-a)*x21?+?(a+1-xx)*x11)?+?(yy-b)?*?((xx-a)*x22?+(a+1-xx)?*?x12)?);????%?calculate?J(xy)
???????end
????end
end
%?show?the?interplotted?image
imwrite(J?‘lena2.jpg‘?‘jpg‘);
figure;
imshow(J);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄??????????0??2006-06-03?22:51??nearest
?????文件??????34184??2006-06-03?22:50??nearest\lena2.jpg
?????文件??????49292??2001-07-16?23:23??nearest\lena.jpg
?????文件???????2103??2006-06-03?22:50??nearest\nearest.m
?????文件??????34184??2006-06-03?22:50??nearest\lena2_nearest.jpg
?????文件??????31349??2006-06-03?22:48??nearest\lena2_bilinear.jpg
?????目錄??????????0??2006-05-30?19:35??bilinear
?????文件?????678912??2006-05-14?02:58??bilinear\雙線性插值程序說明.doc
?????文件???????2446??2006-06-03?22:46??bilinear\bilinear.m
?????文件??????49292??2001-07-16?23:23??bilinear\lena.jpg
?????文件??????31349??2006-06-03?22:48??bilinear\lena2.jpg
?????文件??????31349??2006-06-03?22:48??bilinear\lena2_bilinear.jpg
?????文件??????34184??2006-06-03?22:50??bilinear\lena2_nearest.jpg
-----------?---------??----------?-----??----
???????????????978644????????????????????13
- 上一篇:三相電壓型逆變器電壓閉環控制simuli
nk仿真模型 - 下一篇:自適應均衡器仿真
評論
共有 條評論