def largest_connected_component(volume):
<EOL>volume = np.asarray(volume)<EOL>labels, num_labels = scn.label(volume)<EOL>if not num_labels:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if num_labels == <NUM_LIT:1>:<EOL><INDENT>return volume.astype(np.bool)<EOL><DEDENT>label_count = np.bincount(labels.ravel().astype(np.int))<EOL>label_count[<NUM_LIT:0>] = <NUM_LIT:0><EOL>return labels == label_count.argmax()<EOL>
Return the largest connected component of a 3D array.

    Parameters
    -----------
    volume: numpy.array
        3D boolean array.

    Returns
    --------
    volume: numpy.array
        3D boolean array with only one connected component.