I am trying to consider 0.0001 as zero in my code. How can I define that MaTLAB rounds my number based on decimal that I need?
Thanks a lot.
Best Answer
I am not certain exactly what you want.
One of these should work:
x1 = 0.0001;
x2 = 0.001;
y1 = round(x1)
y2 = round(x2)
roundn = @(x,n) round(x*10.^n)./(10.^n);
z1 = roundn(x1,3)
z2 = roundn(x2,3)
The built-in MATLABround function rounds to the nearest integer. InR2015a, you can also have it round to a specific number of decimal places, but if you have an earlier version, my‘roundn’ anonymous function will do the same thing.
Run my code snippet here to find out which of them does what you want.
Since you chose adaptive threshold, each one of those is a threshold for that specific pixel location in the image. You can use that directly in imbinarize() or simply do
binaryImage = grayImage < T11; % or > depending on what you want.
Best Answer