xtract.bot
POST /api/image-threshold

Threshold an image to pure black-and-white. Manual threshold (0–255) or automatic Otsu method. Useful for OCR pre-processing and printing.

Converts an image to pure black-and-white based on a brightness threshold. Two modes: - `manual`: pass `threshold` (0–255). Pixels brighter than the threshold become white, others black. - `auto`: uses Otsu's method to pick the threshold automatically based on the image's histogram. Useful for OCR pre-processing, line-art generation, and preparing images for monochrome printing.

Inputs

NameTypeDefaultDescription
image*fileInput image (PNG / JPEG / WebP).
thresholdnumber (0…100)50Manual threshold percentage (0–100). Pixels with luminance below this become black; above become white. Ignored when method is `otsu` or `triangle`.
methodenum (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.
formatenum (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"'"
}'