Image threshold
Try it interactively →POST /api/image-thresholdThreshold an image to pure black-and-white. Manual threshold (0–255) or automatic Otsu method. Useful for OCR pre-processing and printing.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| image* | file | — | Input image (PNG / JPEG / WebP). |
| threshold | number (0…100) | 50 | Manual threshold percentage (0–100). Pixels with luminance below this become black; above become white. Ignored when method is `otsu` or `triangle`. |
| method | enum (manual | otsu | triangle) | "manual" | How the threshold boundary is chosen. `manual` uses the supplied threshold percentage; `otsu` and `triangle` pick it automatically from the image's histogram. |
| format | enum (png | jpeg | webp) | — | Output format. Defaults to the input's format. |
Response
Modes: binary, base64-json. Cache: yes (24h TTL).
Code samples
Built from the default-png example.
# Download or substitute the example input:
# curl -O https://xtract.bot/examples/image-png-to-webp/sample.png
IMAGE=$(base64 -w0 < sample.png)
curl -X POST https://api.xtract.bot/api/image-threshold \
-H "Content-Type: application/json" \
-H "Accept: application/octet-stream" \
-H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
-H "X-Api-Key: $XTRACT_API_KEY" \
-d '{
"method": "manual",
"threshold": 50,
"image": "'"$IMAGE"'"
}'