## 2 Materials and Methods
### Calculation of Tile Locations  
Our preferred way of defining the polygonal regions of interest (ROIs) in a WSI is to use the program QuPath [26] (Supplement S7). The next step is to extract the coordinates of the polygons' vertices. We wrote a small QuPath script that can be used in the \"Automate\" Tab in QuPath and exports the polygons' vertices' coordinates into a JSON file ([[https://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/QuPath_sc](https://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/QuPath_sc)]([https://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/QuPath_sc](https://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/QuPath_sc)) ripts/polygon_points_to_json.groovy, accessed on 15 December 2021). The next step is to convert this information into RegionOfInterestPolygon objects ([[http://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/shared/roi.py#L66](http://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/shared/roi.py#L66)]([http://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/shared/roi.py#L66](http://github.com/FAU-DLM/wsi_processing_pipeline/blob/master/shared/roi.py#L66)), accessed on 15 December 2021). There is a convenience function if the ROIs were annotated and extracted with our script from QuPath. ([[https://github.com/FAU-DLM/wsi](https://github.com/FAU-DLM/wsi)]([https://github.com/FAU-DLM/wsi](https://github.com/FAU-DLM/wsi)) _processing_pipeline/blob/master/shared/roi.py#L195, accessed on 15 December 2021)  
It is important to notice that this part is completely optional. The ROI definition may be skipped. Subsequently, all relevant tile locations are calculated. For this process, the function \"WsisToTilesParallel\" ([[https://github.com/FAU-DLM/wsi_processing_pipeline/blob/8c5e4a360](https://github.com/FAU-DLM/wsi_processing_pipeline/blob/8c5e4a360) fa369221 ce86 dd35837e9f1318f430/tile_extraction/tiles.py#L1275]([https://github.com/FAU-DLM/wsi_processing_pipeline/blob/8c5e4a360](https://github.com/FAU-DLM/wsi_processing_pipeline/blob/8c5e4a360) fa369221 ce86 dd35837e9f1318f430/tile_extraction/tiles.py#L1275), accessed on 15 December 2021) is used. It calls the function \"WsiToTiles\" for every WSI and runs in parallel. It takes a few interesting parameters. We will elaborate on a few here; the rest is covered in the function's docstring. \"wsi_paths\":  
First of all, a list with the paths to the WSI files has to be passed. Notice that not only WSI files but also PNG files are supported. If one has already extracted the interesting parts of the WSI as PNGs, one can use them without specifying ROI coordinates, as described before. \"grids_per_roi\", \"optimize_grid_angles\", \"angle_stepsize\", \"minimal_tile_roi_intersection_ratio\":  
The library lays a grid of all possible tiles over each ROI (Supplement S8). If no ROI is specified, the library internally creates one ROI, which simply spans the complete WSI. The logic for this part of the pipeline resides in the tiles.py module, to be more specific, in the Vertex, Rectangle, Grid, and GridManager classes. A Vertex object represents one vertex of the polygonal ROI and provides simple arithmetic operations such as add, subtract, and multiply with scalars and matrices. It also provides the functionality to rotate itself around a specified point. This is performed by multiplying a rotation matrix with the vertex coordinates represented as a 2\(\times\)1 vector. \[\text{Rotation Matrix } \begin{array}{c}x\prime\\ y\prime\end{array} =\left[ \begin{array}{cc}cos(\alpha)&-sin(\alpha)\\ sin(\alpha)&cos(\alpha)\end{array} \right]\left[ \begin{array}{c}x\\ y\end{array} \right]\]  
The Vertex class also provides a convenience function to change the WSI level of the coordinates. Because of its size, a WSI is stored in a pyramid-like format (Supplement S10) in multiple images per level. So particular regions of the image are loaded on-demand with higher resolution while zooming in.