MATLAB Answers

imbinarize sets every pixel of an image to 0 regardless of the level set

10 ビュー (過去 30 日間)
Bálint Décsi
Bálint Décsi 2020 年 9 月 13 日
回答済み: Bálint Décsi 2020 年 9 月 13 日
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.

採用された回答

Bálint Décsi
Bálint Décsi 2020 年 9 月 13 日
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).

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by