display .mat file as an image ?
Show older comments
Hi All Matlab users,
I have an image in .mat file ... I have a problem with display it.
clear all;
I=load ('Data.mat'); % struct double 512x512
I=I.s.I;
I=double(I);
figure(1);
imshow(I);
Could someone help me please ?
I would appreciate for any help.
2 Comments
Jan
on 6 Dec 2011
Beside the useless "clear all" (see http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301), what is the problem? Do you get an error message - if so, which one?
Image Analyst
on 6 Dec 2011
Help with what? It's possible that could work if you had a variable called s, that was a structure and that had a member called I which was an array. Did you get an error or something? What does your save() function call look like - what you used when you saved "s" into Data.mat?
Accepted Answer
More Answers (4)
agatte
on 6 Dec 2011
0 votes
1 Comment
Image Analyst
on 6 Dec 2011
Chandra's version did not accept the output of load() into a variable, like you did. In your code I would be a structure. Do what he did and leave off the I= so that "s" gets loaded into the function's workspace, then get the "I" member of "s" like you originally tried to do. But you never said what *your* code's error was, as Jan and I asked.
Dark
on 9 Apr 2014
0 votes
How do I display 512x512x5 .mat file as an image in Matlab ?
6 Comments
Image Analyst
on 9 Apr 2014
You load the file, then you can extract the image from the structure and call imshow:
storedStructure = load(matFileName);
rgbImage = storedStructure.rgbImage;
imshow(rgbImage);
By the way Agata , have I answered your original question? If so please officially mark my answer as "Accepted".
Dark
on 9 Apr 2014
My matFileName is volume_image.mat. I tried your steps but the 2nd line gives me an error - Reference to non-existent field 'rgbImage'.
Image Analyst
on 9 Apr 2014
Dark, you're supposed to know the name of the variable you used, and replace rgbImage with the actual name. If you don't remember just put storedStructure on its own line and it will report its fields to the command window:
storedStructure % Report fields to command window.
You will see one of the fields look like an image. Use the name of that one to replace rgbImage in my code.
Dark
on 9 Apr 2014
Thanks for your quick reply. I followed your code and get an image. However the image that I get using imshow() is just black and white. I even tried using imshow(rgbImage, []). I basically have 5 dicom slices of a bone which I converted into .mat file. Then I followed your code. How do I view the 5 dicom images in Matlab ?
Tain Neupane
on 9 Sep 2022
Hey Dark,
You can use imtool (X (:,:,n)) to display info slice by slice but I am not sure how to display whole image at once! I have an Image of size 512x512x125. I am having difficulties to display all at once and looking for help here. Thank you.
-Tain
Image Analyst
on 9 Sep 2022
If you have any more questions, then start your own completely new thread, and attach your data and code to read it in with the paperclip icon after you read this:
Annie micheal
on 1 Sep 2016
0 votes
How to convert 100 face images to .mat file of the form 20*20*100 where 20*20 is the face template and 100 is the number of images.
8 Comments
Image Analyst
on 1 Sep 2016
Resize each image with imresize(). Then save into a cell array or a 3 or 4D matrix and call save() to save into a mat file on disk.
Annie micheal
on 1 Sep 2016
I'm new to matlab. Pls send me a sample code for the above conversion
Image Analyst
on 1 Sep 2016
Code samples are in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Try this in the loop
resizedImage(:,:,k) = imresize(rgbImage, [20, 20]);
Annie micheal
on 2 Sep 2016
Thanks a lot.. Its working.. But its not working for RGB image. My code is clc;clear all;close all; % Specify the folder where the files live. myFolder = 'C:/Users/DELL/Documents/MATLAB/face detection/NPD/NPDFaceDetector_Train/data/face'; % Check to make sure that folder actually exists. Warn user if it doesn't. if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; end % Get a list of all files in the folder with the desired file name pattern. filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need. theFiles = dir(filePattern); for k = 1 : length(theFiles) baseFileName = theFiles(k).name; fullFileName = fullfile(myFolder, baseFileName); fprintf(1, 'Now reading %s\n', fullFileName); imageArray = imread(fullFileName); for n = 1 : length(theFiles) FaceDB(:,:,n) = imresize(imageArray, [20 20]); end savefile='FaceDB.mat'; save(savefile,'FaceDB'); end
i get this error Now reading C:\Users\DELL\Documents\MATLAB\face detection\NPD\NPDFaceDetector_Train\data\face\1.jpg Subscripted assignment dimension mismatch.
Error in mat (line 19) FaceDB(:,:,n) = imresize(imageArray, [20 20]);
how to fix this error?
Image Analyst
on 2 Sep 2016
Did you define FaceDB in advance of your loop?
FaceDB = zeros(20, 20, nMax, 'uint8');
Annie micheal
on 3 Sep 2016
No
Image Analyst
on 3 Sep 2016
Well, give it a try.
Annie micheal
on 6 Sep 2016
Its working.. thank u..
manasa p
on 9 Feb 2018
0 votes
how to display 83*86*220 data set image in mat tool
2 Comments
Tain Neupane
on 9 Sep 2022
Same question, I want to display an image of size 512x512x150. How do I do so using imtool or imshow or other ways? I am looking for help as soon as possible. Thank you!
Image Analyst
on 9 Sep 2022
You can use the volume viewer app, or you can extract a single plane and use either imtool (pops up in a new window) or imshow (uses existing axes if there is one, else makes a new one).
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!