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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!