MATLAB Answers

threshold multiple values at the same time

10 views (last 30 days)
Hi am I trying to find the value of a global threshold (mean, median, 50, 100, 150, 200)
Can someone assist me asap please?
TIA!

  3 Comments

Matpar
Matpar on 6 Aug 2019
I am trying to do a global threshold for the given values 50, 100, 150, 200
all at once and have matlab project all images respectfully!!
I do not know how to start the syntax hence the reason for me asking!!!
Help if you can please!!!
Walter Roberson
Walter Roberson on 6 Aug 2019
What does it mean to do a global threshold for the given values 50, 100, 150, 200 ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Aug 2019
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.

  15 Comments

Matpar
Matpar on 7 Aug 2019
Hi Walter,
I tried and tried it did work Walter i am so greatful!!!! yippy!!!
all the lables are now on the image I have been trying to get that to work for the longest while and now realise the alterations.
Ah the next thing is I am trying to work out adpative, global/local thresholding with the same constant!! can you help me please?
and thanks for all your assistance if you didn't help me I would not have gotten this far!!!
I am so happy walter just to figure it out!!
Walter Roberson
Walter Roberson on 7 Aug 2019
Adaptive thresholding and local thresholding do not use constants. The code I showed is already for global thresholding.
Walter Roberson
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by