How to get normalized coordinates of an ROI?

4 views (last 30 days)
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.

Accepted Answer

Adam Danz
Adam Danz on 11 Sep 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];

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!