How to get normalized coordinates of an ROI?

4 ビュー (過去 30 日間)
Sonia Lenehan
Sonia Lenehan 2019 年 9 月 11 日
回答済み: Adam Danz 2019 年 9 月 11 日
I am drawing multiple regions of interest on an image and I need to document the position of each to inform anoother script. At the moment I am using the drawrectangle function but it is giving me the position of the ROI in pixels. How do I convert these pixels to normalized cooridinates? I have tried using property inspector and changing the units in there, but it does not work it seems.

採用された回答

Adam Danz
Adam Danz 2019 年 9 月 11 日
"How do I convert these pixels to normalized cooridinates? "
You can do the conversion yourself by dividing the ROI pixel dimensions by the pixel dimensions of the image.
Here's a working demo you can adjust to your needs.
% Load a matlab demo photo
img = imread('baby.jpg');
ims = imshow(img);
% draw ROI
r1 = drawrectangle('Color',[1 0 0]);
% Get pixel dimensions of image (there's several ways to do this)
imagePixelDim = [ims.XData(2),ims.YData(2)]; % [width, height] in pixels
% Normalize the ROI position by the width and height of the image in pixels
r1Norm = r1.Position ./ [imagePixelDim,imagePixelDim];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by