Skip to main content

tools for tiled image that can be cached on a filesystem.

Project description

TiledImage

大きな画像を効率的に扱うための Python ライブラリです。メモリ使用量を抑えながら、大きな画像をタイル(小さな断片)に分割して管理します。

特徴

  • 大きな画像をタイルに分割して管理
  • ファイルシステム上でのキャッシュ機能
  • メモリ効率の良い画像処理
  • コンテキストマネージャ(with文)による簡単な使用

インストール

pip install tiledimage

基本的な使い方

画像の分割(PNG → PNGs)

from tiledimage import CachedImage
import cv2

# 画像を読み込み
img = cv2.imread("large_image.png")

# タイル化して保存
with CachedImage(
    mode="new",
    dir="output.pngs",
    tilesize=(64, 64),
    cachesize=10,
    bgcolor=(255, 255, 255),  # 背景色(白)
    fileext="jpg"
) as tiled:
    tiled.put_image((0, 0), img)  # 画像を配置

画像の結合(PNGs → PNG)

from tiledimage import CachedImage
import cv2

# タイル化された画像を読み込み
with CachedImage(mode="inherit", dir="input.pngs") as tiled:
    # 全体の画像を取得
    full_image = tiled.get_image()
    # 保存
    cv2.imwrite("combined_image.png", full_image)

コマンドラインツール

画像の分割:

pngs2 input.png output.pngs

画像の結合:

2pngs input.pngs output.png

API リファレンス

CachedImage

メインのクラス。タイル化された画像を管理します。

CachedImage(
    mode,           # "new" または "inherit"
    dir="image.pngs",  # タイルの保存ディレクトリ
    tilesize=128,   # タイルのサイズ(整数またはタプル)
    cachesize=10,   # キャッシュサイズ
    fileext="png",  # タイルのファイル形式
    bgcolor=(0,0,0), # 背景色
    hook=None,      # タイル書き換え時のフック関数
    disposal=False  # 終了時にディレクトリを削除するか
)

主要メソッド

  • put_image(pos, img, linear_alpha=None): 画像を配置
  • get_image(): 全体の画像を取得
  • write_info(): 情報を保存(通常は自動的に呼ばれる)

TiledImage

基本的なタイル画像クラス。キャッシュ機能はありません。

TiledImage(
    tilesize=128,   # タイルのサイズ
    bgcolor=(100,100,100)  # 背景色
)

開発者向け情報

テスト

make test

ビルド

make build

デプロイ

make deploy

ライセンス

MIT License

作者

Masakazu Matsumoto (vitroid@gmail.com)

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

tiledimage-0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

tiledimage-0.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file tiledimage-0.2.tar.gz.

File metadata

  • Download URL: tiledimage-0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for tiledimage-0.2.tar.gz
Algorithm Hash digest
SHA256 986c64b7df2e0a629b105eff63d9af4858b7814faffdbd9bf843ec2f92646c04
MD5 df4645038b3e6a5030953075113cc102
BLAKE2b-256 cf64825690ee5720dc9fd402c27ab5f127ce6fd6ec5ee6af7905d31df82a326b

See more details on using hashes here.

File details

Details for the file tiledimage-0.2-py3-none-any.whl.

File metadata

  • Download URL: tiledimage-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for tiledimage-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a4270036cc516f71658e6d0ded0f530086b53a14b54cf6562d75058d13652069
MD5 360d78ff63b0f4e3fcbd05a62cc3b9d6
BLAKE2b-256 5a7c99374433a479876dce16db7ad3261f90d8a96db9d9c323e7eb1d5fcb4a8d

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