Skip to main content

A collection of image processing utilities for splitting, concatenation, and metrics calculation.

Project description

Jcy_utils

A comprehensive Python utility library for image processing, file management, and metric calculations.

📦 Installation

pip install Jcy_utils

🚀 Features

  • Image Manipulation: Split images, add text, pad to square, resize proportionally, and concatenate images.
  • Batch Processing: Recursively process directories with progress bars.
  • Metrics: Calculate Precision, Recall, TP, FP, etc., for classification tasks.
  • Utilities: Retry decorators, file copying tools.

📖 Usage Examples

1. Add Text to Image

from Jcy_utils import add_text_to_image

add_text_to_image(
    input_path="input.jpg",
    output_path="output.jpg",
    text="Sample Text",
    position=(50, 50),
    color=(255, 0, 0) # Red
)

2. Concatenate Images

Combine multiple images into a grid layout automatically.

from Jcy_utils import concat_images_list_with_padding_rowmax

images = ["img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg"]
concat_images_list_with_padding_rowmax(
    images, 
    target_size=512, 
    save_path="grid_result.jpg", 
    max_images_per_row=2
)

3. Batch Directory Processing

Apply a custom function to every image in a folder structure.

from Jcy_utils import wrap_dir

def my_process(input_path, output_path):
    # Your custom logic here
    pass

wrap_dir(
    func=my_process,
    in_dir="./data/source",
    out_dir="./data/processed",
    ext=['jpg', 'png'],
    level=0  # 0 means auto-detect depth
)

4. Calculate Metrics

Compute Precision/Recall by comparing Ground Truth (GT) and Prediction dictionaries.

from Jcy_utils import calculate_pr2

gt = {'img1': 1, 'img2': 0, 'img3': 1}
pred = {'img1': 1, 'img2': 1, 'img3': 0}

metrics = calculate_pr2(gt, pred)
print(f"Precision: {metrics['precision']:.2f}, Recall: {metrics['recall']:.2f}")

5. Resize Image by Max Side

Resize an image proportionally so its longest dimension matches the target size.

import cv2
from Jcy_utils import resize_by_maxside

# Read image using OpenCV
img = cv2.imread("input.jpg")

# Resize so the longest side is 512 pixels
resized_img = resize_by_maxside(img, max_side=512)

# Save the result
cv2.imwrite("resized_512.jpg", resized_img)

📦 How to Publish to PyPI

If you are the maintainer of this library, follow these steps to publish a new version to PyPI.

1. Prerequisites

Ensure you have the build tools installed:

pip install --upgrade build twine

2. Update Version

Modify the version string in pyproject.toml and src/Jcy_utils/__init__.py (e.g., change 0.0.1 to 0.0.2).

3. Build the Package

Run the following command in the project root directory:

python -m build

This will generate distribution files in the dist/ folder.

4. Upload to PyPI

Upload the newly built packages using Twine:

twine upload dist/*

You will be prompted for your PyPI API token (username: __token__).

🛠 Dependencies

  • numpy
  • opencv-python
  • Pillow
  • tqdm

📄 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jcy_utils-0.0.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jcy_utils-0.0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file jcy_utils-0.0.3.tar.gz.

File metadata

  • Download URL: jcy_utils-0.0.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for jcy_utils-0.0.3.tar.gz
Algorithm Hash digest
SHA256 28f4d95a7ce006a0e83b6f6da4721d6152f3217d97cd419192efdebfdd8a388c
MD5 e480cf020103701d92a3a32486010303
BLAKE2b-256 a8899308eaf2b38b03fa7ac1eace7ffcc1a4fc7b77910f9a4250f240d0610dc4

See more details on using hashes here.

File details

Details for the file jcy_utils-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jcy_utils-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for jcy_utils-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8125fa382589b465dde5e20249c74aa9ebbed7d70f03949e36c30a13d448c2
MD5 ee7b3956f72e2623cc42b545a2313d4c
BLAKE2b-256 0df3d249d1b91c58e6d80c830d29eb2d6d15a158380209756e5d8234929c13df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page