实验记录
脚本
Plot
x=-pi:pi/40:pi;
y=sin(x);
plot(x,y,'-r');
灰度直方图
G=imread ('cameraman.tif');
figure(1), imhist(G);
M = size(G,1);
N = size(G,2);
G=double(G);
for i=1:M
for j=1:N
if G(i,j)>=65
G(i,j)=1;
else
G(i,j)=0;
end
end
end
figure(1), imshow(G);
灰度图像边缘提取
edge 函数
I = imread('cameraman.tif');
BW1 =edge(I,'sobel');
figure(3),imshow(BW1);
BW2=edge(I,'roberts');
figure(4),imshow(BW2);
BW3 = edge(I,'log') ;
figure(5),imshow(BW3);
自定义绘制灰度直方图
G=imread('cameraman.tif');
M=size(G,1);
N=size(G,2);
sum=M*N;
for k=0:255
o=0;
for i=1:M
for j=1:N
if G(i,j)==k
o=o+1;
end
end
end
y(k+1)=o;
end
x=0:1:255;
plot(x,y,'-r');
自定义边缘提取函数
function y=selfedge(I,h,t)
I=double(I);
W= conv2(I,h);
M = size(W,1);
N = size(W,2);
for i=1:M
for j=1:N
if W(i,j)>=t
W(i,j)=1;
else
W(i,j)=0;
end
end
end
figure,imshow(W);
end