how to draw a rectangle on the matlab.ui.control.image object?

17 ビュー (過去 30 日間)
Hakob Bazoyan
Hakob Bazoyan 2019 年 8 月 16 日
コメント済み: Hakob Bazoyan 2019 年 8 月 17 日
I have a matlab.ui.control.image object in my aplication class
classdef GreenScreenUI < matlab.apps.AppBase
properties (Access = public)
OriginalImage matlab.ui.control.Image
end
I'm loaging image in it
app.OriginalImage.ImageSource = app.vImage;
I have a rectangle rect = [x y width height]
How do I draw this rectangle on the image inside OriginalImage?

採用された回答

Hakob Bazoyan
Hakob Bazoyan 2019 年 8 月 17 日
After digging around, I found no way of programmatically drawing an existing rectangle on the matlab.ui.control.image object... Instead, I have used this technique:
  1. Insert Axes object on the app UI (app.OrgImageAxis in the sample below),
  2. Use imshow() providing the image, and set Axes object created in the previos step as Parent
  3. use rectangle() to draw rectangles on the axis created in first step...
app.vImage = imread(fullpath);
imshow(app.vImage, 'Parent', app.OrgImageAxis);
bl = app.GS.Blocks(iInd);
rect = [bl.iPosX bl.iPosY app.vCols app.vRows];
rectangle(app.OrgImageAxis, 'Position', rect);
Untitled.png
Anyway... if, nevertheless, anyone knows how to draw shapes directly on the matlab.ui.control.image object, could you please answer the question?

その他の回答 (1 件)

Image Analyst
Image Analyst 2019 年 8 月 17 日
If you want to draw a rectangle into the overlay above an image, use rectangle():
hold on;
rectangle('Position', [xleft, yTop, width, height]);
If you want to burn a line into an image at column col, use indexing and assignment:
yourImage(:, col, :) = 0; % Burn black line into column col.
If you want a grid, put the above line into two loops, one over columns, and a separtae one over rows.
  1 件のコメント
Hakob Bazoyan
Hakob Bazoyan 2019 年 8 月 17 日
Thanks for the answer.
I'm working on the application, not the plain script - on the script it's all straight forward, but in my application - I have 3 matlab.ui.control.image objects to which one hold command will refer to?
Also I thought that Matlab has efficient shape drawing functions, instead of me replacing pixels in nested loops.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by