Skip to content

Commit 87c8bee

Browse files
committed
docs for auto_calculate_crop_values
1 parent 79ad3ef commit 87c8bee

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Class implementing cropping and passing crops through a neural network for detec
111111

112112
| **Argument** | **Type** | **Default** | **Description** |
113113
|-----------------------|------------------------|--------------|----------------------------------------------------------------------------------------------------------------|
114-
| image | np.ndarray | | Input image BGR. |
114+
| image | np.ndarray | | The input image in BGR format. |
115115
| model_path | str | "yolov8m.pt" | Path to the YOLO model. |
116116
| model | ultralytics model | None | Pre-initialized model object. If provided, the model will be used directly instead of loading from model_path. |
117117
| imgsz | int | 640 | Size of the input image for inference YOLO. |
@@ -252,14 +252,24 @@ An example of working with this mode is presented in Google Colab notebook - [![
252252

253253
## __How to automatically determine optimal parameters for patches (crops):__
254254

255-
To efficiently process a large number of images of varying sizes and contents, manually selecting the optimal patch sizes and overlaps can be cumbersome. To address this, an algorithm has been developed to automatically calculate the best parameters for patches (crops).
255+
To efficiently process a large number of images of varying sizes and contents, manually selecting the optimal patch sizes and overlaps can be difficult.. To address this, an algorithm has been developed to automatically calculate the best parameters for patches (crops).
256256

257257
The `auto_calculate_crop_values` function operates in two modes:
258258

259259
1. **Resolution-Based Analysis**: This mode evaluates the resolution of the source images to determine the optimal patch sizes and overlaps. It is faster but may not yield the highest quality results because it does not take into account the actual objects present in the images.
260260

261261
2. **Neural Network-Based Analysis**: This advanced mode employs a neural network to analyze the images. The algorithm performs a standard inference of the network on the entire image and identifies the largest detected objects. Based on the sizes of these objects, the algorithm selects patch parameters to ensure that the largest objects are fully contained within a patch, and overlapping patches ensure comprehensive coverage. In this mode, it is necessary to input the model that will be used for patch-based inference in the subsequent steps.
262262

263+
Possible arguments of the ```auto_calculate_crop_values``` function:
264+
| **Argument** | **Type** | **Default** | **Description** |
265+
|-----------------------|------------------------|--------------|----------------------------------------------------------------------------------------------------------------|
266+
| image | np.ndarray | | The input image in BGR format. |
267+
| mode | str | "network_based" | The type of analysis to perform. Can be "resolution_based" for Resolution-Based Analysis or "network_based" for Neural Network-Based Analysis.|
268+
| model | ultralytics model | YOLO("yolov8m.pt") | Pre-initialized model object for "network_based" mode. If not provided, the default YOLOv8m model will be used.|
269+
| classes_list | list | None | A list of class indices to consider for object detection in "network_based" mode. If None, all classes will be considered. |
270+
271+
272+
263273
Example of using:
264274
```python
265275
import cv2
@@ -272,7 +282,7 @@ img = cv2.imread(img_path)
272282

273283
# Calculate the optimal crop size and overlap for an image
274284
shape_x, shape_y, overlap_x, overlap_y = auto_calculate_crop_values(
275-
image=img, mode="network_analysis", model=YOLO("yolov8m.pt")
285+
image=img, mode="network_based", model=YOLO("yolov8m.pt")
276286
)
277287
```
278288

0 commit comments

Comments
 (0)