How to binarize a grayscale image with multiple thresholds?
조회 수: 19 (최근 30일)
이전 댓글 표시
I am trying to convert a grayscale image into a binary image with two thresholds:
- img = a grayscale image
- b = the output binary image
- if (img > t1) or (img < t2) then b = 1
- otherwise b = 0
t1 = 200;
t2 = 100;
src = imread('an rgb image');
img = reg2gray(src);
b1 = imbinarize(img, t1);
b2 = imbinarize(img, -t2);
b = imadd(b1,b2);
but this code doesn't work. Is there a function to set multiple thresholds at the same time?
댓글 수: 0
채택된 답변
Akira Agata
2020년 9월 12일
편집: Akira Agata
2020년 9월 12일
Assuming a grayscale image img is a 2D double array, the following code should work:
b = img > t1 | img < t2;
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!