What is this MATLAB statement for: [MN ~] = size (imge) ;?

What does this operator mean?

[MN ~] = size(imge); 

I do not understand the reason for using this "~", and this statement also gives an error message.

+4
source share
2 answers

In versions of MATLAB since 2009, you can use the tilde ( ~ ) to ignore outputs you don't need . If this gives you an error, it means that your version does not support this use of the tilde, and you should replace it with the name of a dummy variable as follows:

 [MN dummy] = size(imge); 

As Sumon explains, M will contain the number or rows in the image and N will be the number of columns; the dummy will be 1 (for one black-and-white image), 3 (for one color image) or an arbitrary integer (for the image stack).

Usually it makes sense to use a tilde if after that there are other parameters that are of interest to you. size is an exception here when it checks (using nargout ) the number of outputs it needs to produce, and accordingly changes its behavior as described here. .

I.e

 test = zeros(3,4,5); [MN dummy] = size(test); 

produces M = 3, N = 4, as one would expect, but

 test = zeros(3,4,5); [MN] = size(test); 

produces M = 3, N = 20.

In your particular case, I assume that imge is a stack of images, and the programmer wanted to know the size of the individual images, but not how many there are.

+4
source

[MND]=size(img) ;

Command

size will give you the number of rows in the first variable M, the number of columns in the second variable N and the number of dimensions in the third variable D for the parameter image, this is the point. If it is a gray scaled image, then D = 2, and if it is an RGB image, then D = 3. If your expression gives an error, then it is reasonable to adhere to the usual convention, as I showed you. Hope this helps :)

0
source

All Articles