Crashing on size(img)

1 次查看(过去 30 天)
Ludzavark
Ludzavark 2024-5-13
评论: Voss 2024-5-13
I am having trouble calling the following code:
% Load image and convert image to array
img = imread(imgPath);
% Get the size of the image
imageSize = size(img);
It crashes at the second line, with the error:
Array indices must be positive integers or logical values.
imageSize = size(img);
I've tried checking the path is correct, it is.
I've tried isempty() on img, it's not
I've tried resaving the image to the project folder, it looks fine.
I've tried checking the format it's in, it's uint8
I've tried disp(img) and it says:
(:,:,1) =
Columns 1 through 23
208 209 210 212 213 214 214 214 213 213 213 214 214 214 215 215 217 217 217 217 217 217 217
... for many more lines
Please can someone tell me what I'm doing wrong

采纳的回答

Voss
Voss 2024-5-13
编辑:Voss 2024-5-13

You have a variable called "size".

If this is a script, do

clear size

and then run the script again.

If this is a function, rename your size variable to another name that's not a function's name.

  4 个评论
Ludzavark
Ludzavark 2024-5-13
Thank you for the explanation - though as a matlab newbie most of that still goes over my head even when you explain it to me! Like what you've said makes sense but I couldn't apply it on my own.
I'm used to the compiler telling me what's wrong, like when I defined the variable 'size' it might have shown me a warning saying that it overlaps a function name from my project.
Anyway thanks again!
Voss
Voss 2024-5-13
You're welcome!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by