twesh
twesh

Reputation:

what does max(max(L)) in MATLAB means?

what does following code in MATLAB means?

L = bwlabel(B,8)
mx= max(max(L))

any ideas?

Upvotes: 2

Views: 6325

Answers (2)

Jonas
Jonas

Reputation: 74940

max takes, by default, the maximum of an array along the first non-singleton dimension. If L is a 2D array (which it should, given your call to bwlabel), the first call of max collapses the first dimension, so that there is only one row with column maxima, and the second call collapses the second dimension, so that there is only a scalar maximum left. In this example, max(max(L)) is equivalent to max(L(:))

Since bwlabel performs connected component labeling (i.e. labeling each connected group of pixels with unique, sequential integers), mx tells you the number of groups of pixels in the image.

EDIT

As @gnovice mentions in the comments, the highest label assigned by bwlabel is returned as its second output argument: [L,mx] = bwlabel(B,8);

Upvotes: 9

Donnie
Donnie

Reputation: 46923

bwlabel returns a 2D matrix of connected components. Nested max() like that returns the single largest value in a 2D matrix, so, the highest component found.

Upvotes: 4

Related Questions