Draw a line with matlab

1 回表示 (過去 30 日間)
oscillator
oscillator 2022 年 2 月 21 日
回答済み: Image Analyst 2022 年 2 月 21 日
Hi, out of personal interest I want to draw a single white line in a black background of 300x200 pixels using matlab.
How do I accomplish that?
could someone at least tell me wich functions I should use?
Thank you for your time
  2 件のコメント
Jan
Jan 2022 年 2 月 21 日
Do you want to draw a line in a figure on the screen, or create a matrix to be saved in a file? Do you want some anti-aliasing or just black and white pixels?
oscillator
oscillator 2022 年 2 月 21 日
I want a matrix in order to use imshow and see the picture in figure(1). Just black and white pixels, nothing complicated

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2022 年 2 月 21 日
If the row is to be in a certain row, you can do
imageArray(row, column1:column2) = 255;
If the row is to be in a certain column, you can do
imageArray(row1:row2, column) = 255;
If you want a line to go from one point to another (at an angle), you can use linspace():
xLine = round(linspace(x1, x2, 1000));
yLine = round(linspace(y1, y2, 1000));
for k = 1 : length(xLine)
imageArray(yLine(k), xLine(k)) = 255;
end

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by