Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

threshold values

Asked by Sivakumaran Chandrasekaran on 22 May 2012

My threshold value=0.9

If the pixel value is less than 0.9, I have to set it to zero...

else set it to 255.

What command should be used for this

0 Comments

Sivakumaran Chandrasekaran

3 Answers

Answer by the cyclist on 22 May 2012

Does this do what you want?

p = 255*(p>=0.9);

3 Comments

Thanks cyclist.
In an image, i have to find the threshold value.

the pixels having threshold values less than 0.9 should be converted to zero.

Your code does not matches my requirement

Image Analyst on 22 May 2012

Assuming p is your image array, it does match your requirement. If it doesn't you need to say why not, because then there would be something you didn't tell us. In your original question you did NOT say anything about "finding" a threshold value - you said that it was 0.9.

Geoff on 22 May 2012

+1 : this does exactly what you have requested, but you might not understand why. The call (p>=0.9) returns an array of 0 or 1: 0 if the value is less than 0.9 and 1 otherwise. By multiplying by 255, this achieves your two tasks (set to zero or set to 255) simultaneously. Did you actually try it?

the cyclist
Answer by Ricky on 22 May 2012

you could try this:

p = 255;

i = find(p < 0.9);

p(i) = 0;

1 Comment

Geoff on 22 May 2012

This code will turn the image into a single value (255), and then do a find which will fail, rendering the last two lines of code pointless.

Ricky
Answer by Sivakumaran Chandrasekaran on 30 May 2012

Hi, Thanks all for guiding me

0 Comments

Sivakumaran Chandrasekaran

Contact us