How do I load and display an image stored in a separate .mat file?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2024-12-14
编辑:Matt J
2024-12-14
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 个评论
Walter Roberson
2024-12-14
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
2024-12-14
"I wish that was in the documentation for the load function."

更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!