MATLAB程序大全 - 图文 联系客服

发布时间 : 星期三 文章MATLAB程序大全 - 图文更新完毕开始阅读ee93ef4b03d276a20029bd64783e0912a3167c3b

☆★☆★☆

1.全景图到穹景图

这个程序我最初是用FreeImage写的,这两天改成了matlab,再不贴上来,我就要忘了。 看到一篇文章有这样的变换,挺有意思的,就拿来试了一下,文章点此。 全景图到穹顶图变换,通俗的说就是将全景图首尾相接做成一个圆环的样子。 先看下面这张图:

下面的矩形就是我们要处理的全景图,上面的矩形是变换后的图像。下面图像的底边对应穹顶图的内圆,顶边对应穹顶图的外圆,当然,反过来也是可以的。 程序流程:

1.定义穹顶图内圆和外圆的半径,变换后的像素就填充在这个内外半径的圆环中。

2.遍历穹顶图,当所处理当前像素位于圆环内,则通过极坐标反变换去全景图中寻找相应位置的像素进行填充。 3.遍历完图像就行了。

用的技巧和图像旋转或放大缩小都是类似的。 处理结果: 原图:

☆★☆★☆

结果:

matlab代码如下:

clear all; close all; clc;

img=imread('pan.jpg');

☆★☆★☆

imshow(img); [m,n]=size(img);

r1=100; %内环半径 r2=r1+m; %外环半径

imgn=zeros(2*r2,2*r2); [re_m,re_n]=size(imgn); for y=1:re_m for x=1:re_n

dis_x=x-re_n/2; dis_y=y-re_m/2;

l=sqrt(dis_x^2+dis_y^2); if l<=r2 && l>=r1 theta=0; if y>re_m/2

theta=atan2(dis_y,dis_x); end

if y

theta=pi+atan2(-dis_y,-dis_x); end if y==re_m/2

theta=atan2(dis_y,dis_x)+0.0001; end

xx=ceil(n*theta/(2*pi)); yy=ceil(l-r1);

if yy>=1 && yy<=m && xx>=1 && xx<=n imgn(y,x)=img(yy,xx); end end end end

figure;

imshow(imgn,[])

最后要说的是,一般我们要是有一张全景图,通常会用cubic映射,将图像变换为立方体的六个面,然后通过图形学方法贴到立方体上,就能做出类似谷歌街景的样子。cubic映射应该才是全景图最常用的处理方法,不过那又是另一类变换了。

☆★☆★☆

2.GUI保存图像

% --- Executes on button press in pushbutton5.

function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global src_img;

[filename,pathname] = uiputfile({'*.jpg';'*.bmp';'*.gif';'*.png';'*.tif'}, 'Write Pic'); str=[pathname filename]; if str~=0

imwrite(src_img,str); end

3.GUI读入图像

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

[filename,pathname] = uigetfile({'*.*';'*.jpg';'*.bmp';'*.gif';'*.png';'*.tif'},'Read Pic'); str = [pathname filename]; global src_img;

if ~isequal([pathname,filename],[0,0]) src_img = imread(str); axes(handles.axes1); imshow(src_img); end

4. GUI选项卡

1.在这个网址下载一个工具包,里面应该有四个文件:tabselectionfcp.p、tabselectionfcn.m、tabpanel.p和tabpanel.m,显然代码用.p格式进行加密了。 2.建立一个空GUI文件,就起名kong.fig吧。

3.在kong.fig上画一个Static Text,默认的tag为text1。 4.终端运行tabpanel('kong.fig','text1');命令,得到如下界面: