How to create a single .mat file from multiple images?

Hi all,
Assume that I have 5 images as following: 1.bmp, 2.bmp, 3.bmp, 4.bmp, 5.bmp. I want to combine those 5 images into a single .mat file. Anyone knows how to solve this issue, please help me!!
Thanks in advance!!

2 comentarios

naila
naila el 1 de Ag. de 2013
Hi I have the same problem with images: 01.dcm, 02.dcm, 03.dcm ... 22.dcm;
%d isn't working for 01.dcm. what should I do Please
What is the error message?

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Oct. de 2012
Editada: Azzi Abdelmalek el 5 de Oct. de 2012
for k=1:5
h{k}=imread(sprintf('%d.bmp',k));
end
save file h

7 comentarios

Le Nguyen
Le Nguyen el 5 de Oct. de 2012
Thanks Azzi!! your solution found me well!!
However, how to modify your solution in order to achieve a 3d .mat file where the 3rd dimension is the frame sequence and the first two dimensions are of the size of the LR image!!
Thanks in advance!!
Matt Kindig
Matt Kindig el 5 de Oct. de 2012
Editada: Matt Kindig el 5 de Oct. de 2012
a = imread('1.bmp'); %read in first image to get size
[r,c]= size(a);
h = NaN(r,c,5); %pre-allocate memory
h(:,:,1) = a;
for k=2:5,
h(:,:,k) = imread(sprintf('%d.bmp',k))
end
save file h
Le Nguyen
Le Nguyen el 6 de Oct. de 2012
Hi Matt,
Your solution didnt work at all!! At the line 4, there was an error as following: "Subscripted assignment dimension mismatch."
Please double check it!!
Matt J
Matt J el 6 de Oct. de 2012
Editada: Matt J el 6 de Oct. de 2012
Le Nguyen, you double check it. You're supposed to be studying the code people suggest to you and understanding why they work or don't work.
In this case, I suspect that your bitmap files are not 2D, but rather have color channels. Thus they cannot be treated as the slices of a 3D array, as Matt Kindig's code attempts to do.
Matt J is probably right. Here are some code snippets that may help you:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Alternatively,
% Get a weighted sum of the Red, Green, and Blue channels.
grayImage = rgb2gray(rgbImage);
Hi all,
After taking a look around Matlab for a while, I seem to know how to solve this issue!! You are right, Matt J!! My bitmap files are all 3D as well as colourful!! That's why Matt Kindig's solution didnt work at all!! Here is my modification and it really works well!!
img = rgb2gray(imread('1.bmp'));
[r,c]= size(img);
h = NaN(r,c,5); %pre-allocate memory
h(:,:,1) = img;
for k=2:5
h(:,:,k) = rgb2gray(imread(sprintf('%d.bmp',k)));
end
save filename h
I am totally a newbie to Matlab, thus, all of your suggestions are always helpful to me and I am really in debt of it!!
Again, thanks a lot!! :)
PS: if there are any modifications for better performance as well as optimization, please let me know!!
Jan
Jan el 1 de Ag. de 2013
Editada: Jan el 1 de Ag. de 2013
@Le: Please be careful with the exclamation marks. The have a lot of power in English, e.g. much more than in German.
Your solution looks fine and efficient. Disk access like imread has the benefit, that it is such slow, that improvements in other parts of the code are usually not significant.

Iniciar sesión para comentar.

Más respuestas (1)

mona
mona el 3 de Feb. de 2017
how to deal with images in a single .mat file?

1 comentario

Shourya
Shourya el 19 de En. de 2022
Hi,
Have you figured out how to display multiple images stored in a single .mat file? Please help.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Oct. de 2012

Comentada:

el 19 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by