How do I load and display an image stored in a separate .mat file?
조회 수: 34 (최근 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일 14:35
편집: Matt J
2024년 12월 14일 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
Walter Roberson
2024년 12월 14일 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
2024년 12월 14일 19:13
"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!