生成3个整数随机数代表rgb通道值, 即随机彩色
H = 400;
W = 600;
imgvertical = uint8(zeros(H,W,3));
imghorizontal = uint8(zeros(H,W,3));
leftThres = 100;
rightThres = 200;
pixelstep = 10; % 条纹大小
numsV = W / pixelstep;
numsH = H / pixelstep;
for i = 1:numsV
r = randi([leftThres,rightThres],1,3); % 改变left right, 即改变整体颜色
imgvertical(:,1 + (i - 1)*pixelstep:i * pixelstep,1) = r(1); % 竖条纹
imgvertical(:,1 + (i - 1)*pixelstep:i * pixelstep,2) = r(2);
imgvertical(:,1 + (i - 1)*pixelstep:i * pixelstep,3) = r(3);
end
for i = 1:numsH
r = randi([leftThres,rightThres],1,3); % 改变left right, 即改变整体颜色
imghorizontal(1 + (i - 1)*pixelstep:i * pixelstep,:,1) = r(1); % 竖条纹
imghorizontal(1 + (i - 1)*pixelstep:i * pixelstep,:,2) = r(2);
imghorizontal(1 + (i - 1)*pixelstep:i * pixelstep,:,3) = r(3);
end
figure
subplot(121)
imshow(imgvertical)
title('Vertical')
subplot(122)
imshow(imghorizontal)
title('Horizontal')
输出结果如下:
文章出处登录后可见!
已经登录?立即刷新