threshold multiple values at the same time
1 view (last 30 days)
Show older comments
Matpar on 6 Aug 2019
Commented: Walter Roberson on 7 Aug 2019
Hi am I trying to find the value of a global threshold (mean, median, 50, 100, 150, 200)
Can someone assist me asap please?
What does it mean to do a global threshold for the given values 50, 100, 150, 200 ?
nd = ndims(YourImageArray);
Thresholded_arrays = bsxfun(@le, YourImageArray, reshape([50, 100, 150, 200], [ones(1,nd), 4]) );
Now Thresholded_arrays is one higher dimension than your original array. For example if your original array was 512 x 768 x 3 x 128 (that is, a stack of 128 RGB images each of which is 512 x 768 pixels), then Thresholded_arrays would be 512 x 768 x 3 x 128 x 4, and Thresholded_arrays(:,:,:,:,1) would be YourImageArray thresholded at value 50.
Walter Roberson on 7 Aug 2019
"If you convert a number that is larger than the maximum value of an integer data type to that type, MATLAB sets it to the maximum value. Similarly, if you convert a number that is smaller than the minimum value of the integer data type, MATLAB sets it to the minimum value."
The calculation A+B in uint8 is like
uint8( max(min(double(A)+double(B),255), 0) )
There is no need to go through and test whether A+B is in the range 0 to 255, because that kind of limit is already built-in to the way that uint8() is defined to operate.
More Answers (0)
Find more on Image Thresholding in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!