谁能给我一些有用的,好玩的MATLAB程序

谁能给我一些有用的,好玩的MATLAB程序,第1张

给你一个画心的程序,去表白吧:

[x,y,z]=meshgrid(linspace(-5,5,120))

f=(x.^2+(9*y.^2)./4+z.^2-1).^3-((9*y.^2).*(z.^3))./80-(x.^2).*(z.^3)

p=patch(isosurface(x,y,z,f,0))

set(p,'FaceColor','r')

grid on

daspect([1 1 1])

view(-30,24)

%%(1)题

I=imread('abc.jpg')

II=rgb2gray(I)

imshow(II)

for i=1:size(II,1)

for j=1:size(II,2)

if (0<=II(i,j) &&II(i,j)<=50)

III(i,j)=2

elseif (50<II(i,j) &&II(i,j)<=100)

III(i,j)=8

elseif (100<II(i,j) &&II(i,j)<=150)

III(i,j)=16

elseif (150<II(i,j) &&II(i,j)<=200)

III(i,j)=64

elseif(200<II(i,j) &&II(i,j)<=250)

III(i,j)=128

end

end

end

figure

imshow(III)

%%(2)题

x=linspace(0,2*pi,500)

for i=1:length(x)

if (x(i)<=pi)

y1(i)=1

else

y1(i)=0

end

if (x(i)<=pi)

y2(i)=x(i)/pi

else

y2(i)=(2*pi-x(i))/pi

end

y3(i)=sin(x(i))

end

figureplot(x,y1)

figureplot(x,y2)

figureplot(x,y3)

figure

subplot(1,3,1)plot(x,y1)

subplot(1,3,2)plot(x,y2)

subplot(1,3,3)plot(x,y3)

figureplot(x,y1,x,y2,x,y3)legend('方波','三角波','正弦')

%%(3)题

eps=0.001

xl=3fl=xl^3-xl^2-6*xl-7 %不支持函数就直接写。

xr=4fr=xr^3-xr^2-6*xr-7

while (1)

xm=(xl+xr)/2fm=xm^3-xm^2-6*xm-7

if (abs(fm)<eps)

break

elseif (fm*fl<0)

xr=xmfr=fm

else

xl=xmfl=fm

end

end

x=xm

f(x)

图像读取:

global I

% dialog for opening files

[imagefile , pathname]= uigetfile('*.tif')

if imagefile ~= 0

filename=[pathname imagefile]

[X,map]=imread(filename)

I=X

show_Callback(hObject, eventdata, handles)

set(handles.save,'enable','on')

end

图像保存:

global I

[imagefile , pathname, filterindex]= uiputfile({'*.tif','tif''*.*','All Files'},'Image Save As')

if (imagefile ~= 0 &filterindex==1)

filename=[pathname imagefile '.tif']

imwrite(I,filename)

else (imagefile ~= 0)

filename=[pathname imagefile]

imwrite(I,filename)

end

频域增强:

global I

J=imnoise(I,'salt &pepper',0.02)

%gei tuxiang tianjia yanjiao zaosheng

subplot(121),imshow(J)

title('han you zaosheng de yuan tuxiang')

J=double(J)

f=fft2(J)

g=fftshift(f)

[M,N]=size(f)

n=3d0=20

n1=floor(M/2)n2=floor(N/2)

for i=1:M

for j=1:N

d=sqrt((i-n1)^2+(j-n2)^2)

h=1/(1+0.414*(d/d0)^(2*n))

g(i,j)=h*g(i,j)

end

end

g=ifftshift(g)

g=uint8(real(ifft2(g)))

subplot(122),imshow(g)

title('san jie Butterworth lvbo tuxiang')


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11134804.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存