中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么利用Matlab一鍵生成工地海報特效

發布時間:2022-03-30 19:19:11 來源:億速云 閱讀:143 作者:iii 欄目:開發技術

本篇內容介紹了“怎么利用Matlab一鍵生成工地海報特效”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

1.使用效果

怎么利用Matlab一鍵生成工地海報特效

怎么利用Matlab一鍵生成工地海報特效

2.圖片準備和導入

首先m文件所在文件夾內應該有如下兩張圖:

怎么利用Matlab一鍵生成工地海報特效

怎么利用Matlab一鍵生成工地海報特效

此外還需要一張近似方形的圖片也要一起放在文件夾中,之后通過以下代碼導入和初步處理圖片(選擇幕布部分和去色代碼,可左右滑動):

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');               % 要做成海報的圖片

怎么利用Matlab一鍵生成工地海報特效

3.圖像傾斜

我們可以看出幕布是有些傾斜的,我們為了讓圖片和幕布更加貼近,我們將圖片進行傾斜處理并將其調整至與幕布區域相似的大小:

% 前景圖片變形=============================================================
tform=affine2d([1 -0.02 0;-0.02 1 0; 0 0 1]);
forePic=imwarp(forePic,tform);
exforePic=imresize(forePic,size(grayscreenPic)+26);

怎么利用Matlab一鍵生成工地海報特效

4.扭曲置換

這部分參考之前布料貼圖的部分呀:

怎么利用Matlab一鍵生成工地海報特效

% 扭曲置換=================================================================
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

怎么利用Matlab一鍵生成工地海報特效

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);

怎么利用Matlab一鍵生成工地海報特效

6.緣修整(摳圖)

上方正交疊底后,幕布外面還是灰色,而且幕布內容部分超出幕布范圍,我們可以用幕布范圍圖修整幕布:

% 邊緣修整=================================================================
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);

怎么利用Matlab一鍵生成工地海報特效

7.背景圖像替換

% 將背景圖幕布區域換為新圖=================================================
bkgPic(190:555,(190:555)+160,:)=screenPic;
imshow(bkgPic)

怎么利用Matlab一鍵生成工地海報特效

8.完整代碼

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一鍵生成工地海報特效”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

拉萨市| 嵊泗县| 内乡县| 南乐县| 洛川县| 曲麻莱县| 惠水县| 冕宁县| 静宁县| 崇左市| 兖州市| 彝良县| 神农架林区| 冕宁县| 天镇县| 扎囊县| 莲花县| 威信县| 石家庄市| 英山县| 福泉市| 衡水市| 雷州市| 泸西县| 安塞县| 洛隆县| 彭阳县| 德昌县| 建始县| 灌云县| 铁岭市| 盘锦市| 房山区| 隆德县| 双流县| 兰考县| 抚顺县| 石阡县| 太仆寺旗| 白河县| 垣曲县|