如何在 MATLAB 中编辑图像的轴以反转方向?

发布于 2024-09-02 20:25:28 字数 278 浏览 6 评论 0原文

我想编辑正在显示的一系列图像中的轴。

这就是我的图像的样子:

parabola

如您所见,从上到下的范围是 0 到 500 左右。我可以颠倒一下吗? 另外,我想镜像所显示的图像,以便它从左到右开始......或者,如果可能的话,让轴从右到左显示。

I would like to edit the axes in my series of images being displayed.

This is what my image looks like:

parabola

As you can see, it ranges from 0 to about 500 from top to bottom. Can I invert that?
Plus, I want to mirror the image being shown, so that it starts from left to right... or, if it's possible, to let the axes show from right to left.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

﹏半生如梦愿梦如真 2024-09-09 20:25:28

要反转轴,您可以设置 ' 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

To reverse an axis, you can set the 'XDir' or 'YDir' property of the current axes to 'reverse':

set(gca,'XDir','reverse');  %# This flips the x axis

Keep in mind that flipping an axis in this way flips everything in the plot as well. This probably isn't what you want to do for the y axis. You probably just want to flip the y axis labels, which you can do by modifying the 'YTickLabel' property in the following way:

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
拥醉 2024-09-09 20:25:28
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 或 IMAGEESC 函数显示图像时,如何反转 y 轴? mathworks 的另一个解决方案

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.

And whoop dee doo the image now have an y axis with the range from bottom to top!

How can I reverse the y-axis when I use the IMAGE or IMAGESC function to display an image in MATLAB? Another solution from mathworks

月亮是我掰弯的 2024-09-09 20:25:28

我发现 gnovice 的答案很有帮助,但它需要对我进行一些调整。我认为以下是反转 y 轴上标签的更通用方法。只需按降序对 y 刻度数字进行排序并重新标记即可。

yTicks = get(gca,'YTick');   
yTicks_reverse = sort(yTicks,2,'descend');                                      
set(gca,'YTickLabel',num2str(yTicks_reverse.')); 

I found gnovice's answer helpful but it needed some tweaks for me. I think the following is a more general way to reverse the labels on the y axis. Simply sort the y tick numbers in descending order and relabel.

yTicks = get(gca,'YTick');   
yTicks_reverse = sort(yTicks,2,'descend');                                      
set(gca,'YTickLabel',num2str(yTicks_reverse.')); 
佼人 2024-09-09 20:25:28

我从一个重复的问题重定向到这里:
翻转轴刻度

'ale' 想要做的只是将 y 轴方向翻转为自上而下。如果这是唯一需要的东西而没有其他东西,我会使用:

axis ij

I was redirected here from a duplicate question:
Flipping axis ticks

What 'ale' wanted to do there was just to flip the y-axis direction to be top down. If that is the only thing needed and nothing else, I would use:

axis ij
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文