资源描述:
《用matlab对图像进行缩放与旋转.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、·%======用matlab对图像进行缩放(双线性插值法)clear; %此题是用双线性插值法实现图像缩放I=imread('f.jpg');%读入原图像,只需将此处的文件换成要变换的图片即可%图像属性% Filename:'f.jpg'% FileModDate:'24-Aug-200816:50:30'% FileSize:20372% Format:'jpg'% FormatVersion:''% Width:480%
2、 Height:640% BitDepth:8% ColorType:'grayscale'% FormatSignature:''% NumberOfSamples:1% CodingMethod:'Huffman'% CodingProcess:'Sequential'% Comment:{}[rows,cols]=size(I);K1=str2double(inputdlg('请输入行缩放倍数','INPUTscalefactor',1,{'0.
3、5'}));%行默认变为原来的0.5倍K2=str2double(inputdlg('请输入列缩放倍数','INPUTscalefactor',1,{'0.4'}));%列默认变为原来的0.4倍width=K1*rows; height=K2*cols;Out=uint8(zeros(width,height)); %创建输出图像矩阵widthScale=rows/width;heightScale=cols/height;forx=6:width-6 %6是为了防止矩阵超出边界溢
4、出 fory=6:height-6 oldX=x*widthScale; %oldX,oldY为原坐标,x,y为新坐标 oldY=y*heightScale; if(oldX/double(uint16(oldX))==1.0)&(oldY/double(uint16(oldY))==1.0) Out(x,y)=I(int16(oldX),int16(oldY));%若oldX,oldY为整数,直接赋值 else
5、 a=double(uint16(oldX)); b=double(uint16(oldY)); x11=double(I(a,b)); %x11赋值为I(a,b) x12=double(I(a,b+1)); %x12赋值为I(a,b+1) x21=double(I(a+1,b)); %x21赋值为I(a+1,b) x22=dou
6、ble(I(a+1,b+1)); %x22赋值为I(a+1,b+1) Out(x,y)=uint8((b+1-oldY)*((oldX-a)*x21+(a+1-oldX)*x11)+(oldY-b)*((oldX-a)*x22+(a+1-oldX)*x12)); %用双线性插值计算公式计算 end endendimshow(I);figure;imshow(Out);%===============使用matlab对图片进行缩放(最近邻域法)clear; %
7、此题是用最近邻域法实现图像缩放I=imread('f.jpg');%读入图像%图像属性% Filename:'f.jpg'% FileModDate:'24-Aug-200816:50:30'% FileSize:20372% Format:'jpg'% FormatVersion:''% Width:480% Height:640% BitDepth:8% ColorType:'graysca
8、le'% FormatSignature:''% NumberOfSamples:1% CodingMethod:'Huffman'% CodingProcess:'Sequential'% Comme