📜  使用Matlab绘制孟加拉国国旗

📅  最后修改于: 2021-04-16 09:19:21             🧑  作者: Mango

先决条件: RGB图像表示
彩色图像可以表示为3阶矩阵。第一个顺序用于行,第二个顺序用于列,第三个顺序用于指定相应像素的颜色。在这里,我们使用RGB颜色格式,因此三阶将分别采用红色,绿色和蓝色的3个值。行和列的值取决于图像的大小。

方法:

  • 制作一个尺寸为300 X 400 X 3的3阶零矩阵。300表示行的像素数,400表示列的像素数,3表示RGB格式的颜色编码。
  • 将整个图像涂成深绿色。
  • 使用圆形方程将圆形涂成鲜红色。
    圆方程:
    ((x-h)^2 - (y-k)^2)=r^2 

    其中(h,k)是中心,(x,y)是x轴和y轴的坐标,并且是圆的半径。

下面是实现:

I=zeros(300, 400, 3);
% here image is of class ‘uint8’, the range of values
% that each colour component can have is [0 – 255]
I=uint8(I);
%painting the whole image Bottle Green
I(:, :, 1)=0;
I(:, :, 2)=106;
I(:, :, 3)=78;
%loop for rows i.e. for x-axis
for i=100:200
%loop for columns i.e. for y-axis
  for j=150:250
%The equation of circle to make the circle in the center.
    if round(sqrt((i-150)^2+(j-200)^2)<50)
% Paint the circle with Bright Red
      I(i, j, 1)=244;
      I(i, j, 2)=42;
      I(i, j, 3)=65;
       end % end if loop.
  end % end column loop.
  end % end row loop.
% show the image formed.
imshow(I);

输出: