## 3 Methods of Automatic Renal Localization
### Extended Maxima Transform  
In this section, we introduce our proposition of the \"slice scanning procedure\", used to locate both kidneys in the image. The description provided in this section concerns the identification of the right kidney only. The identification of the left kidney is the same, except for a different starting point. The initial assumption of the algorithm is as follows:  
* The input algorithm loads \(n\) CT images numbered from 1 to \(n\).
* Each CT image is a raw CT slice containing right (or left) kidney. Slice labeled as \(Ct_{s}\), \(s\ =\ n\ /\ 2\) means the middle CT image. In this image, the boundary of the kidney has the largest (or almost largest) area. The CT end-slices at the position 1 or \(N\), denoted \(Ct_{1}\) and \(Ct_{n}\), contain the smallest kidney.
* A binary mask denoted as \(Sm\), is a predefined area that defines the starting area of the algorithm. The starting area determines the area where the kidney is searched in a raw Ct image.  
The procedure for locating the kidney in the image begins with a slice \(Ct_{s}\). We use a technique based on extended-maxima transform for kidney detection. The Extended-maxima transform is the regional maxima of the H-maxima transform. As regional maxima, we denote connected components of pixels with a constant intensity value. All pixels belonging to the external boundary have a lower value [16].  
We perform extended-maxima transform for all possible \(H\) parameters H = [10, 20, 30,..., 200]. For each result of extended-maxima transform:  
* Leave the top 10 biggest objects.
* Count how many objects completely fit in \(Sm\). Mark the number of objects as \(k\).
* For each object, if it intersects \(Sm\) boundary, remove it.
* Calculate \(sumP\) according to Formula (1). \[sumP=\ \frac{area(RMAX[R(Sm-H)])}{k}\] (1) where \(R\) is reconstruction by dilation of image \(Sm\) from \(Sm-H\). Regional maxima are connected components of pixels with a constant intensity value, and whose external boundary pixels all have a lower value [17]. We use pixel connectivity: 8.  
Figure 2 shows the result of the extended-maxima transform operation for selected \(H\) parameters. For each value of H, a \(sumP\) value has been calculated. In the given example, we used as \(Sm\) a square with the upper left corner position (x, y) = (50,175) and a side length of 200 pixels.  
The next step is to leave one result for which \(sumP\) is the highest and fill the holes and denote as \(H_{0}\) the value of \(H\). In the next step, the extended-maxima transform is executed again but in the raw \(Ct_{s}\) image. Each time algorithm is executed, the circularity coefficient \(PP\) is calculated and the result of the operation is removed from the image. According to this procedure, we generate \(u\) number of masks which are potential candidates for the final kidney mask. Finally, the mask of the highest \(PP\) value is selected. The result of the next five steps is shown in Figure 3.  
The described procedure allows us to find the boundary of the kidney in the \(Ct_{s}\) image. The algorithm for kidneys detection in the remaining slices \((s+1\ldots n\) and \(1\ldots s-1)\) is presented in the subchapter \"Section 3.2 Slice scanning algorithm\". Automatic calculation of the starting area based on neural network is described in the subchapter \"Section 3.3 U-Net assisted initial localization\".  
Figure 3: The result of the next five steps of extended-maxima transforms and result in removing. For example, (**a**) is an original image, and examples (**b–f**) show different shapes found in the next steps. The result of the operation is removed from the image after each step. The circularity factor \(PP\) is calculated for each result.  
Figure 2: The result of the extended-maxima transform operation for the selected parameters H = [30, 70, 110, 120, 140, 170]. The green frame shows an exemplary starting area \(Sm\).