Extracting files saved in .mat file

I have saved a set of images in a single .mat file and also generate a txt file contains the filenames of the images that have been saved in the .mat file. I am looking to be able to extract the images from the .mat file. Any help would be welcome. I have attached the code here.
function saveimage()
[fname,pname] = uigetfile('*.*','Pick an Image File','MultiSelect','on');
if isequal(fname,0)
warndlg('Program has been exited without any files being selected','!! Warning !!');
return;
end
if ischar(fname)
fname = {fname}; % If a single image was selected
end
k=0;
l = length(fname);
for i = 1:l
currentimage = imread([pname fname{i}]);
imgs(i).currentimage=currentimage;
fprintf(fout, '\r'); fprintf(fout, fname{i});
k=k+1;
end
save([foutpath num2str(k),'_',num2str(dt),'_Images.mat'], 'imgs');
if (l > 1)
message = sprintf([num2str(k) ' images successfully saved\n\nResults are saved in ' strrep(foutpath, '\', '\\') '\n\n Click OK to continue']);
uiwait(msgbox(message));
else
message = sprintf([num2str(k) ' image successfully saved\n\nResults are saved in ' strrep(foutpath, '\', '\\') '\n\n Click OK to continue']);
uiwait(msgbox(message));
end
return

回答 (2 件)

Swati Tiwari
Swati Tiwari 2013 年 8 月 15 日

1 投票

You should be able to load the image matrix into the MATLAB workspace using the LOAD function.
var = load('filename.mat');
As per your function, var would most likely be a structure array and the field 'currentimage' would correspond to your image file which you can then write to an image file using the IMWRITE function.
imwrite(var(1).currentimage, 'filename', '<format>')
I would recommend reading the documentation on LOAD and IMWRITE.
HTH

4 件のコメント

Ram
Ram 2013 年 8 月 15 日
Thank you the answer. When I try to extract the file, I get the following error: Reference to non-existent field 'currentimage'.
thanks for inputs
Jan
Jan 2013 年 8 月 15 日
@Ram: If the variable var (better use a name which does not shadow a built-in function) does not contain the field 'currntimage', take the chance to check, what it contains instead:
data = load('filename.mat');
data
Ram
Ram 2013 年 8 月 15 日
Thank you for the response. I am now able to load them and view the images. The field is 'imgs.
Image Analyst
Image Analyst 2013 年 8 月 15 日
Hmmm... Looks like Ram needs to look at this so he can learn how to see what's in variables: http://blogs.mathworks.com/videos/category/gui-or-guide/

サインインしてコメントする。

poongothai rajan
poongothai rajan 2014 年 4 月 23 日

0 投票

my file name is te.mat..i can able to read data from my file...but i couldnot view my images...can u give me code for view my .mat file as images

カテゴリ

タグ

質問済み:

Ram
2013 年 8 月 15 日

回答済み:

2014 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by