




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第利用Matlab一鍵生成工地海報(bào)特效目錄1.使用效果2.圖片準(zhǔn)備和導(dǎo)入3.圖像傾斜4.扭曲置換5.正交疊底6.緣修整(摳圖)7.背景圖像替換8.完整代碼
1.使用效果
這篇的本質(zhì)還是扭曲置換,其實(shí)看過(guò)前面幾篇文章的應(yīng)該都能猜出是怎樣做到的,下面開始講解:
2.圖片準(zhǔn)備和導(dǎo)入
首先m文件所在文件夾內(nèi)應(yīng)該有如下兩張圖:
此外還需要一張近似方形的圖片也要一起放在文件夾中,之后通過(guò)以下代碼導(dǎo)入和初步處理圖片(選擇幕布部分和去色代碼,可左右滑動(dòng)):
bkgPic=imread('bkg.jpg');%背景圖
screenPic=bkgPic(190:555,(190:555)+160,:);%幕布區(qū)域圖片
grayscreenPic=rgb2gray(screenPic);%灰度化幕布區(qū)域圖片
screenRange=imread('screenRange.jpg');%幕布范圍圖(用來(lái)扣幕布邊緣細(xì)節(jié))
screenRange=rgb2gray(screenRange);
forePic=imread('2048.jpg');%要做成海報(bào)的圖片
3.圖像傾斜
我們可以看出幕布是有些傾斜的,我們?yōu)榱俗寛D片和幕布更加貼近,我們將圖片進(jìn)行傾斜處理并將其調(diào)整至與幕布區(qū)域相似的大?。?/p>
%前景圖片變形=============================================================
tform=affine2d([1-0.020;-0.0210;001]);
forePic=imwarp(forePic,tform);
exforePic=imresize(forePic,size(grayscreenPic)+26);
4.扭曲置換
這部分參考之前布料貼圖的部分呀:
%扭曲置換=================================================================
fori=1:size(grayscreenPic,1)
forj=1:size(grayscreenPic,2)
goffset=(double(grayscreenPic(i,j))-128)/10;
offsetLim1=floor(goffset)+13;
offsetLim2=ceil(goffset)+13;
sep1=goffset-floor(goffset);
sep2=ceil(goffset)-goffset;
c1=double(exforePic(i+offsetLim1,j+offsetLim1,:));
c2=double(exforePic(i+offsetLim2,j+offsetLim2,:));
ifsep1==0
c=double(exforePic(i+offsetLim1,j+offsetLim1,:));
else
c=c2.*sep1+c1.*sep2;
newforePic(i,j,:)=c;
end
5.正交疊底
%正交疊底=================================================================
newforePic=uint8((double(newforePic).*double(grayscreenPic))./220);
%imshow(newforePic)
%舊版本的用下面這段代碼
%newforePicR=double(newforePic(:,:,1)).*double(grayscreenPic)./220;
%newforePicG=double(newforePic(:,:,2)).*double(grayscreenPic)./220;
%newforePicB=double(newforePic(:,:,3)).*double(grayscreenPic)./220;
%newforePic(:,:,1)=newforePicR;
%newforePic(:,:,2)=newforePicG;
%newforePic(:,:,3)=newforePicB;
%newforePic=uint8(newforePic);
6.緣修整(摳圖)
上方正交疊底后,幕布外面還是灰色,而且幕布內(nèi)容部分超出幕布范圍,我們可以用幕布范圍圖修整幕布:
%邊緣修整=================================================================
screenPicR=screenPic(:,:,1);newforePicR=newforePic(:,:,1);
screenPicG=screenPic(:,:,2);newforePicG=newforePic(:,:,2);
screenPicB=screenPic(:,:,3);newforePicB=newforePic(:,:,3);
screenPicR(screenRange20)=newforePicR(screenRange
screenPicG(screenRange20)=newforePicG(screenRange
screenPicB(screenRange20)=newforePicB(screenRange
screenPic(:,:,1)=screenPicR;
screenPic(:,:,2)=screenPicG;
screenPic(:,:,3)=screenPicB;
screenPic=uint8(screenPic);
7.背景圖像替換
%將背景圖幕布區(qū)域換為新圖=================================================
bkgPic(190:555,(190:555)+160,:)=screenPic;
imshow(bkgPic)
8.完整代碼
functionconsPoster
bkgPic=imread('bkg.jpg');%背景圖
screenPic=bkgPic(190:555,(190:555)+160,:);%幕布區(qū)域圖片
grayscreenPic=rgb2gray(screenPic);%灰度化幕布區(qū)域圖片
screenRange=imread('screenRange.jpg');%幕布范圍圖(用來(lái)扣幕布邊緣細(xì)節(jié))
screenRange=rgb2gray(screenRange);
forePic=imread('2048.jpg');%要做成海報(bào)的圖片
%前景圖片變形=============================================================
tform=affine2d([1-0.020;-0.0210;001]);
forePic=imwarp(forePic,tform);
exforePic=imresize(forePic,size(grayscreenPic)+26);
%扭曲置換=================================================================
fori=1:size(grayscreenPic,1)
forj=1:size(grayscreenPic,2)
goffset=(double(grayscreenPic(i,j))-128)/10;
offsetLim1=floor(goffset)+13;
offsetLim2=ceil(goffset)+13;
sep1=goffset-floor(goffset);
sep2=ceil(goffset)-goffset;
c1=double(exforePic(i+offsetLim1,j+offsetLim1,:));
c2=double(exforePic(i+offsetLim2,j+offsetLim2,:));
ifsep1==0
c=double(exforePic(i+offsetLim1,j+offsetLim1,:));
else
c=c2.*sep1+c1.*sep2;
newforePic(i,j,:)=c;
%正交疊底=================================================================
newforePic=uint8((double(newforePic).*double(grayscreenPic))./220);
%imshow(newforePic)
%舊版本的用下面這段代碼
%newforePicR=double(newforePic(:,:,1)).*double(grayscreenPic)./220;
%newforePicG=double(newforePic(:,:,2)).*double(grayscreenPic)./220;
%newforePicB=double(newforePic(:,:,3)).*double(grayscreenPic)./220;
%newforePic(:,:,1)=newforePicR;
%newforePic(:,:,2)=newforePicG;
%newforePic(:,:,3)=newforePicB;
%newforePic=uint8(newforePic);
%邊緣修整=================================================================
screenPicR=screenPic(:,:,1);newforePicR=newforePic(:,:,1);
screenPicG=screenPic(:,:,2);newforePicG=newforePic(:,:,2);
screenPicB=screenPic(:,:,3);newforePicB=newforePic(:,:,3);
screenPicR(screenRange20)=newforePicR(screenRange
screenPicG(screenRange20)=newforePicG(screenRange
screenPicB(screenRange20)=newforePicB(screenRange
screenPic(:,:,1)=screenPicR;
screenPic(:,:,2)=screenPicG;
screenPic(:,:,3)=screenPicB;
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 跟崗協(xié)議書范本
- 歐美減產(chǎn)協(xié)議書
- 公司聘用會(huì)計(jì)勞動(dòng)合同
- 避稅車位買賣合同協(xié)議
- 海外承包協(xié)議書
- 生活用水供應(yīng)合作合同協(xié)議
- 車位分期協(xié)議書范本
- 兒女贍養(yǎng)老人協(xié)議書
- 靈魂簽訂協(xié)議書
- 水田租賃協(xié)議書
- 高中英語(yǔ)教師研修-羅馬建筑文化課件
- 貨物驗(yàn)收單(模板)
- 幼兒園教學(xué)課件小班社會(huì)《孤獨(dú)的小熊》課件
- 復(fù)旦大學(xué)大學(xué)生創(chuàng)業(yè)導(dǎo)論課件06創(chuàng)業(yè)的商業(yè)計(jì)劃書
- 客訴客退經(jīng)濟(jì)處罰準(zhǔn)則及要求
- 醫(yī)療糾紛和解協(xié)議書(6篇)
- 293219民事訴訟法(第六版)教學(xué)PPT完整版課件全套ppt教學(xué)教程最全電子教案
- 人教版小學(xué)五年級(jí)數(shù)學(xué)競(jìng)賽試題及答案
- 農(nóng)村不動(dòng)產(chǎn)權(quán)籍調(diào)查工作指南
- 氧氣安全標(biāo)簽
- 管道天然氣改造普及工程(PE管)定向鉆專項(xiàng)施工方案
評(píng)論
0/150
提交評(píng)論