a
    +caP                     @   sR  d Z ddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZddlZddlZddlmZ dd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd ZG dd deZd?ddZd@ddZdd Zdd Zdd  Z d!d" Z!d#d$ Z"d%d& Z#d'd( Z$dAd+d,Z%dBd-d.Z&dCd0d1Z'd2d3 Z(dDd4d5Z)d6d7 Z*d8d9 Z+dEd=d>Z,dS )Fa  
Mask R-CNN
Common utility functions and classes.

Copyright (c) 2017 Matterport, Inc.
Licensed under the MIT License (see LICENSE for details)
Written by Waleed Abdulla
Modified by Ondrej Pesek
    Written import_contents and load_mask methods
    Different way of removing the alpha channel (contained in load_mask)
    Deleted download_train_weights
    A little refactoring made
    # last cross-check with Matterport's implementation: 28/08/2018
    N)LooseVersionc           
      C   s   t j| jd dgt jd}t| jd D ]}| dddd|f }t t j|ddd }t t j|ddd }|jd r|ddg \}}|ddg \}}	|d7 }|	d7 }	nd\}}}}	t |||	|g||< q(|t jS )	zCompute bounding boxes from masks.
    mask: [height, width, num_instances]. Mask pixels are either 1 or 0.

    Returns: bbox array [num_instances, (y1, x1, y2, x2)].
       dtypeNr   axis   )r   r   r   r   )	npzerosshapeint32rangewhereanyarrayastype)
maskboxesimZhorizontal_indiciesZvertical_indiciesx1x2y1y2 r   UC:/Users/landamar/grass_packager/grass786/addons/i.ann.maskrcnn/etc/maskrcnn/utils.pyextract_bboxes&   s    

r   c                 C   s   t | d |dddf }t | d |dddf }t | d |dddf }t | d |dddf }t || dt || d }||dd  |dd  }	||	 }
|
S )as  Calculates IoU of the given box with the array of the given boxes.
    box: 1D vector [y1, x1, y2, x2]
    boxes: [boxes_count, (y1, x1, y2, x2)]
    box_area: float. the area of 'box'
    boxes_area: array of length boxes_count.

    Note: the areas are passed in rather than calculated here for
    efficiency. Calculate once in the caller to avoid duplicate work.
    r   N   r	      )r
   maximumZminimum)boxr   Zbox_areaZ
boxes_arear   r   r   r   intersectionunioniour   r   r   compute_iou@   s     r%   c                 C   s   | dddf | dddf  | dddf | dddf   }|dddf |dddf  |dddf |dddf   }t | jd |jd f}t|jd D ]*}|| }t|| || ||dd|f< q|S )zComputes IoU overlaps between two sets of boxes.
    boxes1, boxes2: [N, (y1, x1, y2, x2)].

    For better performance, pass the largest set first and the smaller second.
    Nr   r   r   r	   )r
   r   r   r   r%   )Zboxes1Zboxes2area1area2overlapsr   Zbox2r   r   r   compute_overlapsU   s    @@ r)   c                 C   s   | j d dks|j d dkr6t| j d |j d fS t| dkd| j d ftj} t|dkd|j d ftj}tj| dd}tj|dd}t| j|}|dddf |dddf  | }|| }|S )zdComputes IoU overlaps between two sets of masks.
    masks1, masks2: [Height, Width, instances]
    r   r         ?r   N)	r   r
   r   reshaper   float32sumdotT)Zmasks1Zmasks2r&   r'   Zintersectionsr#   r(   r   r   r   compute_overlaps_masksh   s    ""$r0   c                 C   s  | j d dksJ | jjdkr*| tj} | dddf }| dddf }| dddf }| dddf }|| ||  }| ddd }g }	t|dkr|d }
|	|
 t	| |
 | |dd  ||
 ||dd  }t
||kd d }t||}t|d}qtj|	tjdS )	zPerforms non-maximum suppression and returns indices of kept boxes.
    boxes: [N, (y1, x1, y2, x2)]. Notice that (y2, x2) lays outside the box.
    scores: 1-D array of box scores.
    threshold: Float. IoU threshold to use for filtering.
    r   fNr	   r   r   r   r   )r   r   kindr   r
   r,   argsortlenappendr%   r   deleter   r   )r   Zscores	thresholdr   r   r   r   ZareaZixsZpickr   r$   Z
remove_ixsr   r   r   non_max_suppression~   s$    
.r8   c           
      C   s  |  tj} | dddf | dddf  }| dddf | dddf  }| dddf d|  }| dddf d|  }||dddf | 7 }||dddf | 7 }|t|dddf 9 }|t|dddf 9 }|d|  }|d|  }|| }|| }	tj||||	gddS )zApplies the given deltas to the given boxes.
    boxes: [N, (y1, x1, y2, x2)]. Note that (y2, x2) is outside the box.
    deltas: [N, (dy, dx, log(dh), log(dw))]
    Nr   r   r   r	   r*   r   )r   r
   r,   Zexpstack)
r   Zdeltasheightwidthcenter_ycenter_xr   r   r   r   r   r   r   apply_box_deltas   s      r>   c                 C   sJ  t | t j} t |t j}| dddf | dddf  }| dddf | dddf  }| dddf d|  }| dddf d|  }|dddf |dddf  }|dddf |dddf  }|dddf d|  }|dddf d|  }	|| | }
|	| | }t || }t || }t j|
|||gdd}|S )zgCompute refinement needed to transform box to gt_box.
    box and gt_box are [N, (y1, x1, y2, x2)]
    Nr   r   r   r	   r*   r   )tfcastr,   logr9   )r!   gt_boxr:   r;   r<   r=   	gt_heightgt_widthgt_center_ygt_center_xdydxdhdwresultr   r   r   box_refinement_graph   s         rL   c                 C   sB  |  tj} | tj}| dddf | dddf  }| dddf | dddf  }| dddf d|  }| dddf d|  }|dddf |dddf  }|dddf |dddf  }|dddf d|  }|dddf d|  }	|| | }
|	| | }t|| }t|| }tj|
|||gddS )zCompute refinement needed to transform box to gt_box.
    box and gt_box are [N, (y1, x1, y2, x2)]. (y2, x2) is
    assumed to be outside the box.
    Nr   r   r   r	   r*   r   )r   r
   r,   rA   r9   )r!   rB   r:   r;   r<   r=   rC   rD   rE   rF   rG   rH   rI   rJ   r   r   r   box_refinement   s        rM   c                   @   sx   e Zd ZdZdddZdd Zdd Zd	d
 ZdddZdd Z	dd Z
edd Zdd Zdd Zdd Zdd ZdS )Datasetz-
    The base class for dataset classes.
    Nc                 C   s&   g | _ g | _ddddg| _i | _d S )N r   BGsourceidname)
_image_ids
image_info
class_infosource_class_ids)self	class_mapr   r   r   __init__   s    zDataset.__init__c                 C   sR   d|vsJ d| j D ]"}|d |kr|d |kr d S q| j |||d d S )N.z Source name cannot contain a dotrR   rS   rQ   )rW   r5   )rY   rR   class_id
class_nameinfor   r   r   	add_class   s    
zDataset.add_classc                 K   s&   |||d}| | | j| d S )N)rS   rR   path)updaterV   r5   )rY   rR   image_idra   kwargsrV   r   r   r   	add_image  s    
zDataset.add_imagec                 C   s   dS )zReturn a link to the image in its source Website or details about
        the image that help looking it up or debugging it.

        Override for your dataset, but pass to this function
        if you encounter images not in your dataset.
        rO   r   rY   rc   r   r   r   image_reference  s    zDataset.image_referencec                    s   dd  t | j| _t| j| _ fdd| jD | _t | j| _t| j| _	dd t
| j| jD | _dd t
| j| jD | _ttdd | jD | _i | _| jD ]F}g | j|< t| jD ],\}}|d	ks||d
 kr| j| | qqdS )zPrepares the Dataset class for use.

        TODO: class map is not supported yet. When done, it should handle mapping
              classes from different datasets to the same class ID.
        c                 S   s   d | ddd S )z>Returns a shorter version of object names for cleaner display.,Nr	   )joinsplitrT   r   r   r   
clean_name)  s    z#Dataset.prepare.<locals>.clean_namec                    s   g | ]} |d  qS rk   r   ).0crl   r   r   
<listcomp>0      z#Dataset.prepare.<locals>.<listcomp>c                 S   s&   i | ]\}}d  |d |d |qS z{}.{}rR   rS   formatrm   r_   rS   r   r   r   
<dictcomp>5  s   z#Dataset.prepare.<locals>.<dictcomp>c                 S   s&   i | ]\}}d  |d |d |qS rr   rs   ru   r   r   r   rv   9  s   c                 S   s   g | ]}|d  qS )rR   r   )rm   r   r   r   r   rp   ?  rq   r   rR   N)r4   rW   Znum_classesr
   arange	class_idsZclass_namesrV   Z
num_imagesrU   zipclass_from_source_map	image_idsZimage_from_source_maplistsetZsourcesrX   	enumerater5   )rY   rZ   rR   r   r_   r   ro   r   prepare"  s&    

zDataset.preparec                 C   s
   | j | S )zTakes a source class ID and returns the int class ID assigned to it.

        For example:
        dataset.map_source_class_id("coco.12") -> 23
        )rz   )rY   Zsource_class_idr   r   r   map_source_class_idJ  s    zDataset.map_source_class_idc                 C   s"   | j | }|d |ksJ |d S )zMMap an internal class ID to the corresponding class ID in the source dataset.rR   rS   )rW   )rY   r]   rR   r_   r   r   r   get_source_class_idR  s    
zDataset.get_source_class_idc                 C   s   | j S N)rU   )rY   r   r   r   r{   X  s    zDataset.image_idsc                 C   s   | j | d S )zReturns the path or URL to the image.
        Override this to return a URL to the image if it's available online for easy
        debugging.
        ra   )rV   rf   r   r   r   source_image_link\  s    zDataset.source_image_linkc                 C   s0   t j| j| d }|jdkr,t j|}|S )zLoad the specified image and return a [H,W,3] Numpy array.

        Modified by Ondrej Pesek to not care about alpha channel
        ra   r   )skimageioimreadrV   ndimZcolorZgray2rgb)rY   rc   imager   r   r   
load_imagec  s    
zDataset.load_imagec                 C   s   ddi| _ tdt|d D ]2}| ||||d   | j ||d  |i q|D ]:}ttj	|dD ] }| j
|tj|d |d qlqTdS )a  
        Initialize an empty Dataset class with classes and images
        :param classes: List of classes names
        :param directories: List of directories containing training images
        :param modelName: Name of model

        Written by Ondrej Pesek
        rP   r   r	   z*.jpg)rc   ra   N)classesr   r4   r`   rb   globZiglobosra   ri   re   rj   )rY   r   ZdirectoriesZ	modelNamer   Z	directoryr   r   r   r   import_contentso  s    

zDataset.import_contentsc           
      C   s  | j | }ttjtj|d d d}zBtj|d }t	t
|dkrX|}n|dddddf }W n   Y dS 0 t
|jd |jd dg}t
|jd |jd dg}t
| j|d dd	  g}|t
j|dddddf< tdt	|D ]}	t
|| j||	 dd	   zxtj|d }t	t
|dkrn|t
j|dddddf< n0|dddddf t
j|dddddf< W n   Y  dS 0 t
||fd q||dfS )
a  Load instance masks for the given image.

        This function converts the different mask format to one format in the
        form of an array of binary masks of shape [height, width, instances].

        Returns:
            masks: A bool array of shape [height, width, instance count] with
                a binary mask per instance.
            class_ids: a 1D array of class IDs of the instance masks.

        Written by Ondrej Pesek
        ra   r   z*.pngr   N)NNr	   r	   -)rV   r   r   ra   ri   rj   r   r   r   r4   r
   r   r   r   r   r   boolr   r5   concatenate)
rY   rc   r_   aZloadedImageZ	maskImager   Z
maskAppendrx   r   r   r   r   get_mask  s0    
$   4
zDataset.get_mask)N)N)__name__
__module____qualname____doc__r[   r`   re   rg   r   r   r   propertyr{   r   r   r   r   r   r   r   r   rN      s   
		
(
rN   squarec                 C   s  | j }| jdd \}}dd||f}d}	g d}
d}|dkrJ| ||	|
|fS |rbtd|t|| }	|rr|	|k rr|}	|r|dkrt||}t||	 |kr|| }	|	dkrt| t||	 t||	 fdd	} |dkrR| jdd \}}|| d }|| | }|| d }|| | }||f||fd
g}
tj| |
ddd} |||| || f}nl|dkr>| jdd \}}|d dksJ d|d dkr||d  d }|| d }|| | }nd }}|d dkr||d  d }|| d }|| | }nd }}||f||fd
g}
tj| |
ddd} |||| || f}n|dkr| jdd \}}t	d|| }t	d|| }||||f}| ||| ||| f } dd||f}nt
d|| |||	|
|fS )ah  Resizes an image keeping the aspect ratio unchanged.

    min_dim: if provided, resizes the image such that it's smaller
        dimension == min_dim
    max_dim: if provided, ensures that the image longest side doesn't
        exceed this value.
    min_scale: if provided, ensure that the image is scaled up by at least
        this percent even if min_dim doesn't require it.
    mode: Resizing mode.
        none: No resizing. Return the image unchanged.
        square: Resize and pad with zeros to get a square image
            of size [max_dim, max_dim].
        pad64: Pads width and height with zeros to make them multiples of 64.
               If min_dim or min_scale are provided, it scales the image up
               before padding. max_dim is ignored in this mode.
               The multiple of 64 is needed to ensure smooth scaling of feature
               maps up and down the 6 levels of the FPN pyramid (2**6=64).
        crop: Picks random crops from the image. First, scales the image based
              on min_dim and min_scale, then picks a random crop of
              size min_dim x min_dim. Can be used in training only.
              max_dim is not used in this mode.

    Returns:
    image: the resized image
    window: (y1, x1, y2, x2). If max_dim is provided, padding might
        be inserted in the returned image. If so, this window is the
        coordinates of the image part of the full image (excluding
        the padding). The x2, y2 pixels are not included.
    scale: The scale factor used to resize the image
    padding: Padding added to the image [(top, bottom), (left, right), (0, 0)]
    Nr   r   r	   )r   r   r   r   Znoner   T)preserve_ranger   constantmodeZconstant_valuesZpad64@   z*Minimum dimension must be a multiple of 64cropzMode {} not supported)r   r   maxminroundresizer
   padrandomZrandint	Exceptionrt   r   )r   Zmin_dimZmax_dimZ	min_scaler   Zimage_dtypehwZwindowscalepaddingr   Z	image_maxZtop_padZ
bottom_padZleft_padZ	right_padZmax_hZmax_wyxr   r   r   resize_image  sh    !
"


r   c                 C   s   t  2 t d tjj| ||dgdd} W d   n1 s@0    Y  |dur||\}}}}| ||| ||| f } ntj| |ddd} | S )aD  Resizes a mask using the given scale and padding.
    Typically, you get the scale and padding from resize_image() to
    ensure both, the image and the mask, are resized consistently.

    scale: mask scaling factor
    padding: Padding to add to the mask in the form
            [(top, bottom), (left, right), (0, 0)]
    ignorer	   r   )zoomorderNr   r   )warningscatch_warningssimplefilterscipyZndimager   r
   r   )r   r   r   r   r   r   r   r   r   r   r   resize_mask  s    

6r   c           
      C   s   t j||jd f td}t|jd D ]}|dddd|f t}| | dd \}}}}	|||||	f }|jdkrtdt||}t 	|t j|dddd|f< q(|S )zResize masks to a smaller version to reduce memory load.
    Mini-masks can be resized back to image scale using expand_masks()

    See inspect_data.ipynb notebook for more details.
    r   r   Nr   r   z&Invalid bounding box with area of zero)
r
   r   r   r   r   r   sizer   r   around)
bboxr   Z
mini_shape	mini_maskr   r   r   r   r   r   r   r   r   minimize_mask5  s    

&r   c                 C   s   t j|dd |jd f td}t|jd D ]t}|dddd|f }| | dd \}}}}	|| }
|	| }t||
|f}t |t j|||||	|f< q0|S )zResizes mini masks back to image size. Reverses the change
    of minimize_mask().

    See inspect_data.ipynb notebook for more details.
    Nr   r   r   r   )r
   r   r   r   r   r   r   r   )r   r   image_shaper   r   r   r   r   r   r   r   r   r   r   r   expand_maskI  s    "&r   c                 C   s   d S r   r   )r   Zconfigr   r   r   	mold_mask\  s    r   c           	      C   sp   d}|\}}}}t | || || f} t| |kddtj} tj|dd tjd}| |||||f< |S )a(  Converts a mask generated by the neural network to a format similar
    to its original shape.
    mask: [height, width] of type float. A small, typically 28x28 mask.
    bbox: [y1, x1, y2, x2]. The box to fit the mask in.

    Returns a binary mask with the same size as the original image.
    r*   r	   r   Nr   r   )r   r
   r   r   r   r   )	r   r   r   r7   r   r   r   r   Z	full_maskr   r   r   unmold_mask`  s    r   c                 C   s  t t | t |\} }|  } | }| t | }| t | }t d|d || }t d|d || }t ||\}}t ||\}	}
t ||\}}t j||
gddddg}t j||	gddddg}t j|d|  |d|  gdd}|S )a  
    scales: 1D array of anchor sizes in pixels. Example: [32, 64, 128]
    ratios: 1D array of anchor ratios of width/height. Example: [0.5, 1, 2]
    shape: [height, width] spatial shape of the feature map over which
            to generate anchors.
    feature_stride: Stride of the feature map relative to the image in pixels.
    anchor_stride: Stride of anchors on the feature map. For example, if the
        value is 2 then generate anchors for every other feature map pixel.
    r   r	   r   r   r   r*   )	r
   Zmeshgridr   ZflattenZsqrtrw   r9   r+   r   )scalesratiosr   Zfeature_strideanchor_strideZheightsZwidthsZshifts_yZshifts_xZ
box_widthsZbox_centers_xZbox_heightsZbox_centers_yZbox_centersZ	box_sizesr   r   r   r   generate_anchorsx  s     r   c              	   C   sF   g }t t| D ]&}|t| | ||| || | qtj|ddS )a  Generate anchors at different levels of a feature pyramid. Each scale
    is associated with a level of the pyramid, but each ratio is used in
    all levels of the pyramid.

    Returns:
    anchors: [N, (y1, x1, y2, x2)]. All generated anchors in one array. Sorted
        with the same order of the given scales. So, anchors of scale[0] come
        first, then anchors of scale[1], and so on.
    r   r   )r   r4   r5   r   r
   r   )r   r   Zfeature_shapesZfeature_stridesr   Zanchorsr   r   r   r   generate_pyramid_anchors  s    r   c                 C   s*   t | jdksJ | tj| dkdd  S )zIt's common to have tensors larger than the available data and
    pad with zeros. This function removes rows that are all zeros.

    x: [rows, columns].
    r   r   r	   r   )r4   r   r
   all)r   r   r   r   
trim_zeros  s    r   r*           c	                 C   sz  t | } |dd| jd f }t |}|d|jd  }t|ddd }	||	 }||	 }||	 }|d|	f }t||}
d}dt|jd g }dt| jd g }tt|D ]}t|
| ddd }t|
||f |k d }|j	dkr|d|d  }|D ]`}|| dkr"q|
||f }||k r< q|| || kr|d7 }|||< |||<  qqq|||
fS )aq  Finds matches between prediction and ground truth instances.

    Returns:
        gt_match: 1-D array. For each GT box it has the index of the matched
                  predicted box.
        pred_match: 1-D array. For each predicted box, it has the index of
                    the matched ground truth box.
        overlaps: [pred_boxes, gt_boxes] IoU overlaps.
    .Nr   r   r	   )
r   r   r
   r3   r0   Zonesr   r4   r   r   )gt_boxesgt_class_idsgt_masks
pred_boxespred_class_idspred_scores
pred_masksiou_thresholdZscore_thresholdindicesr(   Zmatch_count
pred_matchgt_matchr   Z
sorted_ixsZlow_score_idxjr$   r   r   r   compute_matches  s<    


r   c              	   C   s  t | |||||||\}}	}
t|	dktt|	d  }t|	dktjt| }tdg|dgg}tdg|dgg}tt|d ddD ] }t	|| ||d  ||< qt
|dd |dd kd d }t|| ||d   ||  }||||
fS )a5  Compute Average Precision at a set IoU threshold (default 0.5).

    Returns:
    mAP: Mean Average Precision
    precisions: List of precisions at different class score thresholds.
    recalls: List of recall values at different class score thresholds.
    overlaps: [pred_boxes, gt_boxes] IoU overlaps.
    r   r	   r   r   N)r   r
   Zcumsumrw   r4   r   r,   r   r   r    r   r-   )r   r   r   r   r   r   r   r   r   r   r(   
precisionsrecallsr   r   ZmAPr   r   r   
compute_ap	  s&    
 &"r   r	   c	                 C   s   |pt ddd}g }	|D ]B}
t| |||||||
d\}}}}|rRtd|
| |	| qt |	 }	|rtd|d |d |	 |	S )	zECompute AP over a range or IoU thresholds. Default range is 0.5-0.95.r*   g      ?g?)r   zAP @{:.2f}:	 {:.3f}zAP @{:.2f}-{:.2f}:	 {:.3f}r   r   )r
   rw   r   printrt   r5   r   Zmean)rB   Zgt_class_idZgt_maskZpred_boxZpred_class_idZ
pred_scoreZ	pred_maskZiou_thresholdsverboseZAPr   Zapr   r   r(   r   r   r   compute_ap_range<  s0    
r   c           	      C   s^   t | |}tj|dd}tj|dd}t||kd }|| }tt||jd  }||fS )zCompute the recall at the given IoU threshold. It's an indication
    of how many GT boxes were found by the given prediction boxes.

    pred_boxes: [N, (y1, x1, y2, x2)] in image coordinates
    gt_boxes: [N, (y1, x1, y2, x2)] in image coordinates
    r	   r   r   )r)   r
   r   Zargmaxr   r4   r}   r   )	r   r   r$   r(   Ziou_maxZ
iou_argmaxZpositive_idsZmatched_gt_boxesZrecallr   r   r   compute_recalle  s    
r   c                    s   t | ts| g} g }t|D ]<  fdd| D }|| }t |ttfsN|g}|| qtt| }|du r|dgt| }dd t||D }t|dkr|d }|S )a  Splits inputs into slices and feeds each slice to a copy of the given
    computation graph and then combines the results. It allows you to run a
    graph on a batch of inputs even if the graph is written to support one
    instance only.

    inputs: list of tensors. All must have the same first dimension length
    graph_fn: A function that returns a TF tensor that's part of a graph.
    batch_size: number of slices to divide the data into.
    names: If provided, assigns names to the resulting tensors.
    c                    s   g | ]}|  qS r   r   )rm   r   r   r   r   rp     rq   zbatch_slice.<locals>.<listcomp>Nc                 S   s    g | ]\}}t j|d |dqS )r   )r   rT   )r?   r9   )rm   onr   r   r   rp     rq   r	   r   )
isinstancer|   r   tupler5   ry   r4   )ZinputsZgraph_fnZ
batch_sizenamesZoutputsZinputs_sliceZoutput_slicerK   r   r   r   batch_slice~  s     
r   c                 C   sP   |\}}t |d |d |d |d g}t g d}t | | |t jS )aa  Converts boxes from pixel coordinates to normalized coordinates.
    boxes: [N, (y1, x1, y2, x2)] in pixel coordinates
    shape: [..., (height, width)] in pixels

    Note: In pixel coordinates (y2, x2) is outside the box. But in normalized
    coordinates it's inside the box.

    Returns:
        [N, (y1, x1, y2, x2)] in normalized coordinates
    r	   r   r   r	   r	   )r
   r   Zdivider   r,   r   r   r   r   r   shiftr   r   r   
norm_boxes  s    "r   c                 C   sV   |\}}t |d |d |d |d g}t g d}t t | || t jS )aa  Converts boxes from normalized coordinates to pixel coordinates.
    boxes: [N, (y1, x1, y2, x2)] in normalized coordinates
    shape: [..., (height, width)] in pixels

    Note: In pixel coordinates (y2, x2) is outside the box. But in normalized
    coordinates it's inside the box.

    Returns:
        [N, (y1, x1, y2, x2)] in pixel coordinates
    r	   r   )r
   r   r   Zmultiplyr   r   r   r   r   r   denorm_boxes  s    "r   r   TFc	           	      C   sN   t tjt dkr0tjj| ||||||||d	S tjj| ||||||dS dS )aX  A wrapper for Scikit-Image resize().

    Scikit-Image generates warnings on every call to resize() if it doesn't
    receive the right parameters. The right parameters depend on the version
    of skimage. This solves the problem by using different parameters per
    version. And it provides a central place to control resizing defaults.
    z0.14)r   r   cvalclipr   anti_aliasinganti_aliasing_sigma)r   r   r   r   r   N)r   r   __version__Z	transformr   )	r   Zoutput_shaper   r   r   r   r   r   r   r   r   r   r     s*    r   )NNNr   )N)r*   r   )r*   )Nr	   )N)r	   r   r   TFFN)-r   r   r   Znumpyr
   Z
tensorflowr?   r   Zskimage.colorr   Z
skimage.ioZskimage.transformZurllib.requestZurllibr   r   Zdistutils.versionr   r   r%   r)   r0   r8   r>   rL   rM   objectrN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sf   % B
j
'  
K 
;  
)
$       