How do I load and display an image stored in a separate .mat file?
34 views (last 30 days)
Show older comments
Nicholas
on 14 Dec 2024 at 14:21
Commented: Stephen23
on 14 Dec 2024 at 19:13
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{:});
0 Comments
Accepted Answer
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
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.
Stephen23
on 14 Dec 2024 at 19:13
"I wish that was in the documentation for the load function."
More Answers (0)
See Also
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!