程序.docx
《程序.docx》由会员分享,可在线阅读,更多相关《程序.docx(11页珍藏版)》请在冰豆网上搜索。
![程序.docx](https://file1.bdocx.com/fileroot1/2023-4/28/ac926793-4d81-41cd-861d-daf56f4472c1/ac926793-4d81-41cd-861d-daf56f4472c11.gif)
程序
x=0:
0.4*pi:
2*pi
y1=sin(x);y2=cos(x);y3=sin(x-0.1*pi);y4=cos(x+0.1*pi)
plot(y1)
plot(x,y1,x.y2,x,y3,x,y4)
x=-8:
0.5:
8
y=x
[X,Y]=meshgrid(x,y)
R=sqrt(X.^2+Y.^2)+eps
Z=sin(R)./R
mesh(X,Y,Z)
gridon
z=[15,35,10;20,10,30]
t=[0:
pi/20:
pi]
holdon
axis([04*pi-1010])
plot(t,10*sin(t),'r+:
')
plot(t,5*cos(t),'b*--:
')
xlabel('时间t');ylabel('幅值x');title('简单绘图实例')
legend('x1=10sin(t):
点画线','x2=5cost:
虚线')
gridon
grid
[X,map]=imread('canoe.tif')
image(X)
colormap(map)
I=imread('rice.png')
J=imread('cameraman.tif')
K=imsubract(I,J)
L=imsubract(I,120)
sel=strel('diamond',4)
seq=getsequence(sel)
I=imread('pout.tif')
imagesc(I,[01])
colormap(gray)
I=imread('greens.jpg')
image(RGB)
I=imread('trees.tif')
[X,map]=gray2ind(I,60)
imshow(X,map)
I=imread('cameraman.tif')
J=imadjust(I,[0,0.2],[0.51])
figure
subplot(121),imshow(I);subplot(122),imshow(J)
figure
subplot(121),imhist(I);subplot(122),imhist(J)
I=imread('eight.tif')
J1=imnoise(I,'salt&pepper',0.02)
J2=imnoise(I,'gaussian',0,0.01)
J3=imnoise(I,'poisson')
J4=imnoise(I,'speckle',0.04)
imshow(I)
figure
subplot(221),imshow(J1);subplot(222),imshow(J2)
subplot(223),imshow(J3);subplot(224),imshow(J4)
I=imread('eight.tif')
J=imnoise(I,'salt&pepper',0.02)
L=medfilt2(J)
subplot(131),imshow(I)
subplot(132),imshow(J)
subplot(133),imshow(L)
I=imread('rice.png')
I1=im2bw(I)
total=bwarea(I1)
subplot(121);imshow(I)
subplot(122);imcontour(I,3)
improfile
I=imread('rice.png')
I=imread('rice.png')
J=imread('cameraman.tif')
K=imsubtract(I,J)
L=imsubtract(I,120)
figure
subplot(221),imshow(I);subplot(222),imshow(J)
subplot(223),imshow(K);subplot(224),imshow(L)
J=imread('rice.png')
I=imread('cameraman.tif')
I1=im2bw(I)
J1=im2bw(J)
K1=I1&J1
K2=I1|J1
K3=~I1
K4=xor(I1,J1)
figure
subplot(221),imshow(I);subplot(222),imshow(J)
subplot(223),imshow(I1);subplot(224),imshow(J1)
figure
subplot(221),imshow(K1);subplot(222),imshow(K2)
subplot(223),imshow(K3);subplot(224),imshow(K4)
rgb=imread('a.jpg')
figure;imshow(rgb)
[X_no_dither,map]=rgb2ind(rgb,8,'nodither')
figure,subplot(121),imshow(X_no_dither,map)
[X_dither,map]=rgb2ind(rgb,8,'dither')
subplot(122),imshow(X_dither,map)
rgb=imread('a.jpg')
c=[12146410]
r=[10456129]
pixels=impixel(rgb,c,r)
imshowb.jpg
vals=impixel
I=imread('b.jpg')
x=[1942741677]
y=[964623733]
subplot(121),imshow(I)
subplot(122),improfile(I,x,y)
gridon
I1=imread('rice.png')
I2=imread('b.jpg')
m1=mean2(I1)
m2=mean2(I2)
s1=std(I1)
s2=std(I2)
r=corr2(I1,I2)
I=imread('circuit.tif')
BW1=edge(I,'prewitt')
BW2=edge(I,'log')
BW3=edge(I,'canny')
subplot(221),imshow(I)
subplot(222),imshow(BW1)
subplot(223),imshow(BW2)
subplot(224),imshow(BW3)
I=imread('c.jpg')
se=strel('line',11,90)
I1=imdilate(I,se)
subplot(121),imshow(I),title('原始图像')
subplot(122),imshow(I1),title('膨胀后的同像')
I=imread('cameraman。
tif')
se=strel('ball',5,5)
I1=imdilate(I,se)
subplot(121),imshow(I),title('原始图像')
subplot(122),imshow(I1),title('膨胀后的同像')
I=imread('cameraman。
tif')
I1=256-I
se=strel('ball',5,5)
I2=imdilate(I,se)
I3=256-I2
subplot(121),imshow(I),title('原始图像')
subplot(122),imshow(I3),title('膨胀后的同像')
I1=imread('circles.png')
subplot(131),imshow(I1),title('原始图像')
se=strel('rectangle',[4030])
I2=imerode(I1,se)
subplot(132),imshow(I2),title('腐蚀后的同像')
I3=imdilate(I2,se)
subplot(133),imshow(I3),title('先腐蚀后膨胀的图像')
I1=imread('circles.png')
subplot(131),imshow(I1),title('原始图像')
se=strel('disk',11)
I2=imerode(I1,se)
subplot(132),imshow(I2),title('腐蚀后的同像')
I3=imdilate(I2,se)
subplot(133),imshow(I3),title('先腐蚀后膨胀的图像')
I1=imread('circles.png')
subplot(121),imshow(I1),title('原始图像')
se=strel('disk',11)
I2=imopen(I1,se)
subplot(122),imshow(I2),title('开运算后的同像')
I=imread('a.jpg')
BW=imextendedmin(I,50)
subplot(121),imshow(I)
subplot(122),imshow(BW)
I=imread('a.jpg')
imshow(I,[])
improfile
BW1=imread('c.jpg')
c=[43185212]
r=[3868181]
BW2=bwselect(BW1,c,r,4)
subplot(121),imshow(BW1)
ssubplot(121),imshow(BW2)
BW1=imread('circbw.tif')
imshow(BW1)
BW1=imread('text.png')
se=ones(5)
BW2=imdilate(BW1,se)
increase=(bwarea(BW2)-bwarea(BW1))/bwarea(BW1)
BW1=imread('c.jpg')
se=ones(5)
BW2=imdilate(BW1,se)
increase=(bwarea(BW2)-bwarea(BW1))/bwarea(BW1)
BW=im2bw(imread('coins.png'))
BW1=imfill(BW,'holes')
subplot(121),imshow(BW),title('原始图像')
subplot(122),imshow(BW1);title('填充后的图像')
I=imread('rice.png')
I1=im2bw(I)
total=bwarea(I1)
I=imread('shuye.jpg')
se=strel('ball',5,5)
BW1=im2bw(I)
BW2=imopen(BW1,se)
subplot(121),imshow(BW1)
subplot(122),imshow(BW2)
total=bwarea(I)
image=imread('shuye.jpg')
image1=imresize('image',0.2)
image2=rgb2gray('image1')
figure
subplot(121),imshow(image1)
subplot(122),imshow(image2)
image=imread('shuye.jpg')
image1=imread('back.jpg')
grayscale=rgb2gray(image)
grayscale1=rgb2gray(image1)
subtract=imsubtract(grayscale1,grayscale)
figure
imshow(subtract)
R=imclearborder(subtract,8)
figure
imshow(R)
image2=imadjust(R)
figure
imshow(image2)
image3=imfill(image2,'holes')
figure
imshow(image3)
image4=edge(image2,'canny')
figure
imshow(image4)
I=strel('line',3,90)
image5=imdilate(image4,I)
figure
imshow(image5)
filled=imfill(image5,'holes')
figure
imshow(filled)
K=strel('diamond',1)
image6=imerode(filled,K)
image7=imerode(image5,K)
figure
imshow(image7)
image8=medfilt2(image7,[33])
figure
imshow(image8)
L=bwlabel(image8,8)
s=regionprops(L,'Area','Centroid')
k=ismember(L,find([s,Area]>=2200))
number=size(s,1)
area=[s.Area]
centroid=cat(1,s.Centroid)
imshow(k)
holdon
fori=1:
number
text(centroid(i,1),centroid(i,2),num2str(area(i)))
end