Skip to main content

A tiny digital photographic utility.

Project description

Anshitsu

Testing

codecov

Anshitsu is a small digital photographic utility.

It was originally created as a simple retouching tool for batch processing photos from the command line. "Anshitsu" means "darkroom" in Japanese.

The goal is not to replace a full photo editor. Anshitsu aims to provide practical retouching presets that get images roughly 80 percent of the way there with a short command.

Install

Run this command in an environment where a currently supported Python version is installed.

We have tested it on Windows, Mac, and Ubuntu on GitHub Actions, but we have not tested it on Macs with Apple Silicon, so please use it at your own risk on Macs with Apple Silicon.

pip install anshitsu

Usage

It is as described in the following help.

NAME
    anshitsu - Process Runnner for Command Line Interface

SYNOPSIS
    anshitsu <flags>

DESCRIPTION
    This utility converts the colors of images such as photos.

    If you specify a directory path, it will convert
    the image files in the specified directory.
    If you specify a file path, it will convert the specified file.
    If you specify an option, the specified conversion will be performed.

    Tosaka mode is named after Tosaka-senpai's "Tri-X de banzen"
    line from "Kyūkyoku Chōjin R". It aims for a grainy
    black-and-white photo look similar to Kodak Tri-X film.
    This mode converts the image to grayscale and adjusts contrast.
    Use floating-point numbers; values around 2.4 usually work well.

FLAGS
    --path=PATH
        Type: Optional[Union]
        Default: None
        Directory or file path. Defaults to None.
    -k, --keep_alpha=KEEP_ALPHA
        Type: bool
        Default: False
        Keep the alpha channel. Defaults to False.
    --colorautoadjust=COLORAUTOADJUST
        Type: bool
        Default: False
        Correct colors using Automatic Color Equalization. Defaults to False.
    --colorstretch=COLORSTRETCH
        Type: bool
        Default: False
        Apply gray-world white balance and color stretching. Defaults to False.
    -g, --grayscale=GRAYSCALE
        Type: bool
        Default: False
        Convert to grayscale. Defaults to False.
    --orthochromatic=ORTHOCHROMATIC
        Type: bool
        Default: False
        Convert to orthochromatic-style grayscale. Defaults to False.
    -i, --invert=INVERT
        Type: bool
        Default: False
        Invert image colors. Defaults to False.
    --color=COLOR
        Type: Optional[Union]
        Default: None
        Adjust color. Defaults to None.
    -b, --brightness=BRIGHTNESS
        Type: Optional[Union]
        Default: None
        Adjust brightness. Defaults to None.
    --sharpness=SHARPNESS
        Type: Optional[Union]
        Default: None
        Adjust sharpness. Defaults to None.
    --contrast=CONTRAST
        Type: Optional[Union]
        Default: None
        Adjust contrast. Defaults to None.
    -t, --tosaka=TOSAKA
        Type: Optional[Union]
        Default: None
        Use Tosaka mode. Defaults to None.
    --outputrgb=OUTPUTRGB
        Type: bool
        Default: False
        Convert a monochrome image to RGB. Defaults to False.
    --sepia=SEPIA
        Type: bool
        Default: False
        Colorize a monochrome image with sepia tones. Defaults to False.
    --cyanotype=CYANOTYPE
        Type: bool
        Default: False
        Colorize a monochrome image with cyanotype-like Prussian blue. Defaults to False.
    --rochester=ROCHESTER
        Type: bool
        Default: False
        Apply a warm color grade inspired by Kodak PORTRA 400. Defaults to False.
    --ashigara=ASHIGARA
        Type: bool
        Default: False
        Apply a vivid color grade inspired by Fujifilm Velvia 100. Defaults to False.
    --crossprocess=CROSSPROCESS
        Type: bool
        Default: False
        Apply a random cross-process-style color grade. Defaults to False.
    --apocalypse=APOCALYPSE
        Type: bool
        Default: False
        Apply a red-orange Velvia 100 cross-process preset. Defaults to False.
    --ultramarine=ULTRAMARINE
        Type: bool
        Default: False
        Apply a blue-forward color grade inspired by Kodak Ultramax. Defaults to False.
    --roppongi=ROPPONGI
        Type: bool
        Default: False
        Apply a smooth fine-grain monochrome preset. Defaults to False.
    --classic=CLASSIC
        Type: bool
        Default: False
        Apply a classic high-acutance monochrome preset. Defaults to False.
    -n, --noise=NOISE
        Type: Optional[Union]
        Default: None
        Add Gaussian noise. Defaults to None.
    --overwrite=OVERWRITE
        Type: bool
        Default: False
        Overwrite original files. Defaults to False.
    --version=VERSION
        Type: bool
        Default: False
        Show version. Defaults to False.
    -l, --line_drawing=LINE_DRAWING
        Type: bool
        Default: False
        Convert to a line drawing. Defaults to False.
    --posterize=POSTERIZE
        Type: Optional[Union]
        Default: None
        Posterize the image. Defaults to None.
    --vignette=VIGNETTE
        Type: Optional[Union]
        Default: None
        Darken image edges with a radial vignette. Defaults to None.

If a directory is specified in the path, an anshitsu_out directory will be created in the specified directory, and the converted JPEG, PNG, and supported RAW images will be stored in PNG format.

If you specify a JPEG, PNG, or supported RAW image file as the path, an anshitsu_out directory will be created in the directory where the image is stored, and the converted image will be stored in PNG format.

RAW images are developed with rawpy before entering the normal Anshitsu processing pipeline. RAW support depends on the LibRaw support available through the installed rawpy version.

Note: Unsupported file formats are skipped during directory processing. If an unsupported file is specified directly, Pillow or the RAW loader will report an error.

Library Usage

Anshitsu can also be used as a small image processing library. The core API is Processor, which accepts a Pillow Image and returns a processed Pillow Image.

from anshitsu.image_io import open_image
from anshitsu.process.processor import Processor


image = open_image("input.jpg")

processed = Processor(
    image=image,
    rochester=True,
    vignette=0.4,
    noise=2.0,
).process()

processed.save("output.png")

The same API can be used from a web API, a desktop GUI application, or another Python script. The caller is responsible for reading the input image and saving or returning the processed image.

Processing Flow

Anshitsu applies selected operations in a fixed order. When multiple options are specified, this flow defines how they are combined.

flowchart TD
    input[Input image] --> alpha[Prepare input]
    alpha --> invert[Invert]
    invert --> correction[Base color correction]
    correction --> colorPresets[Color presets]
    colorPresets --> manual[Manual adjustments]
    manual --> monochrome[Monochrome presets]
    monochrome --> finishing[Finishing adjustments]
    finishing --> toning[Toning]
    toning --> output[Output conversion]
    output --> restoreAlpha[Restore alpha]
    restoreAlpha --> saved[Saved image]

    alpha -. keep_alpha .-> restoreAlpha

    correction --> caa[colorautoadjust]
    correction --> stretch[colorstretch]

    colorPresets --> rochester[rochester]
    colorPresets --> ashigara[ashigara]
    colorPresets --> crossprocess[crossprocess]
    colorPresets --> apocalypse[apocalypse]
    colorPresets --> ultramarine[ultramarine]

    manual --> color[color]
    manual --> brightness[brightness]
    manual --> sharpness[sharpness]
    manual --> posterize[posterize]

    monochrome --> grayscale[grayscale]
    monochrome --> ortho[orthochromatic]
    monochrome --> roppongi[roppongi]
    monochrome --> classic[classic]

    finishing --> contrast[contrast and tosaka contrast]
    finishing --> lineDrawing[line_drawing]
    finishing --> noise[noise]
    finishing --> vignette[vignette]

    toning --> sepia[sepia]
    toning --> cyanotype[cyanotype]

    output --> outputrgb[outputrgb]

Algorithms

The following algorithms are available in this tool.

RGBA to RGB Convert

Converts an image that contains Alpha, such as RGBA, to image data that does not contain Alpha. Transparent areas will be filled with white.

This algorithm is performed on any image file.

invert

Inverts the colors of an image using Pillow's built-in algorithm.

In the case of negative film, color conversion that takes into account the film base color is not performed, but we plan to follow up with a feature to be developed in the future.

colorautoadjust

Applies color correction using the Automatic Color Equalization algorithm described in the following paper.

This process is more time consuming than the algorithm used in "colorstretch", but it can reproduce more natural colors.

(References)

A. Rizzi, C. Gatta and D. Marini, "A new algorithm for unsupervised global and local color correction.", Pattern Recognition Letters, vol. 24, no. 11, 2003.

colorstretch

The "gray world" and "stretch" algorithms described in the following paper are combined to apply color correction.

This process is faster than the algorithm used in "colorautoadjust".

(References)

D. Nikitenko, M. Wirth and K. Trudel, "Applicability Of White-Balancing Algorithms to Restoring Faded Colour Slides: An Empirical Evaluation.", Journal of Multimedia, vol. 3, no. 5, 2008.

grayscale

Convert a color image to grayscale using the algorithm described in the following article.

Python でグレースケール(grayscale)化

Note: This article is written in Japanese.

orthochromatic

Converts a color image to orthochromatic-style grayscale.

This conversion darkens red tones and lifts blue tones to approximate the look of older orthochromatic film.

Tosaka mode

Tosaka mode is named after Tosaka-senpai's "Tri-X de banzen" line from "Kyūkyoku Chōjin R". It aims for a grainy black-and-white photo look similar to Kodak Tri-X film.

Use floating-point numbers when using this mode; values around 2.4 usually work well.

When this mode is specified, color images will also be converted to grayscale.

roppongi

Applies a smooth fine-grain monochrome preset inspired by Fujifilm ACROS.

This preset uses a mild orthopanchromatic response, compresses highlights, keeps blacks firm, and adds restrained fine grain.

classic

Applies a classic high-acutance monochrome preset inspired by Kodak TRI-X in Rodinal.

This preset is less aggressive than Tosaka mode. It uses a firm tone curve, visible but restrained grain, mild sharpening, and highlight protection.

outputrgb

Converts a monochrome image to RGB.

rochester

Applies a warm, low-saturation color grade inspired by Kodak PORTRA 400.

ashigara

Applies a vivid, high-contrast color grade inspired by Fujifilm Velvia 100.

crossprocess

Applies a random cross-process-style color grade.

Cross processing can produce unpredictable color shifts depending on film, chemistry, and exposure. This preset intentionally varies the color response each time it runs.

apocalypse

Applies a red-orange cross-process preset inspired by Fujifilm Velvia 100.

This preset leans into the orange-to-red color cast associated with cross-processing Velvia 100. The strength of the red shift varies slightly each time it runs.

ultramarine

Applies a blue-forward consumer color film grade inspired by Kodak Ultramax.

This preset emphasizes blues while keeping reds slightly restrained, with highlight compression to avoid harsh clipping.

noise

Add Gaussian noise.

To add noise, you need to specify a floating-point number; a value of about 10.0 will be just right.

vignette

Darkens image edges with a radial vignette.

To add a vignette, specify a floating-point number between 0.0 and 1.0.

Special Thanks

We are using the following libraries.

shunsukeaihara/colorcorrect

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

anshitsu-4.1.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distributions

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

anshitsu-4.1.0-py3-none-win_amd64.whl (99.7 kB view details)

Uploaded Python 3Windows x86-64

anshitsu-4.1.0-py3-none-manylinux_2_28_x86_64.whl (195.9 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

anshitsu-4.1.0-py3-none-macosx_11_0_arm64.whl (177.6 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file anshitsu-4.1.0.tar.gz.

File metadata

  • Download URL: anshitsu-4.1.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for anshitsu-4.1.0.tar.gz
Algorithm Hash digest
SHA256 f7742cdbb13527b558f573f679783e32c601c92990f8e7260759c1acb4a658de
MD5 5cd436dce5ca8f856e88b12392cf193a
BLAKE2b-256 08c941f00843118f74be5cd55abacb741513459e7260f12a83d2c685dd458eff

See more details on using hashes here.

File details

Details for the file anshitsu-4.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: anshitsu-4.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 99.7 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for anshitsu-4.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7e5f9b31e22cf8af8d4f7a2185bc307852eb9dfd4646e542e992a807981d587e
MD5 a05c65461755e471a0c7e76ee20882ff
BLAKE2b-256 60390c39f4529b402791c1fc0fbe88d4175d620ee2019d978bc5e4be3becd9a4

See more details on using hashes here.

File details

Details for the file anshitsu-4.1.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: anshitsu-4.1.0-py3-none-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 195.9 kB
  • Tags: Python 3, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for anshitsu-4.1.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da3a83d6e92311ea0c52d7aa90b911edf14b9e9dbeca81f86cd0ca35720db487
MD5 74fa59a5c729ad0ec3dded3767085757
BLAKE2b-256 ea9372f998c45bede113f84be2dc6366e0dd6a9e1a158f99adbb930fb09528de

See more details on using hashes here.

File details

Details for the file anshitsu-4.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: anshitsu-4.1.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 177.6 kB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for anshitsu-4.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33aa658bf95ce30ecf3580166b345573abf8f073c8fcd8ee39d2db31dde3ae78
MD5 ccb332f4d49d3af8fb172de32bcc1c77
BLAKE2b-256 74d7eb4e9e5833d16eea223423e4ede65b8c8b2b34e043d2617d1b81f275cae1

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