> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datamarkin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Slicer

> Sliced inference for detecting small objects in large images.

This module provides high-accuracy object detection on large images by slicing images into overlapping tiles, running inference on each slice, and merging predictions with intelligent NMS/NMM. Designed for simplicity and performance following PixelFlow principles with comprehensive edge case handling.

## Classes

* [`SlicedInference`](#slicedinference) - Performs sliced inference on large images for improved small object detection.

## Functions

* [`auto_slice_size`](#auto_slice_size) - Automatically calculate optimal slice dimensions based on image properties.

## SlicedInference

Performs sliced inference on large images for improved small object detection.

The main challenge in sliced inference is accurately merging predictions from overlapping slices. This implementation handles critical edge cases including objects on slice boundaries, nested objects, and partial detections at slice edges using intelligent NMS/NMM algorithms with configurable thresholds.

### Example

```python Example theme={null}
import cv2
import pixelflow as pf
from ultralytics import YOLO

# Setup model and sliced inference
model = YOLO("yolo11n.pt")
slicer = pf.SlicedInference(slice_height=640, slice_width=640, overlap_ratio_h=0.2)

# Define detector function
def detector_func(image):
```

## auto\_slice\_size

Automatically calculate optimal slice dimensions based on image properties.

Computes slice dimensions that maintain the image's aspect ratio while targeting a specific slice size. Ensures slices are neither too small (minimum 320px) nor larger than the original image dimensions.

## Function Signature

```python theme={null}
auto_slice_size(
    image_height: int,
    image_width: int,
    target_size: int = 640
) -> Any
```

### Parameters

<ParamField path="image_height" type="int" required>
  Height of the input image in pixels
</ParamField>

<ParamField path="image_width" type="int" required>
  Width of the input image in pixels
</ParamField>

<ParamField path="target_size" type="int" optional default="640">
  Target dimension for the larger side of each slice. Will be adjusted to maintain aspect ratio. Default is 640.
</ParamField>

### Returns

<ResponseField name="result" type="Any">
  Tuple\[int, int]: Optimal (slice\_height, slice\_width) dimensions that maintain aspect ratio and respect size constraints.
</ResponseField>

### Example

```python Example theme={null}
import pixelflow as pf

# Square image - both dimensions equal target_size
h, w = pf.auto_slice_size(2000, 2000, target_size=640)
print(f"Square image slices: {h}x{w}")
```
