o  iN @s6ddlmZddlZddlmZmZGdddZdS)) annotationsN)OrderingTransformations OrderingTypecseZdZdZdddejjejjejjffd6fdd Z d7ddZ d8ddZ d8ddZ d8ddZ d8dd Zd8d!d"Zd9d$d%Zd9d&d'Zd9d(d)Zd9d*d+Zed:d;d0d1Zed:d;d2d3Zed:d;d4d5ZZS)<Orderinga Ordering class that projects a 2D or 3D image into a 1D sequence. It also allows the image to be transformed with one of the following transformations: Reflection (see np.flip for more details). Transposition (see np.transpose for more details). 90-degree rotation (see np.rot90 for more details). The transformations are applied in the order specified by the transformation_order parameter. Args: ordering_type: The ordering type. One of the following: - 'raster_scan': The image is projected into a 1D sequence by scanning the image from left to right and from top to bottom. Also called a row major ordering. - 's_curve': The image is projected into a 1D sequence by scanning the image in a circular snake like pattern from top left towards right gowing in a spiral towards the center. - random': The image is projected into a 1D sequence by randomly shuffling the image. spatial_dims: The number of spatial dimensions of the image. dimensions: The dimensions of the image. reflected_spatial_dims: A tuple of booleans indicating whether to reflect the image along each spatial dimension. transpositions_axes: A tuple of tuples indicating the axes to transpose the image along. rot90_axes: A tuple of tuples indicating the axes to rotate the image along. transformation_order: The order in which to apply the transformations. N ordering_typestr spatial_dimsint dimensions0tuple[int, int, int] | tuple[int, int, int, int]reflected_spatial_dimstuple[bool, bool] | Nonetranspositions_axesEtuple[tuple[int, int], ...] | tuple[tuple[int, int, int], ...] | None rot90_axes"tuple[tuple[int, int], ...] | Nonetransformation_ordertuple[str, ...]returnNonec s t||_|jttvrtdttd|jd||_||_t||jdkrsz,Ordering._order_template..)rshapeevalrr"array)r%rdepthsrowscolumnssequenceorderingr)r6r*r8s "zOrdering._order_templaterYcolsrX int | NonecCsdg}t|D]$}t|D]}|dur"t|D] }||||fqq |||fq qt|}|Sr-rangeappendr"rWrYr]rXidxrcdidx_npr)r)r*raster_scan_idxs    zOrdering.raster_scan_idxc Csg}t|D]B}|ddkrt|nt|ddd}|D]+}|r@|ddkr*t|nt|ddd}|D] }||||fq4q|||fqqt|} | S)NrOrrr_) rYr]rXrcrdcol_idxreZ depth_idxrfrgr)r)r* s_curve_idxs $$ zOrdering.s_curve_idxcCslg}t|D]"}t|D]}|r t|D] }||||fqq |||fq qt|}tj||Sr-)r`rar"rWrandomshufflerbr)r)r* random_idxs     zOrdering.random_idx)rrrr r r r r rrrrrrrr)r+r,rr,)rr,)rr,rr,r-)rYr r]r rXr^rr,)__name__ __module__ __qualname____doc__rr>r?rArCrr/r2r4r rr7r@rDrBr8 staticmethodrhrkrn __classcell__r)r)r'r*rs4 -         r) __future__rnumpyr"monai.utils.enumsrrrr)r)r)r*s