【发布时间】:2017-03-16 22:22:43
【问题描述】:
我只需要使用 rbbox 获得以像素为单位的 ROI(相对于图像,而不是图形),但我很难将 rbbox 的标准化图形坐标转换为图像坐标。
我已经尝试将它乘以:图像尺寸、图形尺寸、屏幕尺寸、(图像尺寸)/(图形尺寸)。也尝试使用轴位置。
Normalized 表示从 0 到 1,所以 1 应该是图像大小或图形大小,所以我尝试的应该是有效的!我想也许这个数字的边界也算数......谷歌这次没有帮助。
应该有一个方法pixelStuff = FromNormalizedToImagePixels(normalizedStuff)!!
- 以像素为单位的图形大小=窗口大小,没用,它包括 边框。
- 我需要“图像像素”中的 ROI(图中的图像)。
- 如果我能在 图(无边框)。
我错过了什么??
代码示例:
close all; clc;
figH = figure();
set(figH,'Units','normalized');
if isvalid(figH)
% load some image
imgData = imread('ImL_9.png');
imshow(imgData,'Colormap', hot(256),'DisplayRange',...
[min(imgData(:)) max(imgData(:))],'InitialMagnification','fit');
grid on; axis on; xlabel('x'); ylabel('y');
axis equal; axis manual;
% Get image size (pixels)
[isy,isx] = size(imgData);
% Set axis to fit image
ax = get(figH,'CurrentAxes');
set(ax,'xlim',[0 isx]); set(ax,'ylim',[0 isy]);
% Get mouse event to set ROI
k = waitforbuttonpress;
imgROIn = rbbox;
annotation('rectangle',imgROIn,'Color','red');
% Get screen size
screenSize = get(0,'screensize');
% Get figure position
pos = get(figH, 'Position');
% Conversion 1. roi size px = roi size norm * (image size px / figure size norm)
cx = isx / pos(3);
cy = isy / pos(4);
conv = [cx cy cx cy];
% Converts from normalized figure coordinate to image pixels coordinate
imgROIpx = imgROIn.*conv;
% Show result. imgROIpx does not match what was expected, like
% selecting the entire image the result should be: 0 0 isx isy
imgROIpx
end
【问题讨论】:
-
mathworks.com/help/matlab/ref/annotation.html#inputarg_dim
To change the units, use the Units property -
我需要 IMAGE 坐标中的 ROI,图中的图像。以像素为单位获取位置将导致图形窗口大小(包括其边框)。
-
添加了完整的示例代码。
标签: matlab matlab-figure roi