?? matlab實用程序百例3.txt
字號:
imshow(flower)
colormap(copper)
n=size(X,1);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','輪廓圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 100 50 20],...
'callback',[...
'cla,',...
'[X,map]=imread(''flowers.tif'');,',...
'X=double(flower);,',...
'X=(0.25/256)*X;,',...
'C=copper(35);,',...
'set(gca,''colororder'',C(21:35,:),''box'',''on'');,',...
'imcontour(X,3);,',...
'axis([1 n 1 n]),',...
'axis(''ij''),',...
'axis(''square'')']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','偽彩圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 100 50 20],...
'callback',[...
'cla,',...
'D=-del2(X);,',...
'pcolor(D),',...
'axis([1 n 1 n]),',...
'axis(''ij''),',...
'shading(''flat'')']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','3D表面圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 100 50 20],...
'callback',[...
'cla,',...
'D=-del2(X);,',...
'surf(X,D),',...
'colormap(copper),',...
'axis([1 n 1 n 0 1]),',...
'axis(''ij''),',...
'shading(''flat''),',...
'view(-20,75);']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','關閉',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[80 50 80 30],...
'callback','close');
實例79:圖像邏輯操作
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','實例79');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
load imdemos bacteria
imshow(bacteria)
k1=~(bacteria>100);
k2=filter2(fspecial('laplacian'),bacteria);
k3=(k2>-4)&k1;
k4=erode(k1)&(k3==0);
[r,c]=find(k4);
k5=bwselect(k1,c,r);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','二值分割圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 110 50 20],...
'callback',[...
'cla,',...
'imshow(k1)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','濾波結果圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 110 50 20],...
'callback',[...
'cla,',...
'imshow(k2)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','閾值化圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 110 50 20],...
'callback',[...
'cla,',...
'imshow(k3)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','目標的核',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 60 50 20],...
'callback',[...
'cla,',...
'imshow(k4)']);
b5=uicontrol('parent',h0,...
'units','points',...
'tag','b5',...
'style','pushbutton',...
'string','目標分割圖',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 60 50 20],...
'callback',[...
'cla,',...
'imshow(k5)']);
b6=uicontrol('parent',h0,...
'units','points',...
'tag','b6',...
'style','pushbutton',...
'string','關閉',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 60 50 20],...
'callback','close');
實例80:進度條的使用
h0=figure('toolbar','none',...
'position',[198 56 350 450],...
'name','實例80');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.6 0.5],...
'visible','off');
I=imread('flowers.tif');
imshow(I)
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','轉換',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[50 80 60 25],...
'callback',[...
'handlek=waitbar(0,''initializing......'');,',...
'pause(0.5),',...
'i=1;,',...
'while i<=100,',...
'waitbar(i/100,handlek,[num2str(i),''%finished''],handlek),',...
'i=i+1;,',...
'pause(0.05),',...
'end,',...
'pause(1.5),',...
'cla,',...
'delete(handlek),',...
'Y=rgb2ntsc(I);,',...
'J=Y(:,:,1);,',...
'imshow(J)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','關閉',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[150 80 60 25],...
'callback','close');
例81:MRI數據的顯示
load mri
D = squeeze(D);
h0=figure('toolbar','none',...
'position',[198 56 450 468],...
'name','實例81');
h1=axes('parent',h0,...
'position',[0.3 0.45 0.5 0.5],...
'visible','off');
image_num = 8;
image(D(:,:,image_num))
axis image
colormap(map)
x = xlim;
y = ylim;
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[50 100 60 20],...
'string','二維圖',...
'callback',[...
'cla,',...
'contourslice(D,[],[],image_num),',...
'axis ij,',...
'xlim(x),',...
'ylim(y),',...
'daspect([1,1,1]),',...
'colormap(''default'')']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 100 60 20],...
'string','三維圖',...
'callback',[...
'cla,',...
'phandles = contourslice(D,[],[],[1,12,19,27],8);,',...
'view(3);,',...
'axis tight,',...
'set(phandles,''LineWidth'',2)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[50 50 60 20],...
'string','立體圖',...
'callback',[...
'cla,',...
'Ds = smooth3(D);,',...
'hiso = patch(isosurface(Ds,5),''FaceColor'',[1,.75,.65],''EdgeColor'',''none'');,',...
'hcap = patch(isocaps(D,5),''FaceColor'',''interp'',''EdgeColor'',''none'');,',...
'colormap(map),',...
'view(45,30),',...
'axis tight,',...
'daspect([1,1,.4]),',...
'lightangle(45,30),',...
'lighting phong,',...
'isonormals(Ds,hiso),',...
'set(hcap,''AmbientStrength'',.6),',...
'set(hiso,''SpecularColorReflectance'',0,''SpecularExponent'',50)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 50 60 20],...
'string','關閉',...
'callback','close');
實例82:圖像類型轉換
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','實例82');
h1=axes('parent',h0,...
'position',[0.2 0.45 0.5 0.5],...
'visible','off');
load earth
clims = [10 60];
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','強度圖像',...
'position',[30 120 50 20],...
'callback',[...
'cla,',...
'imagesc(X,clims),',...
'colormap(gray)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','索引圖像',...
'position',[100 120 50 20],...
'callback',[...
'cla,',...
'image(X),',...
'colormap(map),',...
'axis image']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','真彩圖像',...
'position',[170 120 50 20],...
'callback',[...
'cla,',...
'image(X),',...
'axis image']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','關閉',...
'position',[100 50 50 20],...
'callback','close');
實例83:特殊的圖像顯示技術
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','實例83');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','顏色條',...
'position',[30 120 50 20],...
'callback',[...
'cla,',...
'I = imread(''plane.jpg'');,',...
'imshow(I),',...
'colorbar']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'position',[100 120 50 20],...
'string','單幀顯示',...
'callback',[...
'cla,',...
'load mri,',...
'imshow(D(:,:,:,7))']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','動畫顯示',...
'position',[30 60 50 20],...
'callback',[...
'cla,',...
'load mri,',...
'montage(D,map),',...
'mov=immovie(D,map);,',...
'colormap(map),',...
'movie(mov)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','紋理映射',...
'position',[170 60 50 20],...
'callback',[...
'cla,',...
'[x,y,z] = cylinder;,',...
'I = imread(''girls.jpg'');,',...
'warp(x,z,y,I);']);
b5=uicontrol('parent',h0,...
'units','points',...
'tag','b5',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','關閉',...
'position',[100 60 50 20],...
'callback','close');
b6=uicontrol('parent',h0,...
'units','points',...
'tag','b6',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','多幀顯示',...
'position',[170 120 50 20],...
'callback',[...
'cla,',...
'load mri,',...
'montage(D,map)']);
實例84:圖像的幾何操作
h0=figure('toolbar','none',...
'position',[198 56 400 468],...
'name','實例84');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
I=imread('plane.jpg','jpg');
imshow(I)
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','圖像旋轉',...
'position',[200 120 50 20],...
'callback',[...
'cla,',...
'k=str2num(get(e1,''string''));,',...
'I=imread(''plane.jpg'',''jpg'');,',...
'J=imrotate(I,k,''bilinear'');,',...
'imshow(J)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','圖像剪切',...
'position',[200 80 50 20],...
'callback',[...
'cla,',...
'imshow plane.jpg,',...
'I=imcrop;,',...
'imshow(I)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','pushbutton',...
'string','關閉',...
'position',[120 30 50 20],...
'callback','close');
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','edit',...
'horizontalalignment','right',...
'position',[50 80 100 20]);
t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'backgroundcolor',[0.75 0.75 0.75],...
'style','text',...
'string','請輸入旋轉角度(0~90)度',...
'fontsize',12,...
'position',[40 100 130 20]);
實例85:拉個朗日插值
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -