日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab数字图像处理实验一:图像的读取显示存储、平移镜像放大缩小及旋转

發(fā)布時間:2024/8/1 循环神经网络 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab数字图像处理实验一:图像的读取显示存储、平移镜像放大缩小及旋转 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

靈活運(yùn)用csdn來完成一下實(shí)驗(yàn)作業(yè)

  • 題目一:讀取、顯示、存儲
  • 題目二:平移、鏡像、放大、縮小、旋轉(zhuǎn)
    • 平移
    • 鏡像
    • 放大
    • 縮小
    • 旋轉(zhuǎn)

題目一:讀取、顯示、存儲

讀入一幅RGB圖像,變換為灰度圖像和二值圖像,并在同一個窗口內(nèi)分別顯示RGB圖像和灰度圖像,注上文字標(biāo)題,并將結(jié)果以文件形式存到磁盤上。
就靈活運(yùn)用一下百度。

a=imread('01.jpg') i=rgb2gray(a) I=im2bw(i,0.5) subplot(2,2,1);imshow(a);title('RGB'); %2x2的區(qū)域里的第一幅圖,標(biāo)題為RGB subplot(2,2,2);imshow(i);title('Gray'); subplot(2,2,3);imshow(I);title('Binary') imwrite(a,'01_rgb.jpg');imwrite(i,'01_gray.jpg');imwrite(I,'01_binary.jpg');

結(jié)果如下,哎就很煩不知道m(xù)atlab裝的時候出了什么問題不能顯示中文,但是用英文看起來很牛,淺用一下。

題目二:平移、鏡像、放大、縮小、旋轉(zhuǎn)

對圖像執(zhí)行平移、鏡像(水平鏡像、垂直鏡像)、放大、縮小及旋轉(zhuǎn)操作,其中放大、旋轉(zhuǎn)操作分別采用最近鄰插值及雙線性插值方法實(shí)現(xiàn),要求根據(jù)算法自己編寫代碼實(shí)現(xiàn),并分析兩種插值方法的優(yōu)缺點(diǎn)。
就matlab相關(guān)的真的很難找,是我搜索的關(guān)鍵詞不對嗎,csdn能不能努努力下次直接把我想要的給我推到最前面。
平移、鏡像、縮小的參考了這里
巧妙地抄了過來,參考網(wǎng)址里的代碼只能對灰度圖像進(jìn)行處理,我又靈活運(yùn)用了百度,加了顏色的處理。用原本的代碼平移有色圖像(學(xué)名叫啥啊不知道)的話會變成三張圖,就很牛嗷很牛。
最近鄰插值和雙線性插值的放大、旋轉(zhuǎn)參考了這里
淺刪了一下雙三次的,其他照搬,自信即巔峰!

平移

src=imread('u.jpg'); [m,n,c]=size(src); dst=zeros(m,n,c); left=[1,0,-50;0,1,-50;0,0,1]; for i=1:mfor j=1:nt=left*[i;j;1];if t(1,1)<=m&&t(2,1)<=n&&t(1,1)>=1&&t(2,1)>=1dst(t(1,1),t(2,1),:)=src(i,j,:);endend end subplot(1,2,1),imshow(uint8(src)),title('Src'); subplot(1,2,2),imshow(uint8(dst)),title('Dst');

鏡像

水平的:

src=imread('u.jpg'); [m,n,c]=size(src); dst=zeros(m,n,c); left=[1,0,0;0,-1,m;0,0,1]; for i=1:mfor j=1:nt=left*[i;j;1];if t(1,1)<=m&&t(2,1)<=n&&t(1,1)>=1&&t(2,1)>=1dst(t(1,1),t(2,1),:)=src(i,j,:);endend end subplot(1,2,1),imshow(uint8(src)),title('Origin'); subplot(1,2,2),imshow(uint8(dst)),title('Mirror Horizontally');

垂直的:

src=imread('u.jpg'); [m,n,c]=size(src); dst=zeros(m,n,c); left=[-1,0,n;0,1,0;0,0,1]; for i=1:mfor j=1:nt=left*[i;j;1];if t(1,1)<=m&&t(2,1)<=n&&t(1,1)>=1&&t(2,1)>=1dst(t(1,1),t(2,1),:)=src(i,j,:);endend end subplot(1,2,1),imshow(uint8(src)),title('Origin'); subplot(1,2,2),imshow(uint8(dst)),title('Mirror Vertically');

放大

srcimg=imread('u.jpg'); [srcWidth ,srcHeight,Color]=size(srcimg); dstWidth=srcWidth+50*2; dstHeight=srcHeight+50*2; dstimg0=zeros(dstWidth,dstHeight,Color,class(srcimg)); dstimg1=zeros(dstWidth,dstHeight,Color,class(srcimg)); for i=1:dstWidth %最近鄰插值for j=1:dstHeightfor n = 1:Colorsrc_i=i*(srcWidth/dstWidth);src_j=j*(srcHeight/dstHeight);dstimg0(i,j,n)=srcimg(round(src_i),round(src_j),n); endend end for i=1:dstWidth-1 %雙線性插值for j=1:dstHeight-1for n = 1:Colorsrc_i=i*(srcWidth/dstWidth);src_j=j*(srcHeight/dstHeight);src_ii=fix(src_i);src_iu=src_i - src_ii; src_jj=fix(src_j);src_jv=src_j - src_jj;if src_ii == 0 src_ii=src_ii+1;endif src_jj ==0 src_jj=src_jj+1;enddstimg1(i,j,n)=(1-src_iu)*(1-src_jv)*srcimg(src_ii,src_jj,n)+(1-src_iu)*src_jv*srcimg(src_ii,src_jj+1,n)+src_iu*(1-src_jv)*srcimg(src_ii+1,src_jj,n) +src_iu*src_jv*srcimg(src_ii+1,src_jj+1,n);endend end figure,imshow(srcimg),title('Origin'); figure,imshow(uint8(dstimg0)),title('Nearest Neighbor'); figure,imshow(dstimg1),title('Bilinear Interpolation');

縮小

src=imread('u.jpg'); [m,n,c]=size(src); dst=zeros(m,n,c,class(src)); left=[1/2,0,0;0,1/2,0;0,0,1]; for i=1:mfor j=1:nt=left*[i;j;1];if t(1,1)<=m&&t(2,1)<=n&&t(1,1)>=1&&t(2,1)>=1dst(round(t(1,1)),round(t(2,1)),:)=src(i,j,:);endend end subplot(1,2,1),imshow(uint8(src));subplot(1,2,2),imshow(uint8(dst));

旋轉(zhuǎn)

srcimg=imread('u.jpg'); srcimg=double(srcimg); [srcHeight,srcWidth,Color]=size(srcimg); angle=pi/6; dstWidth=srcWidth*cos(angle)+srcHeight*sin(angle); dstHeight=srcWidth*sin(angle)+srcHeight*cos(angle); dstHeight=ceil(dstHeight); dstWidth=ceil(dstWidth); u0=srcWidth*sin(angle); T=[cos(angle),sin(angle);-sin(angle),cos(angle)]; dstimg0=zeros(dstWidth,dstHeight,Color,class(srcimg)); dstimg1=zeros(dstWidth,dstHeight,Color,class(srcimg)); for u=1:dstWidth %最近鄰插值for v=1:dstHeightfor n=1:Colortem=T*([u;v]-[u0;0]); x=tem(1);y=tem(2); if x>=1 & x<=srcHeight & y>=1 & y<=srcWidth x_low=floor(x);x_up=ceil(x); y_low=floor(y);y_up=ceil(y); if (x-x_low)<=(x_up-x) x=x_low; elsex=x_up; endif (y-y_low)<=(y_up-y) y=y_low; elsey=y_up; endp1=srcimg(x_low,y_low,n); %雙線性插值p2=srcimg(x_up,y_low,n); p3=srcimg(x_low,y_low,n); p4=srcimg(x_up,y_up,n); s=x-x_low; t=y-y_low; dstimg0(u,v,n)=srcimg(x,y,n); dstimg1(u,v,n)=(1-s)*(1-t)*p1+(1-s)*t*p3+(1-t)*s*p2+s*t*p4; endendend end subplot(2,2,1),imshow(uint8(srcimg)),title('Origin'); subplot(2,2,2),imshow(uint8(dstimg0)),title('Nearest Neighbor'); subplot(2,2,3),imshow(dstimg1/255),title('Bilinear Interpolation');

總結(jié)

以上是生活随笔為你收集整理的matlab数字图像处理实验一:图像的读取显示存储、平移镜像放大缩小及旋转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。