imcomplement for binary image doesn't replace 1.000 with 0.000

I have a binary image that I am certain has only values of 0.0000 and 1.0000. I need the complement of this image, but when I use imcomplement, all the values that are 1.0000 become very small nonzero numbers (eg 1.0245e-16) and this ruins the rest of my program b/c I need to use bwdist later. Am I doing something wrong?

1 件のコメント

Jan
Jan 2011 年 7 月 14 日
Usually a binary image can be stored as LOGICAL or UINT8 array to save memory. This would solve the floating point problems implicitely. Therefore it is called *binary*.

サインインしてコメントする。

回答 (1 件)

Friedrich
Friedrich 2011 年 7 月 14 日

2 投票

Hi,
are you sure that your value is really 1.0? Because:
imcomplement(.9999999999999994)
ans =
5.5511e-016
>> .9999999999999994
ans =
1.0000
For varifying you can round your values and take a look at the result:
imcomplement(round(.9999999999999994))
ans =
0

2 件のコメント

Jan
Jan 2011 年 7 月 14 日
+1. It seems to be another floating point problem.
Andrei Bobrov
Andrei Bobrov 2011 年 7 月 14 日
double(int8([1 0 1.12e-14]))

サインインしてコメントする。

質問済み:

2011 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by