【发布时间】:2011-02-21 09:02:48
【问题描述】:
我想编辑正在显示的一系列图像中的轴。
这是我的图像的样子:
如您所见,它从上到下的范围从 0 到大约 500。我可以反转吗? 另外,我想镜像显示的图像,使其从左到右开始......或者,如果可能的话,让轴从右到左显示。
【问题讨论】:
标签: matlab image-processing plot axes
我想编辑正在显示的一系列图像中的轴。
这是我的图像的样子:
如您所见,它从上到下的范围从 0 到大约 500。我可以反转吗? 另外,我想镜像显示的图像,使其从左到右开始......或者,如果可能的话,让轴从右到左显示。
【问题讨论】:
标签: matlab image-processing plot axes
要反转轴,可以将current axes的'XDir'或'YDir'属性设置为'reverse':
set(gca,'XDir','reverse'); %# This flips the x axis
请记住,以这种方式翻转轴也会翻转绘图中的所有内容。这可能不是您想要对 y 轴执行的操作。您可能只想翻转 y 轴 标签,您可以通过以下方式修改 'YTickLabel' 属性来实现:
yLimits = get(gca,'YLim'); %# Get the y axis limits
yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and
%# subtract them from the upper limit
set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings
%# and update the y axis labels
【讨论】:
'XTick' 和'YTick' 属性来更改坐标轴值。如果'XTickLabelMode' 和'YTickLabelMode' 属性设置为'auto'(默认值,当您没有修改标签时),那么标签将在您更改刻度值后自动更新。否则,您将不得不自己更新标签。
Im = imread('onion.png');
Im = flipdim(Im ,1); % vertical flip the image.
axis xy; %set the xy to be at (0,0), this flips the image back again.
而且,哇哦,图像现在有一个 y 轴,范围从底部到顶部!
在MATLAB中使用IMAGE或IMAGESC函数显示图像时如何反转y轴?Another solution from mathworks
【讨论】:
我发现 gnovice 的回答很有帮助,但它需要对我进行一些调整。我认为以下是一种更通用的方法来反转 y 轴上的标签。只需按降序对 y 刻度数进行排序并重新标记。
yTicks = get(gca,'YTick');
yTicks_reverse = sort(yTicks,2,'descend');
set(gca,'YTickLabel',num2str(yTicks_reverse.'));
【讨论】:
image(Im); set(gca,'YDir','normal')
【讨论】: