How do I load and display an image stored in a separate .mat file?

34 views (last 30 days)
I am trying to load an image from a provided file and display the image for a class project. We were given the following bit of code to do this so be gentle with me. The prupose of doing this to use linear algebra to do image compression of the data matrix for the image.
image = load("MAT 350 Project Two MATLAB Image.mat");
figure(1);
imshow(image);
And I get the following errors.
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was struct.
Error in images.internal.imageDisplayValidateParams (line 11)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});

Accepted Answer

Matt J
Matt J on 14 Dec 2024 at 14:35
Edited: Matt J on 14 Dec 2024 at 14:38
If you look at,
disp(image)
you will see that image is a struct as the error message is telling you. What you probably meant to do is,
image=load("MAT 350 Project Two MATLAB Image.mat").whatever_the_name_of_the_variable_in_the_file_is
  4 Comments
Walter Roberson
Walter Roberson on 14 Dec 2024 at 17:37
variable = load(file)
is defined in the documentation. If file is a .mat file then the output is a struct array with one field for each variable in the .mat file. If file is a text file, then the output is a 2D numeric array.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!