MATLAB: Display .mat file as an image

.mat filedisplay

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.

Best Answer

Why don't you just do something like
% Load entire mat file contents into a structure.
% The structure has a member "I" that is a double 512x512 array.
storedStructure = load('Data.mat');
% Extract out the image from the structure into its own variable.
% Don't use I as the variable name - bad for several reasons.
imageArray = storedStructure.s.I; % Or storedStructure.I depending on what members your structure has.
% Display the image in a brand new figure window.
figure(1);
% Display double image, scaled appropriately.
% No need to cast to uint8 - could even be bad
% if your double numbers don't span the 0-255 range nicely.
imshow(imageArray, []);