欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MATLAB 全景圖切割及盒圖顯示的實(shí)現(xiàn)步驟

 更新時(shí)間:2021年05月14日 10:46:59   作者:slandarer  
本文給大家分兩部分介紹,第一部分通過圖文的形式給大家介紹了全景圖切割的代碼,第二部分給大家介紹了盒圖展示效果的實(shí)現(xiàn)代碼,對MATLAB 全景圖切割相關(guān)知識(shí)感興趣的朋友,跟隨小編一起看看吧

part1 全景圖切割

原圖:

在這里插入圖片描述

切割效果:

在這里插入圖片描述
在這里插入圖片描述

以下是切割部分步驟:
舉這張圖為例,圖片格式hdr,jpg啥的都行:

在這里插入圖片描述

1.1 邊緣剔除

有些全景圖會(huì)自帶白灰色邊緣,若是直接進(jìn)行切割便會(huì)出現(xiàn)如下效果:

在這里插入圖片描述

這時(shí)候我們首先要對原圖進(jìn)行白邊剔除,代碼如下:

oriPic=imread('test.hdr');
[rows,cols,~]=size(oriPic);

for i=cols:-1:1
    tempListR=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListG=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListB=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(:,i,:)=[];
    else
        break;
    end
end
oriPic=oriPic(:,end:-1:1,:);
for i=size(oriPic,2):-1:1
    tempListR=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListG=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListB=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(:,i,:)=[];
    else
        break;
    end
end
oriPic=oriPic(:,end:-1:1,:);
for i=rows:-1:1
    tempListR=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListG=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListB=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(i,:,:)=[];
    else
        break;
    end
end
oriPic=oriPic(end:-1:1,:,:);
for i=size(oriPic,1):-1:1
    tempListR=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListG=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListB=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(i,:,:)=[];
    else
        break;
    end
end
oriPic=oriPic(end:-1:1,:,:);

1.2 圖像裁剪

我們要讓完成的就是如下的變換和裁剪:

在這里插入圖片描述
在這里插入圖片描述

這部分其實(shí)已經(jīng)有較為成熟的原理和代碼:
代碼參考:https://stackoverflow.com/questions/29678510/convert-21-equirectangular-panorama-to-cube-map

原理參考:
http://paulbourke.net/panorama/cubemaps/#1

http://paulbourke.net/panorama/cubemaps/

原理參考文章中更加清晰的變化圖:

在這里插入圖片描述

另:
在參考代碼的基礎(chǔ)上,對映射像素進(jìn)行了插值處理,可以使圖像更加平滑,原理如下:

在這里插入圖片描述
在這里插入圖片描述

主要函數(shù)代碼:

function resultPic=createCubeMapFace(oriPic,id,height,width)
    [M,N,~]=size(oriPic);
    resultPic=zeros([height,width,3]);
    an=sin(pi/4);
    ak=cos(pi/4);
    
    faceTransform=[0,0;
               pi/2,0;
               pi,0;
               -pi/2,0;
               0,-pi/2;
               0,pi];
    ftu=faceTransform(id,1);
    ftv=faceTransform(id,2);

    for y=0:height-1
        for x=0:width-1
            nx=y/height-0.5;
            ny=x/width-0.5;

            nx=nx*2*an;
            ny=ny*2*an;

            if (ftv == 0)
                u=atan2(nx, ak);
                v=atan2(ny*cos(u),ak);
                u=u+ftu;
            elseif(ftv>0)
                d=sqrt(nx*nx+ny*ny);
                v=pi/2-atan2(d,ak);
                u=atan2(ny,nx);
            else
                d=sqrt(nx*nx+ny*ny);
                v=-pi/2+atan2(d,ak);
                u=atan2(-ny,nx);
            end

            u=u/(pi);
            v=v/(pi/2);

            while(v<-1)
                v=v+2;
                u=u+1;
            end
            while(v>1)
                v=v-2;
                u=u+1;
            end
            while(u<-1)
                u=u+2;
            end
            while(u>1)
                u=u-2;
            end
            u=u/2+0.5;
            v=v/2+0.5;

            u=u*(N-1)+1;
            v=v*(M-1)+1;
            
            fv=floor(v);fv1=floor(v)+1;pv=v-fv;fv1(fv1>M)=M;
            fu=floor(u);fu1=floor(u)+1;pu=u-fu;fu1(fu1>N)=N;
            resultPic(x+1,y+1,:)=double(oriPic(fv,fu,:)).*(1-pv).*(1-pu)+...
                                 double(oriPic(fv1,fu,:)).*(pv).*(1-pu)+...
                                 double(oriPic(fv,fu1,:)).*(1-pv).*(pu)+...
                                 double(oriPic(fv1,fu1,:)).*(pv).*(pu);
        end
    end
    resultPic=uint8(resultPic);
end

函數(shù)調(diào)用及圖像存儲(chǔ):
這里后面長寬數(shù)值可以任意設(shè)定,但是要求長寬數(shù)值一致,如果按照當(dāng)前寫法,結(jié)果被存儲(chǔ)至result文件夾:

if ~exist('result','dir')
   mkdir('result');
end

for i=1:6
    resultPic=createCubeMapFace(oriPic,i,500,500);
    figure(i)
    imshow(resultPic)
    imwrite(resultPic,['result\',num2str(i),'.jpg'])
end

另: 如圖所示
圖片序號(hào)[1,2,3,4,5,6]分別對應(yīng)圖片[右,后,左,前,上,下]

在這里插入圖片描述

1.3 完整代碼

function panoramic2box
oriPic=imread('889027-884424860.jpg');
[rows,cols,~]=size(oriPic);

for i=cols:-1:1
    tempListR=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListG=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListB=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(:,i,:)=[];
    else
        break;
    end
end
oriPic=oriPic(:,end:-1:1,:);
for i=size(oriPic,2):-1:1
    tempListR=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListG=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    tempListB=oriPic(floor(rows/4):ceil(3*rows/4),i,1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(:,i,:)=[];
    else
        break;
    end
end
oriPic=oriPic(:,end:-1:1,:);
for i=rows:-1:1
    tempListR=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListG=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListB=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(i,:,:)=[];
    else
        break;
    end
end
oriPic=oriPic(end:-1:1,:,:);
for i=size(oriPic,1):-1:1
    tempListR=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListG=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    tempListB=oriPic(i,floor(cols/4):ceil(3*cols/4),1);
    if all(round(tempListR-mean(tempListR))==0)&&all(tempListR==tempListG)&&all(tempListR==tempListB)
        oriPic(i,:,:)=[];
    else
        break;
    end
end
oriPic=oriPic(end:-1:1,:,:);
% =========================================================================
if ~exist('result','dir')
   mkdir('result');
end

for i=1:6
    resultPic=createCubeMapFace(oriPic,i,500,500);
    figure(i)
    imshow(resultPic)
    imwrite(resultPic,['result\',num2str(i),'.jpg'])
end



% =========================================================================
function resultPic=createCubeMapFace(oriPic,id,height,width)
    [M,N,~]=size(oriPic);
    resultPic=zeros([height,width,3]);
    an=sin(pi/4);
    ak=cos(pi/4);
    
    faceTransform=[0,0;
               pi/2,0;
               pi,0;
               -pi/2,0;
               0,-pi/2;
               0,pi];
    ftu=faceTransform(id,1);
    ftv=faceTransform(id,2);

    for y=0:height-1
        for x=0:width-1
            nx=y/height-0.5;
            ny=x/width-0.5;

            nx=nx*2*an;
            ny=ny*2*an;

            if (ftv == 0)
                u=atan2(nx, ak);
                v=atan2(ny*cos(u),ak);
                u=u+ftu;
            elseif(ftv>0)
                d=sqrt(nx*nx+ny*ny);
                v=pi/2-atan2(d,ak);
                u=atan2(ny,nx);
            else
                d=sqrt(nx*nx+ny*ny);
                v=-pi/2+atan2(d,ak);
                u=atan2(-ny,nx);
            end

            u=u/(pi);
            v=v/(pi/2);

            while(v<-1)
                v=v+2;
                u=u+1;
            end
            while(v>1)
                v=v-2;
                u=u+1;
            end
            while(u<-1)
                u=u+2;
            end
            while(u>1)
                u=u-2;
            end
            u=u/2+0.5;
            v=v/2+0.5;

            u=u*(N-1)+1;
            v=v*(M-1)+1;
            
            fv=floor(v);fv1=floor(v)+1;pv=v-fv;fv1(fv1>M)=M;
            fu=floor(u);fu1=floor(u)+1;pu=u-fu;fu1(fu1>N)=N;
            resultPic(x+1,y+1,:)=double(oriPic(fv,fu,:)).*(1-pv).*(1-pu)+...
                                 double(oriPic(fv1,fu,:)).*(pv).*(1-pu)+...
                                 double(oriPic(fv,fu1,:)).*(1-pv).*(pu)+...
                                 double(oriPic(fv1,fu1,:)).*(pv).*(pu);
        end
    end
    resultPic=uint8(resultPic);
end
end

1.4 其他幾組切割結(jié)果

圖片源自:https://www.cgmodel.com/article/9004.html

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

part2 盒圖展示

2.1 曲面繪制

使用surf繪制各個(gè)曲面后,并為各個(gè)曲面貼圖:

for i=1:6
    oriPic.(['p',num2str(i)])=imread(['result\',num2str(i),'.jpg']);   
end
[rows,cols,~]=size(oriPic.p1);
[baseXY,baseZ]=meshgrid(1:cols,rows:-1:1);

ax=gca;hold(ax,'on')


surf(baseXY(:,end:-1:1)-(1+rows)/2,-(rows-1)./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p1,'EdgeColor','none','FaceColor','interp')
surf(-(rows-1)./2.*ones(size(baseXY)),baseXY-(1+rows)/2,baseZ,'CData',oriPic.p2,'EdgeColor','none','FaceColor','interp')
surf(baseXY-(1+rows)/2,(rows-1)./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p3,'EdgeColor','none','FaceColor','interp')
surf((rows-1)./2.*ones(size(baseXY)),baseXY(:,end:-1:1)-(1+rows)/2,baseZ,'CData',oriPic.p4,'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,ones(size(baseXY)),'CData',oriPic.p6(end:-1:1,end:-1:1,:),'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,rows-1+ones(size(baseXY)),'CData',oriPic.p5(:,end:-1:1,:),'EdgeColor','none','FaceColor','interp')

在這里插入圖片描述
在這里插入圖片描述

2.2 視角調(diào)整

通過設(shè)置axes屬性將視角調(diào)整至盒子里面

ax=axes('parent',fig,'position',[-0.45 -0.45 1.9 1.9]);hold(ax,'on')
ax.ZLim=[0,rows+1];
ax.XLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.YLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.Color=[0 0 0];
ax.CameraPosition=[0,0,rows/2];
ax.CameraPositionMode='manual';
ax.DataAspectRatio=[1,1,1];
ax.DataAspectRatioMode='manual';
ax.Projection='perspective';
ax.CameraTargetMode='manual';
ax.CameraViewAngle = 7;
ax.View=[-2.7391 90.0000];
ax.CameraTarget=[0 0 (rows-1)/2];
ax.Toolbar.Visible='on';

運(yùn)行后點(diǎn)擊那個(gè)三位旋轉(zhuǎn)按鈕即可開始漫游

在這里插入圖片描述

此時(shí)的盒圖是無縫隙版本,有縫隙版放在后面

在這里插入圖片描述

2.3 完整代碼

無縫隙版:

function showBox
for i=1:6
    oriPic.(['p',num2str(i)])=imread(['result\',num2str(i),'.jpg']);   
end
[rows,cols,~]=size(oriPic.p1);
[baseXY,baseZ]=meshgrid(1:cols,rows:-1:1);

fig=figure('units','pixels','position',[300 80 500 500],...
                       'Numbertitle','off','menubar','none','resize','off',...
                       'name','box');
                   

ax=axes('parent',fig,'position',[-0.45 -0.45 1.9 1.9]);hold(ax,'on')
ax.ZLim=[0,rows+1];
ax.XLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.YLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.Color=[0 0 0];
ax.CameraPosition=[0,0,rows/2];
ax.CameraPositionMode='manual';
ax.DataAspectRatio=[1,1,1];
ax.DataAspectRatioMode='manual';
ax.Projection='perspective';
ax.CameraTargetMode='manual';
ax.CameraViewAngle = 7;
ax.View=[-2.7391 90.0000];
ax.CameraTarget=[0 0 (rows-1)/2];
ax.Toolbar.Visible='on';




surf(baseXY(:,end:-1:1)-(1+rows)/2,-(rows-1)./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p1,'EdgeColor','none','FaceColor','interp')
surf(-(rows-1)./2.*ones(size(baseXY)),baseXY-(1+rows)/2,baseZ,'CData',oriPic.p2,'EdgeColor','none','FaceColor','interp')
surf(baseXY-(1+rows)/2,(rows-1)./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p3,'EdgeColor','none','FaceColor','interp')
surf((rows-1)./2.*ones(size(baseXY)),baseXY(:,end:-1:1)-(1+rows)/2,baseZ,'CData',oriPic.p4,'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,ones(size(baseXY)),'CData',oriPic.p6(end:-1:1,end:-1:1,:),'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,rows-1+ones(size(baseXY)),'CData',oriPic.p5(:,end:-1:1,:),'EdgeColor','none','FaceColor','interp')

end

在這里插入圖片描述

有縫隙版:

function showBox2
for i=1:6
    oriPic.(['p',num2str(i)])=imread(['result\',num2str(i),'.jpg']);   
end
[rows,cols,~]=size(oriPic.p1);
[baseXY,baseZ]=meshgrid(1:cols,rows:-1:1);

fig=figure('units','pixels','position',[300 80 500 500],...
                       'Numbertitle','off','menubar','none','resize','off',...
                       'name','box');
                   

ax=axes('parent',fig,'position',[-0.45 -0.45 1.9 1.9]);hold(ax,'on')
ax.ZLim=[0,rows+1];
ax.XLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.YLim=[0-(1+rows)/2,rows+1-(1+rows)/2];
ax.Color=[0 0 0];
ax.CameraPosition=[0,0,rows/2];
ax.CameraPositionMode='manual';
ax.DataAspectRatio=[1,1,1];
ax.DataAspectRatioMode='manual';
ax.Projection='perspective';
ax.CameraTargetMode='manual';
ax.CameraViewAngle = 7;
ax.View=[-2.7391 90.0000];
ax.CameraTarget=[0 0 (rows+1)/2];
ax.Toolbar.Visible='on';




surf(baseXY(:,end:-1:1)-rows/2,-rows./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p1,'EdgeColor','none','FaceColor','interp')
surf(-rows./2.*ones(size(baseXY)),baseXY-(1+rows)/2,baseZ,'CData',oriPic.p2,'EdgeColor','none','FaceColor','interp')
surf(baseXY-(1+rows)/2,rows./2.*ones(size(baseXY)),baseZ,'CData',oriPic.p3,'EdgeColor','none','FaceColor','interp')
surf(rows./2.*ones(size(baseXY)),baseXY(:,end:-1:1)-(1+rows)/2,baseZ,'CData',oriPic.p4,'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,zeros(size(baseXY)),'CData',oriPic.p6(end:-1:1,end:-1:1,:),'EdgeColor','none','FaceColor','interp')
surf(baseXY'-(1+rows)/2,baseXY-(1+rows)/2,rows+ones(size(baseXY)),'CData',oriPic.p5(:,end:-1:1,:),'EdgeColor','none','FaceColor','interp')

end

在這里插入圖片描述
在這里插入圖片描述

以上就是MATLAB 全景圖切割及盒圖顯示的詳細(xì)內(nèi)容,更多關(guān)于MATLAB 全景圖的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python中的subprocess.Popen()使用詳解

    python中的subprocess.Popen()使用詳解

    今天小編就為大家分享一篇python中的subprocess.Popen()使用詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • 使用Python繪制臺(tái)風(fēng)軌跡圖的示例代碼

    使用Python繪制臺(tái)風(fēng)軌跡圖的示例代碼

    這篇文章主要介紹了使用Python繪制臺(tái)風(fēng)軌跡圖的示例代碼,幫助大家更好的理解和使用python繪制圖形,感興趣的朋友可以了解下
    2020-09-09
  • Python for i in range ()用法詳解

    Python for i in range ()用法詳解

    今天小編就為大家分享一篇Python for i in range ()用法詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Matplotlib scatter繪制散點(diǎn)圖的方法實(shí)現(xiàn)

    Matplotlib scatter繪制散點(diǎn)圖的方法實(shí)現(xiàn)

    這篇文章主要介紹了Matplotlib scatter繪制散點(diǎn)圖的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • python爬蟲parsel-css選擇器的具體用法

    python爬蟲parsel-css選擇器的具體用法

    本文主要介紹了python爬蟲parsel-css選擇器的具體用法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • Python中文件讀取與保存代碼示例

    Python中文件讀取與保存代碼示例

    Python中保存文件是一項(xiàng)非?;镜娜蝿?wù),它允許我們將程序輸出保存到磁盤上,以便以后使用或與他人共享,這篇文章主要給大家介紹了關(guān)于Python中文件讀取與保存的相關(guān)資料,需要的朋友可以參考下
    2024-04-04
  • python3 中文亂碼與默認(rèn)編碼格式設(shè)定方法

    python3 中文亂碼與默認(rèn)編碼格式設(shè)定方法

    今天小編就為大家分享一篇python3 中文亂碼與默認(rèn)編碼格式設(shè)定方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • 詳解python?flask是如何預(yù)防CSRF攻擊

    詳解python?flask是如何預(yù)防CSRF攻擊

    CSRF(Cross-site?request?forgery)攻擊是一種常見的網(wǎng)絡(luò)安全漏洞,它可以通過欺騙用戶執(zhí)行惡意請求來攻擊?Web?應(yīng)用程序,本篇文章將介紹python?flask是如何預(yù)防CSRF攻擊,需要的朋友可以參考下
    2024-04-04
  • Django 請求Request的具體使用方法

    Django 請求Request的具體使用方法

    這篇文章主要介紹了Django 請求Request的具體使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • 關(guān)于Pandas?count()與values_count()的用法及區(qū)別

    關(guān)于Pandas?count()與values_count()的用法及區(qū)別

    這篇文章主要介紹了關(guān)于Pandas?count()與values_count()的用法及區(qū)別,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05

最新評(píng)論