如何使用MATLAB绘制日本国旗 |
您所在的位置:网站首页 › 用java画国旗 › 如何使用MATLAB绘制日本国旗 |
先决条件:RGB 图像表示 MATLAB,也称为矩阵实验室,是一种数值计算环境和编程语言平台。它由 MathWorks 设计和开发。 MATLAB 是一个框架,它允许我们执行矩阵操作、实现算法、绘制函数和数据、创建用户界面以及与使用不同编程语言(如 C、C++、python、java 等)编写的程序进行交互。 如何在 MATLAB 中绘制彩色图像?彩色图像可以表示为 3 阶矩阵。一阶用于行,二阶用于列,三阶用于指定相应像素的颜色。这里我们使用 RGB 颜色格式,所以三阶将分别取红色、绿色和蓝色 3 个值。行和列的值取决于图像的大小。 日本国旗的画法: 制作一个具有维度 (300, 500, 3) 的 3 阶零矩阵,其中 300 表示行的像素数,600 表示行数,3 表示 RGB 格式的颜色编码。 首先将整个矩阵涂成白色。红色的 RGB 为 (255, 255, 255)。I(:, :, :)=255; 在行和列上应用循环并实现圆的方程,这样我们在旗帜的中心得到一个圆圈,并使用 RGB 格式将其着色为深红色。圆的方程:((x-h)^2 - (y-k)^2)=r^2其中 (h, k) 是圆心,(x, y) 是 x 轴和 y 轴的坐标,是圆的半径。深红荣耀颜色的 rgb 格式为 (188, 0, 45). 下面是代码: % create a 2-D matrix and paint it white I = uint8(zeros(300, 500, 3))+255; %the center point 1 through which the circle will pass circle_center1=150; %the center point 2 through which the circle will pass circle_center2=250; radius=6.32; % radius of the circle x=i; % x-axis co-ordinate y=j; % y-axis co-ordinate %loop for rows i.e. for x-axis for i = 101:200 %loop for columns i.e. for y-axis for j = 101:300 %applying the equation of circle to make the circle in the center. if round(sqrt((i-circle_center1)^2 + (j-circle_center2)^2)) < radius^2 % fill the circle with crimson glory % color using RGB color representation. I(i, j, 1) = 188; I(i, j, 2) = 0; I(i, j, 3) = 45; end end % end column loop. end % end row loop. % show the image formed. figure, imshow(I);输出: |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |