<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
這篇的本質還是扭曲置換,其實看過前面幾篇文章的應該都能猜出是怎樣做到的,下面開始講解:
首先m檔案所在資料夾內應該有如下兩張圖:
此外還需要一張近似方形的圖片也要一起放在資料夾中,之後通過以下程式碼匯入和初步處理圖片(選擇幕布部分和去色程式碼,可左右滑動):
bkgPic=imread('bkg.jpg'); % 背景圖 screenPic=bkgPic(190:555,(190:555)+160,:);% 幕布區域圖片 grayscreenPic=rgb2gray(screenPic); % 灰度化幕布區域圖片 screenRange=imread('screenRange.jpg'); % 幕布範圍圖(用來扣幕布邊緣細節) screenRange=rgb2gray(screenRange); forePic=imread('2048.jpg'); % 要做成海報的圖片
我們可以看出幕布是有些傾斜的,我們為了讓圖片和幕布更加貼近,我們將圖片進行傾斜處理並將其調整至與幕布區域相似的大小:
% 前景圖片變形============================================================= tform=affine2d([1 -0.02 0;-0.02 1 0; 0 0 1]); forePic=imwarp(forePic,tform); exforePic=imresize(forePic,size(grayscreenPic)+26);
這部分參考之前布料貼圖的部分呀:
% 扭曲置換================================================================= for i=1:size(grayscreenPic,1) for j=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,:)); if sep1==0 c=double(exforePic(i+offsetLim1,j+offsetLim1,:)); else c=c2.*sep1+c1.*sep2; end newforePic(i,j,:)=c; end end
% 正交疊底================================================================= 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(screenRange>20)=newforePicR(screenRange>20); screenPicG(screenRange>20)=newforePicG(screenRange>20); screenPicB(screenRange>20)=newforePicB(screenRange>20); screenPic(:,:,1)=screenPicR; screenPic(:,:,2)=screenPicG; screenPic(:,:,3)=screenPicB; screenPic=uint8(screenPic);
% 將背景圖幕布區域換為新圖================================================= bkgPic(190:555,(190:555)+160,:)=screenPic; imshow(bkgPic)
function consPoster bkgPic=imread('bkg.jpg'); % 背景圖 screenPic=bkgPic(190:555,(190:555)+160,:);% 幕布區域圖片 grayscreenPic=rgb2gray(screenPic); % 灰度化幕布區域圖片 screenRange=imread('screenRange.jpg'); % 幕布範圍圖(用來扣幕布邊緣細節) screenRange=rgb2gray(screenRange); forePic=imread('2048.jpg'); % 要做成海報的圖片 % 前景圖片變形============================================================= tform=affine2d([1 -0.02 0;-0.02 1 0; 0 0 1]); forePic=imwarp(forePic,tform); exforePic=imresize(forePic,size(grayscreenPic)+26); % 扭曲置換================================================================= for i=1:size(grayscreenPic,1) for j=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,:)); if sep1==0 c=double(exforePic(i+offsetLim1,j+offsetLim1,:)); else c=c2.*sep1+c1.*sep2; end newforePic(i,j,:)=c; end end % 正交疊底================================================================= 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(screenRange>20)=newforePicR(screenRange>20); screenPicG(screenRange>20)=newforePicG(screenRange>20); screenPicB(screenRange>20)=newforePicB(screenRange>20); screenPic(:,:,1)=screenPicR; screenPic(:,:,2)=screenPicG; screenPic(:,:,3)=screenPicB; screenPic=uint8(screenPic); % imshow(screenPic) % 將背景圖幕布區域換為新圖================================================= bkgPic(190:555,(190:555)+160,:)=screenPic; imshow(bkgPic) end
以上就是利用Matlab一鍵生成工地海報特效的詳細內容,更多關於Matlab海報特效的資料請關注it145.com其它相關文章!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45