Suppose you thresholded an image at value t1 and thresholded the result at value t2, describe the results if (a) t1>t2 and (b) t2>t1.

조회 수: 1 (최근 30일)
  댓글 수: 7

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2023년 5월 19일
편집: DGM 2023년 5월 19일
Say
%B = A >= t1; % threshold A at t1
%C = B >= t2; % threshold B at t2
The relationship between t1,t2 is irrelevant. What matters is the relationship between t2 and the values used in B. In the context of the example I gave, B is logical, so for numerical purposes, its elements are either 0 or 1. In other contexts, a binarized image may be represented with values of 0 or 255. Depending on where t2 is with respect those two values, the output will either be entirely black, unchanged, or white.
A = linspace(0,1,6)
A = 1×6
0 0.2000 0.4000 0.6000 0.8000 1.0000
B = A >= 0.5
B = 1×6 logical array
0 0 0 1 1 1
C1 = B >= -0.5 % below the interval
C1 = 1×6 logical array
1 1 1 1 1 1
C2 = B >= 0.5 % inside the interval
C2 = 1×6 logical array
0 0 0 1 1 1
C3 = B >= 1.5 % above the interval
C3 = 1×6 logical array
0 0 0 0 0 0
  댓글 수: 8
DGM
DGM 2023년 5월 19일
편집: DGM 2023년 5월 19일
Yes. 0<0.4<1, so the image is unchanged. You should also get a warning when you do that.
inpict = imread('peppers.png'); % this is uint8, RGB
mk1 = im2bw(inpict,0.3); % this is logical, single-channel
mk2 = im2bw(mk1,0.4); % this is logical, single-channel
Warning: The input image is already binary.
isequal(mk1,mk2)
ans = logical
1
The threshold parameter given to im2bw() is in unit-scale, regardless of the class (and implied scale) of the input image. In the case of inpict, the scale of the image is [0 255], so it's thresholded at 0.3*255. In the case of mk1, the scale is [0 1], so you're thresholding at 0.4*1.
Since im2bw() doesn't allow the threshold parameter to be less than 0 or greater than 1, logical-class inputs will always be unchanged. If you were to check the internals of im2bw(), it knows that nothing will change, so it doesn't even bother with the comparison. It just dumps the warning and returns the input.
This is different than the example I gave above where thresholds are specified outside of the unit interval. Like I said, there are only three possible outcomes for a binarized input. The only way the output will differ from the input is if the threshold value is outside the interval defined by the values in the input.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by