Metadata-Version: 2.1
Name: tree-disk-pith
Version: 0.1.2
Summary: A package for tree disk pith detection in images
Home-page: https://github.com/tuke307/tree-disk-pith
Author: Tony Meissner
Author-email: tonymeissner70@gmail.com
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: numpy==2.1.2
Requires-Dist: opencv-python==4.10.0.84
Requires-Dist: pandas==2.2.3
Requires-Dist: matplotlib==3.9.2
Requires-Dist: pathlib==1.0.1
Requires-Dist: scikit-learn==1.5.2
Requires-Dist: Pillow==11.0.0
Requires-Dist: scikit-image==0.24.0
Requires-Dist: ultralytics==8.3.23

# Tree Disk Pith Detection

[![PyPI - Version](https://img.shields.io/pypi/v/tree-disk-pith)](https://pypi.org/project/tree-disk-pith/)

A Python package for analyzing tree rings in cross-sectional images. Originally forked from [hmarichal93/apd](https://github.com/hmarichal93/apd).

## Installation

```bash
pip install tree-disk-pith
```

## Usage

### Python API

```python
import treediskpith

# Configure the analyzer
treediskpith.configure(
    input_image="input/tree-disk4.png",
    save_results=True,
)

# Run the detection
(
    img_in,          # Original input image
    img_pre,         # Preprocessed image
    pith,  # Center of the tree disk
) = treediskpith.run()
```

### Command Line Interface (CLI)

Basic usage:
```bash
tree-disk-pith --input_image ./input/tree-disk3.png --new_shape 640 --debug
```

Save intermediate results:
```bash
tree-disk-pith --input_image ./input/tree-disk3.png --new_shape 640 --debug --method apd_pcl --save_results
```

Advanced usage with custom parameters:
```bash
tree-disk-pith \
    --input_image input/tree-disk3.png \
    --cx 1204 \
    --cy 1264 \
    --output_dir custom_output/ \
    --sigma 4.0 \
    --th_low 10 \
    --th_high 25 \
    --save_results \
    --debug
```

## CLI Arguments

| Argument | Type | Required | Default | Description |
|----------|------|----------|---------|-------------|
| `--input_image` | str | Yes | - | Input image file path |
| `--output_dir` | str | Yes | - | Output directory path |
| `--method` | str | No | apd | Detection method to use. Choices are apd, apd_pcl, or apd_dl |
| `--model_path` | str | No | - | Path to the weights file (required if using apd_dl method) |
| `--percent_lo` | float | No | 0.7 | percent_lo parameter for the algorithm |
| `--st_w` | int | No | 3 | st_w parameter for the algorithm |
| `--lo_w` | int | No | 3 | lo_w parameter for the algorithm |
| `--st_sigma` | float | No | 1.2 | st_sigma parameter for the algorithm |
| `--new_shape` | int | No | 0 | New shape for resizing the input image. If 0, no resizing is done |
| `--debug` | flag | No | False | Enable debug mode to save intermediate images and outputs |
| `--save_results` | flag | No | False | Save intermediate images, labelme and config file |

## Development

### Setting up Development Environment

1. Clone the repository:
```bash
git clone https://github.com/tuke307/tree-disk-pith.git
cd tree-disk-pith
```

2. Create and activate virtual environment:
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

3. Install development dependencies:
```bash
pip install -r requirements.txt
```

4. Install the package in editable mode:
```bash
pip install -e .
```

5. fetch dataset
```bash
python fetch_dataset.py
```

6. Download pretrained model
```bash
python fetch_pretrained_model.py
```
