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)
50分...重谢桐绝友宏圆 = =||function [ans1 ans2 ans3]=fff_sha(C)
[m n]=size(C)
c1=0.2
c2=0.5
c3=0.8
for i=1:m
for j=1:n
aaa=C(i,j)
if (aaa>=0)&&(aaa<=c1)
ans1(i,j)=0ans2(i,j)=0ans3(i,j)=1
continue
end
if (aaa>=c1)&&(aaa<局槐=c2)
ans1(i,j)=0ans2(i,j)=(c2-aaa)/(c2-c1)ans3(i,j)=(aaa-c1)/(c2-c1)
continue
end
if (aaa>=c2)&&(aaa<=c3)
ans1(i,j)=(c3-aaa)/(c3-c2)ans2(i,j)=(aaa-c2)/(c3-c2)ans3(i,j)=0
continue
end
if (aaa>=c3)&&(aaa<=1)
ans1(i,j)=1ans2(i,j)=0ans3(i,j)=0
continue
end
end
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)