imbinarize(I) returning "Error using > , Matrix dimensions must agree."

4 views (last 30 days)
Hi, I'm having trouble thresholding my grayscale images and my errors don't match any issues I've seen online. I ran into this issue originally with my own grayscale jpegs, but I'm replicating the issue here with the image "George" from this post so that others can run my code if needed.
imbinarize(I) is throwing an error, but imbinarize(I, T) is not:
>> url = 'https://blogs.mathworks.com/images/steve/36/george.jpg';
>> I = imread(url);
>> imshow(I)
>> T = 0.5;
>> bw = imbinarize(I, T);
>> imshow(bw)
>> bw = imbinarize(I);
Error using >
Matrix dimensions must agree.
Error in imbinarize>binarize (line 162)
BW = I > T*classrange(2);
Error in imbinarize (line 152)
BW = binarize(I,T);
Additionally, I tried using graythresh() to determine the threshold, but for some reason it gives me a logical array:
>> T = graythresh(I);
>> whos T
Name Size Bytes Class Attributes
T 256x1 256 logical
Interestingly, multithresh does work:
>> T = multithresh(I)
T =
uint8
112
I recently updated Matlab to ensure that this wasn't a compatibility issue or something, and it's still happening. I'm sure I can use multithresh() to make this if needed, but I'd really like to do this right and to make sure I'm not missing something in my image processing.
Thank you!
  1 Comment
Voss
Voss on 18 Feb 2022
I don't run into the error here:
url = 'https://blogs.mathworks.com/images/steve/36/george.jpg';
I = imread(url);
imshow(I)
T = 0.5;
bw = imbinarize(I, T);
imshow(bw)
bw = imbinarize(I);
imshow(bw)

Sign in to comment.

Accepted Answer

Jacquie
Jacquie on 18 Feb 2022
Update: issue fixed in R2021b
I had been using R2018b, so I tried downloading R2021b and the issue is resolved. I still don't know why I ran into that error, but I'll be working in the new install now.
Thanks!

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!