How to get normalized coordinates of an ROI?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sonia Lenehan
le 11 Sep 2019
Réponse apportée : Adam Danz
le 11 Sep 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.
0 commentaires
Réponse acceptée
Adam Danz
le 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];
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!