필터 지우기
필터 지우기

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

조회 수: 7 (최근 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