简体   繁体   中英

what does Tilde image mean in MATLAB?

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?

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

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

~ 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

~只不过是Matlab中的Not运算符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM