How to get normalized coordinates of an ROI?

14 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Adam Danz
Adam Danz il 11 Set 2019
"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];

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by