
    1-Ph3                     ~    d dl ZddlmZ ddlmZ ddZd Z ej        d	
          	 	 	 	 	 	 	 dddd            Z	dS )    N   )_hoghistogram   )utilsh㈵>c                    |dk    r.| t          j        t          j        |                     |z   z  }n|dk    r?t          j        | t          j        t          j        |                     |z   z            }n|dk    r3| t          j        t          j        | dz            |dz  z             z  }n|dk    rz| t          j        t          j        | dz            |dz  z             z  }t          j        |d          }|t          j        t          j        |dz            |dz  z             z  }nt          d          |S )NL1zL1-sqrtL2r   L2-Hysg?z/Selected block normalization method is invalid.)npsumabssqrtminimum
ValueError)blockmethodepsouts       T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/_hog.py_hog_normalize_blockr      s"   ~~rvbfUmm,,s23	9		gervbfUmm44s:;<<	4bgbfUAX..a7888	8		bgbfUAX..a7888jc""BGBF36NNS!V3444JKKKJ    c                 j   t          j        | j        | j                  }d|dddf<   d|dddf<   | ddddf         | ddddf         z
  |ddddf<   t          j        | j        | j                  }d|dddf<   d|dddf<   | ddddf         | ddddf         z
  |ddddf<   ||fS )a  Compute unnormalized gradient image along `row` and `col` axes.

    Parameters
    ----------
    channel : (M, N) ndarray
        Grayscale image or one of image channel.

    Returns
    -------
    g_row, g_col : channel gradient along `row` and `col` axes correspondingly.
    dtyper   Nr   r   )r   emptyshaper   )channelg_rowg_cols      r   _hog_channel_gradientr#      s     HW]'-888EE!QQQ$KE"aaa%LQRRU^gcrc111fo5E!B$'NHW]'-888EE!!!Q$KE!!!R%LQQQU^gaaa"fo5E!!!QrT'N%<r   F)multichannel_output	      r'      r)   r   T)channel_axisc                	   t          j        |           } t          j        | j                  }	|                     |	d          } |du}
|
r
| j        dz
  n| j        }|dk    rt          d          	 |rt          j        |           } 	 |
rMt          j	        | |	          }t          j	        | |	          }t          j	        | |	          }t          | j        d                   D ]n}t          | dddd|f                   \  |dddd|f<   |dddd|f<   t          j        |dddd|f         |dddd|f                   |dddd|f<   o|                    d          }t          j        t          j        | j        d	                   t          j        | j        d                   d
d          \  }}||||f         }||||f         }nt          |           \  }}	 | j        dd         \  }}|\  }}|\  }}t#          ||z            }t#          ||z            }t          j        |||ft&                    }|                    t&          d          }|                    t&          d          }t)          j        ||||||||||
  
         d}|rxddlm} t1          ||          dz  dz
  } t          j        |          }!t           j        |!dz   z  |z  }"| t          j        |"          z  }#| t          j        |"          z  }$t          j        ||f|	          }t          |          D ]}%t          |          D ]}&t9          |!|#|$          D ]\  }'}(})t;          |%|z  |dz  z   |&|z  |dz  z   g          }*|                    t#          |*d	         |)z
            t#          |*d         |(z             t#          |*d	         |)z             t#          |*d         |(z
                      \  }}|||fxx         ||%|&|'f         z  cc<   ̌	 ||z
  dz   }+||z
  dz   },|,d	k    s|+d	k    r ||z  }-||z  }.t          d|- d|. d          t          j        |+|,|||f|	          }/t          |+          D ]D}%t          |,          D ]2}&||%|%|z   |&|&|z   ddf         }0t?          |0|          |/|%|&ddf<   3E	 |r|/                                 }/|r|/|fS |/S )a  Extract Histogram of Oriented Gradients (HOG) for a given image.

    Compute a Histogram of Oriented Gradients (HOG) by

        1. (optional) global image normalization
        2. computing the gradient image in `row` and `col`
        3. computing gradient histograms
        4. normalizing across blocks
        5. flattening into a feature vector

    Parameters
    ----------
    image : (M, N[, C]) ndarray
        Input image.
    orientations : int, optional
        Number of orientation bins.
    pixels_per_cell : 2-tuple (int, int), optional
        Size (in pixels) of a cell.
    cells_per_block : 2-tuple (int, int), optional
        Number of cells in each block.
    block_norm : str {'L1', 'L1-sqrt', 'L2', 'L2-Hys'}, optional
        Block normalization method:

        ``L1``
           Normalization using L1-norm.
        ``L1-sqrt``
           Normalization using L1-norm, followed by square root.
        ``L2``
           Normalization using L2-norm.
        ``L2-Hys``
           Normalization using L2-norm, followed by limiting the
           maximum values to 0.2 (`Hys` stands for `hysteresis`) and
           renormalization using L2-norm. (default)
           For details, see [3]_, [4]_.

    visualize : bool, optional
        Also return an image of the HOG.  For each cell and orientation bin,
        the image contains a line segment that is centered at the cell center,
        is perpendicular to the midpoint of the range of angles spanned by the
        orientation bin, and has intensity proportional to the corresponding
        histogram value.
    transform_sqrt : bool, optional
        Apply power law compression to normalize the image before
        processing. DO NOT use this if the image contains negative
        values. Also see `notes` section below.
    feature_vector : bool, optional
        Return the data as a feature vector by calling .ravel() on the result
        just before returning.
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

        .. versionadded:: 0.19
           `channel_axis` was added in 0.19.

    Returns
    -------
    out : (n_blocks_row, n_blocks_col, n_cells_row, n_cells_col, n_orient) ndarray
        HOG descriptor for the image. If `feature_vector` is True, a 1D
        (flattened) array is returned.
    hog_image : (M, N) ndarray, optional
        A visualisation of the HOG image. Only provided if `visualize` is True.

    Raises
    ------
    ValueError
        If the image is too small given the values of pixels_per_cell and
        cells_per_block.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients

    .. [2] Dalal, N and Triggs, B, Histograms of Oriented Gradients for
           Human Detection, IEEE Computer Society Conference on Computer
           Vision and Pattern Recognition 2005 San Diego, CA, USA,
           https://lear.inrialpes.fr/people/triggs/pubs/Dalal-cvpr05.pdf,
           :DOI:`10.1109/CVPR.2005.177`

    .. [3] Lowe, D.G., Distinctive image features from scale-invatiant
           keypoints, International Journal of Computer Vision (2004) 60: 91,
           http://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf,
           :DOI:`10.1023/B:VISI.0000029664.99615.94`

    .. [4] Dalal, N, Finding People in Images and Videos,
           Human-Computer Interaction [cs.HC], Institut National Polytechnique
           de Grenoble - INPG, 2006,
           https://tel.archives-ouvertes.fr/tel-00390303/file/NavneetDalalThesis.pdf

    Notes
    -----
    The presented code implements the HOG extraction method from [2]_ with
    the following changes: (I) blocks of (3, 3) cells are used ((2, 2) in the
    paper); (II) no smoothing within cells (Gaussian spatial window with sigma=8pix
    in the paper); (III) L1 block normalization is used (L2-Hys in the paper).

    Power law compression, also known as Gamma correction, is used to reduce
    the effects of shadowing and illumination variations. The compression makes
    the dark regions lighter. When the kwarg `transform_sqrt` is set to
    ``True``, the function computes the square root of each color channel
    and then applies the hog algorithm to the image.
    F)copyNr   r   zwOnly images with two spatial dimensions are supported. If using with color/multichannel images, specify `channel_axis`.r   )axisr   ijT)indexingsparse)drawg      ?zoThe input image is too small given the values of pixels_per_cell and cells_per_block. It should have at least: z
 rows and z cols.)r   )!r   
atleast_2dr   _supported_float_typer   astypendimr   r   
empty_likeranger   r#   hypotargmaxmeshgridarangeintzerosfloatr   hog_histograms r1   minpisincosziptupleliner   ravel)1imageorientationspixels_per_cellcells_per_block
block_norm	visualizetransform_sqrtfeature_vectorr*   float_dtypemultichannelndim_spatialg_row_by_chg_col_by_chg_magnidx_chidcs_maxrrccr!   r"   s_rows_colc_rowc_colb_rowb_coln_cells_rown_cells_colorientation_histogram	hog_imager1   radiusorientations_arrorientation_bin_midpointsdr_arrdc_arrrcodrdccentren_blocks_rown_blocks_colmin_rowmin_colnormalized_blocksr   s1                                                    r   hogru   0   s=   h M%  E-ek::KLL5L11Et+L%1A5:>>uzLq.
 
 	
    4mE===mE===uK888EKN++ 	 	F &eAAAqqq&L&9::AAAqqq&L)AAAqqq&L)#%8AAAqqq&L);qqq!!!V|+D$ $F111aaa<  
 ==a=((Iek!n%%Iek!n%%	
 
 
B BH,-BH,-,U33u ;rr?LE5"LE5"LE5eun%%Keun%%K H	k<0   LLUL++ELLUL++E    I HUE""a'!+9\22$&E-=-C$D|$S!"&!:;;;"&!:;;;HeU^;???	{## 
	H 
	HA;'' 	H 	H!$%5vv!F!F H HIAr2"AI
$:AIQR
<R#STTF!YYF1IN++F1IN++F1IN++F1IN++	 FB b"f%%%)>q!Qw)GG%%%%H	H  %'1,L%'1,LqLA--%-%-2 2 2 #*2 2 2
 
 	
 	|UE<@   <   X X|$$ 	X 	XA)!a%i-QY*IJE)=eJ)W)W)WaAAAg&&	X  6-3355 ! )++  r   )r   )r%   r&   r(   r   FFT)
numpyr   r@   r   _sharedr   r   r#   channel_as_last_axisru    r   r   <module>rz      s                      "  0 666 d! d! d! d! d! 76d! d! d!r   