How to get normalized coordinates of an ROI?

9 visualizaciones (últimos 30 días)
Sonia Lenehan
Sonia Lenehan el 11 de Sept. de 2019
Respondida: Adam Danz el 11 de Sept. de 2019
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.

Respuesta aceptada

Adam Danz
Adam Danz el 11 de Sept. de 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];

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by