将.png读入Matlab时尺寸混淆 [英] Dimensions getting mixed up when reading .pngs into Matlab

查看:132
本文介绍了将.png读入Matlab时尺寸混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从计算机上的文件夹中将一系列.png图像读取到matlab中:

I'm reading a series of .png images into matlab from a folder on my computer using the code below:

datapath = dirname;
i = 1;
myFolder = dirname;
if ~isdir(myFolder)
  errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
  uiwait(warndlg(errorMessage));
  return;
end
filePattern = fullfile(myFolder, '*.png');
pngFiles = dir(filePattern);
for k = 1:length(pngFiles)
  baseFileName = pngFiles(k).name;
  fullFileName = fullfile(myFolder, baseFileName);
  imageArray{i} = double(imread(fullFileName))/255;
  %imshow(imageArray{i});
  i = i+1;
end

我正在读取的每个png为1024x800.但是,当我在使用调试器时将鼠标悬停在imageArray {i}上时,我被告知图像的尺寸为800x1024x3!首先,行和列是如何混合的?其次,为什么给我的2D图像一个额外的尺寸?奇怪的是,当在imageArray {i}上调用imshow时,它会显示出完全正常的图像.这是怎么回事?

Each png I'm reading is 1024x800. However, when I hover over imageArray{i} when using the debugger I'm told that the dimensions of the image are 800x1024x3! Firstly, how did the rows and columns get mixed up? Secondly, why is my 2D image being given an extra dimension? The odd thing is that when call imshow on imageArray{i} it displays a perfectly normal looking image. What is going one here?

谢谢!

推荐答案

这就是

Thats an RGB (or Truecolor) image. They consits of 3 layers stacked together to form an image. In your case each layer corresponds to 800x1024 pixels.

对于RGB图像,深度(第3维)始终为3.第一个平面在图像的每个像素中包含红色度,第二个平面在图像的每个像素中包含绿色度,第三个平面包含图像每个像素中的蓝色程度.

For an RGB image, depth(3rd dimension) is always 3. The first plane contains the degree of red in each pixel of the image, the second plane contains the degree of green in each pixel of the image, and the third plane contains the degree of blue in each pixel of the image.

在MATLAB中,
第一维对应于图像中的行数. 第二维对应于图像中的列数.

In matlab,
First dimension corresponds to the number of rows in the image. Second dimension corresponds to the number of columns in the image.

但是在Windows中恰恰相反.
第一维对应于列数,第二维对应于行数.
这就是为什么让它们逆转的原因.

But in windows its just the opposite.
First dimension corresponds to number of columns and second dimension corresponds to the number of rows.
That is the reason why you got them reversed.

这篇关于将.png读入Matlab时尺寸混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆