0

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

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?

Thanks!

Adam
  • 8,752
  • 12
  • 54
  • 96

1 Answers1

1

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.

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.

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

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.

Santhan Salai
  • 3,888
  • 19
  • 29