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

조회 수: 817 (최근 30일)
I execute the following commands to display an image using the IMAGESC function:
load clown
clims = [10 60];
imagesc(X,clims)
colormap(gray)
The y-axis runs from the top of the image to the bottom. I would like to reverse the y-axis so that it starts at the bottom of the image and runs to to the top.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2010년 7월 29일
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
The first row of pixels is normally at the top of an image. By default, the IMAGE and IMAGESC functions invert the y-axis direction when the image is displayed on an axes by setting the 'YDir' property to 'reverse.' To invert the y-axis direction, set the 'YDir' property to 'normal', as follows:
load clown
clims = [10 60];
imagesc(flipud(X),clims)
colormap(gray)
set(gca,'YDir','normal')
  댓글 수: 2
Royi Avital
Royi Avital 2018년 5월 1일
The problem is doing this flips the data as well. How could one only flip the axis yet not how the data is displayed?
Mary Abbott
Mary Abbott 2018년 5월 9일
Hi Royi,
Only setting the 'YDir' property of the axes to 'normal' will flip how the y-axis is displayed, causing the image to appear upside down. To account for this, we use the "flipud" function to flip the image back. Essentially, we are flipping it horizontally twice, so the end result should not appear flipped.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

BHANESH BHADRECHA
BHANESH BHADRECHA 2015년 11월 2일
편집: madhan ravi 2019년 2월 3일
set(gca,'YDir','normal')

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by