#NEWLINE# @ ndfeature #NEWLINE# def igo( pixels , double_angles = False , verbose = False ) : #NEWLINE# #INDENT# '\n    Extracts Image Gradient Orientation (IGO) features from the input image.\n    The output image has ``N * C`` number of channels, where ``N`` is the\n    number of channels of the original image and ``C = 2`` or ``C = 4``\n    depending on whether double angles are used.\n\n    Parameters\n    ----------\n    pixels : :map:`Image` or subclass or ``(C, X, Y, ..., Z)`` `ndarray`\n        Either the image object itself or an array with the pixels. The first\n        dimension is interpreted as channels. This means an N-dimensional image\n        is represented by an N+1 dimensional array.\n    double_angles : `bool`, optional\n        Assume that ``phi`` represents the gradient orientations.\n\n        If this flag is ``False``, the features image is the concatenation of\n        ``cos(phi)`` and ``sin(phi)``, thus 2 channels.\n\n        If ``True``, the features image is the concatenation of\n        ``cos(phi)``, ``sin(phi)``, ``cos(2 * phi)``, ``sin(2 * phi)``, thus 4\n        channels.\n    verbose : `bool`, optional\n        Flag to print IGO related information.\n\n    Returns\n    -------\n    igo : :map:`Image` or subclass or ``(X, Y, ..., Z, C)`` `ndarray`\n        The IGO features image. It has the same type and shape as the input\n        ``pixels``. The output number of channels depends on the\n        ``double_angles`` flag.\n\n    Raises\n    ------\n    ValueError\n        Image has to be 2D in order to extract IGOs.\n\n    References\n    ----------\n    .. [1] G. Tzimiropoulos, S. Zafeiriou and M. Pantic, "Subspace learning\n        from image gradient orientations", IEEE Transactions on Pattern Analysis\n        and Machine Intelligence, vol. 34, num. 12, p. 2454--2466, 2012.\n    ' #NEWLINE# if ( len ( pixels . shape ) != 3 ) : #NEWLINE# #INDENT# raise ValueError ( 'IGOs only work on 2D images. Expects image data to be 3D, channels + shape.' ) #NEWLINE# #UNINDENT# n_img_chnls = pixels . shape [ 0 ] #NEWLINE# feat_chnls = 2 #NEWLINE# if double_angles : #NEWLINE# #INDENT# feat_chnls = 4 #NEWLINE# #UNINDENT# grad = gradient ( pixels ) #NEWLINE# grad_orient = np . angle ( ( grad [ : n_img_chnls ] + ( 1j * grad [ n_img_chnls : ] ) ) ) #NEWLINE# igo_pixels = np . empty ( ( ( n_img_chnls * feat_chnls ) , pixels . shape [ 1 ] , pixels . shape [ 2 ] ) , dtype = pixels . dtype ) #NEWLINE# if double_angles : #NEWLINE# #INDENT# dbl_grad_orient = ( 2 * grad_orient ) #NEWLINE# igo_pixels [ : n_img_chnls ] = np . sin ( grad_orient ) #NEWLINE# igo_pixels [ n_img_chnls : ( n_img_chnls * 2 ) ] = np . sin ( dbl_grad_orient ) #NEWLINE# igo_pixels [ ( n_img_chnls * 2 ) : ( n_img_chnls * 3 ) ] = np . cos ( grad_orient ) #NEWLINE# igo_pixels [ ( n_img_chnls * 3 ) : ] = np . cos ( dbl_grad_orient ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# igo_pixels [ : n_img_chnls ] = np . sin ( grad_orient ) #NEWLINE# igo_pixels [ n_img_chnls : ] = np . cos ( grad_orient ) #NEWLINE# #UNINDENT# if verbose : #NEWLINE# #INDENT# info_str = 'IGO Features:\n' #NEWLINE# info_str = '{}  - Input image is {}W x {}H with {} channels.\n' . format ( info_str , pixels . shape [ 2 ] , pixels . shape [ 1 ] , n_img_chnls ) #NEWLINE# info_str = '{}  - Double angles are {}.\n' . format ( info_str , ( 'enabled' if double_angles else 'disabled' ) ) #NEWLINE# info_str = '{}Output image size {}W x {}H with {} channels.' . format ( info_str , igo_pixels . shape [ 2 ] , igo_pixels . shape [ 1 ] , n_img_chnls ) #NEWLINE# print ( info_str ) #NEWLINE# #UNINDENT# return igo_pixels