%生成4个半径依次为10,30,50,100的圆
clc;
clear;
close all;
I = zeros(256,256); %定义一个256*256的灰度图
iter = [10 30 50 100];
for k=0:3
for i = 1:256
for j = 1:256
if sqrt((i-128)^2+(j-128)^2) <= iter(k+1);
I(i,j) = 1;
end
end
end
subplot(1,4,k+1);
imshow(I);
end
%生成4个矩形10*20,40,80,100
clc;
clear;
close all;
I = zeros(256,256);
width = 10;
iter = [20,40,60,80];
for k = 0:3
for i = 128-width/2:128+width/2
for j = (128-iter(k+1)):(128+iter(k+1))
I(j,i) = 1;
end
end
subplot(1,4,k+1);
imshow(I);
end