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

11 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Hakob Bazoyan
Hakob Bazoyan am 17 Aug. 2019
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?

Weitere Antworten (1)

Image Analyst
Image Analyst am 17 Aug. 2019
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 Kommentar
Hakob Bazoyan
Hakob Bazoyan am 17 Aug. 2019
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.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by