what does Tilde image mean in MATLAB?

Anna picture Anna · Apr 17, 2015 · Viewed 9.8k times · Source

I am working on a code for image processing in Matlab and the thinning won't work unless I call the function on the original image with the tilde and then save it to the same variable (found it somewhere on the internet).

 I= bwmorph(~I, 'thin', inf);
 I=~I;

My question is, what does the tilde do/mean here?

Answer

Sameh Kamal picture Sameh Kamal · Apr 17, 2015

Tilde ~ is the NOT operator in Matlab, and it has nothing special with images, it just treats them as matrices.

~ as operator return a boolean form of the matrix it's called against, that the result matrix is 1 for 0 in the original matrix and 0 otherwise.

Examples:

a = magic(2)
a =

     1     3
     4     2

~a
ans =

     0     0
     0     0

another:

b = [4,0,5,6,0];
~b
ans =
 0     1     0     0     1