Issue while plotting image (wrong scale)

4 vues (au cours des 30 derniers jours)
Priyank Goel
Priyank Goel le 4 Août 2021
Réponse apportée : Raag le 4 Juil 2025
Hello, I am getting inverted image, and when I am trying to invert it using (reverse) I got the the corrected image but the y axis scale also got inverted. Is this correct or is there a way to correct it. Please suggest possible solution, I am confused whether it is right or not for single valued decomposition.
I have attached the MATLAB script and the output image for your reference after inversion but the scale is also inverted and is going from high to low.
for i = 1:52;
data(:,:,i) = rgb2gray(imread(sprintf('~/Downloads/4_68_image/scene_%0.4d.bmp',i)));
end
r = 1024;
c = 1024;
data = double(reshape(data,r*c,52));
mode = 1
freq = 1
[Phi ,~, C]=svd(data-repmat(mean(data,2),[1 size(data,2)]),'econ');
% Plot the figures
close all
figure('name','POD')
subplot(1,1,1)
imagesc(reshape(Phi(1:r*c,mode),r,c));axis image;set(gca,'Ydir','reverse')

Réponses (1)

Raag
Raag le 4 Juil 2025
Hi Priyank,
This is a common issue when displaying reshaped image data in MATLAB. The confusion arises because MATLAB’s ‘imagesc’ function, by default, places the (1,1) pixel at the top-left, with the y-axis increasing downwards ('YDir','normal').
To keep the image upright and the y-axis increasing from top to bottom (the MATLAB default), you can flip the image data before displaying, and use 'YDir','normal'. Here’s how you can modify your code:
imagesc(flipud(reshape(Phi(1:r*c,mode), r, c)));
axis image;
colormap(jet); % Optional: for better visualization
colorbar; % Optional: show color scale
set(gca, 'YDir', 'normal'); % Standard y-axis direction (top-to-bottom)
Here ‘flipud()’ flips the image data vertically, correcting any inversion caused during reshaping.
'YDir','normal' ensures the y-axis increases from top to bottom, which is standard in MATLAB.
This is how the output may look like:
For more information, refer the following documentation:

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by