Okay, I discovered the answer. I sum it up here for the record. For imbinarize(I,T), T must be a double between 0 and 1 (though I can be uint8 or double, it doesn't matter).
imbinarize sets every pixel of an image to 0 regardless of the level set
12 views (last 30 days)
Show older comments
Bálint Décsi
on 13 Sep 2020
Answered: Bálint Décsi
on 13 Sep 2020
Description
In the code part below I have problems with the TH matrix, output of the function. IMG and level are an rgb image and a value between 0 and 255, respectively. The function imbinarize sets each pixel ot TH to 0 and I don't know why. Is it something very trivial I fail to take into consideration?
function [TH] = threshold(IMG, level)
szrgb = size(IMG,3);
if szrgb ~= 1
warning('Input image is not grayscale, an attempt to convert it will be made')
IMG = rgb2gray(IMG);
end
TH = imbinarize(IMG, level);
end
Steps that did not solve my problem
I checked every step in debug mode. Went with different values for level. Converted level into int8 before calling imbinarize. Also, imbinarize(IMG), when the function uses Otsu's method for the right threshold, works fine.
0 Comments
Accepted Answer
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!