2

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?

aspiring_sarge
  • 2,355
  • 1
  • 25
  • 32
Anna
  • 21
  • 1
  • 1
  • 2
  • 4
    http://www.mathworks.com/help/matlab/matlab_prog/symbol-reference.html – Douglas Zare Apr 17 '15 at 18:20
  • @DouglasZare allow me to thank you to, since that link answered my question and not the answers already provided here (yes, I did post an answer to cover that). :) – gsamaras Jul 21 '16 at 23:00

4 Answers4

8

In your question, as already told, it's the logical not operator.

But, my research made me come here and for my part the answer is (this is more general than your question):

Argument Placeholder

To have the fileparts function return its third output value and skip the first two, replace arguments one and two with a tilde character:

[~, ~, filenameExt] = fileparts(fileSpec);

See Ignore Function Inputs in the MATLAB Programming documentation for more information.


Source: MATLAB Operators and Special Characters

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
gsamaras
  • 71,951
  • 46
  • 188
  • 305
6

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
Sameh K. Mohamed
  • 2,323
  • 4
  • 29
  • 55
  • @Anna you should accept the answer. However Sameh my research brought me to this question for another reason, so allow me to post an answer, please. :) – gsamaras Jul 21 '16 at 22:55
2

~ is the logical NOT operator in MATLAB. I've never used the bwmorph function but from the documentation the first input argument is a binary image.

What ~I will do (in theory, anyway) is return a NxNx3 array, where 1 is where the RGB value of I is 0.

For a smaller example:

A = [50, 200, 67; 12, 0, 0];

test = ~A;

Returns:

test =

     0     0     0
     0     1     1
sco1
  • 12,154
  • 5
  • 26
  • 48
1

~ is nothing but a Not operator in Matlab.

  • Except when it's not an operator at all, as in [this answer](http://stackoverflow.com/a/38515691/102441) – Eric Feb 02 '17 at 16:56