Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Le Nguyen
Le Nguyen am 5 Okt. 2012
Kommentiert: Shourya am 19 Jan. 2022
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 Kommentare
naila
naila am 1 Aug. 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
Azzi Abdelmalek
Azzi Abdelmalek am 1 Aug. 2013
What is the error message?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 5 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 5 Okt. 2012
for k=1:5
h{k}=imread(sprintf('%d.bmp',k));
end
save file h
  7 Kommentare
Le Nguyen
Le Nguyen am 6 Okt. 2012
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 am 1 Aug. 2013
Bearbeitet: Jan am 1 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

mona
mona am 3 Feb. 2017
how to deal with images in a single .mat file?
  1 Kommentar
Shourya
Shourya am 19 Jan. 2022
Hi,
Have you figured out how to display multiple images stored in a single .mat file? Please help.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by