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

7 次查看(过去 30 天)
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