Skip to content

Conversion

Module for converting raw images with RawTherapee

RawConverter

A class for converting a list of raw image files to JPEG or other formats using RawTherapee command line interface.

Parameters:

Name Type Description Default
image_list ImageList

A list of paths to raw image files.

None
output_dir Union[str, Path]

The directory where the converted images will be saved. Defaults to "./converted".

'./converted'
pp3_path Union[str, Path]

The path to a pp3 file containing processing instructions for RawTherapee. Defaults to None.

None
keep_dir_tree bool

A flag indicating whether to preserve the directory structure of the input files in the output directory. If True, the converted images will be saved in subdirectories of the output directory corresponding to the relative paths of the input files. Defaults to False.

False

Examples:

To convert a list of raw images to JPEG format with default parameters and save them in the "converted":

>>> from pathlib import Path
>>> from impreproc.raw_conversion import RawConverter
>>> image_list = ImageList("path/to/raw/images", image_ext = "DNG")
>>> converter = RawConverter(image_list, output_dir="converted")
>>> converter.convert()

To preserve the directory structure of the input files in the output directory, use the following code:

>>> converter = RawConverter(image_list, output_dir="converted", keep_dir_tree=True)
>>> converter.convert()

To add a processing profile to the conversion, use the following code:

>>> converter = RawConverter(image_list, output_dir="converted", pp3_path="path/to/pp3_profile.pp3")
>>> converter.convert()

To add additional parameters to RawTherapee, use the following code. See the documentation of convert_raw function for all the details.

>>> converter = RawConverter(image_list, output_dir="converted", pp3_path="path/to/pp3_profile.pp3")
>>> converter.convert("-j100", "-js3", "-Y")

__init__(output_dir='./converted', pp3_path=None, opts=[], keep_dir_tree=False, image_list=None)

Initializes the RawConverter object.

Parameters:

Name Type Description Default
output_dir Union[str, Path]

The directory where the converted images will be saved. Defaults to "converted".

'./converted'
pp3_path Union[str, Path]

The path to a pp3 file containing processing instructions for RawTherapee. Defaults to None.

None
keep_dir_tree bool

A flag indicating whether to preserve the directory structure of the input files in the output directory. If True, the converted images will be saved in subdirectories of the output directory corresponding to the relative paths of the input files. Defaults to False.

False
image_list ImageList

A list of paths to raw image files. Defaults to None.

None
opts List[str]

Additional options to pass to RawTherapee, e.g. ("-j100", "-Y"). See the documentation of convert_raw function for all the details.

[]
NOTE

image_list shuld be set only in convert method. Kept int init for backward compatibility.

convert(image_list)

Converts the raw image files to the specified format using RawTherapee.

Parameters:

Name Type Description Default
image_list ImageList

A list of paths to raw image files.

required

Returns:

Name Type Description
bool bool

True if all files were converted successfully, False otherwise.

convert_raw(fname, output_path='converted', profile_path=None, rawtherapee_path=None, opts=[])

Converts a raw image file to a specified format using RawTherapee.

Parameters:

Name Type Description Default
fname Union[str, Path]

Path to the raw image file to convert.

required
output_path Union[str, Path]

Directory to save the converted file(s). Defaults to "converted" in the current working directory.

'converted'
profile_path Union[str, Path]

Path to a processing profile (pp3) file to use for the conversion. Defaults to None.

None
opts List[str]

Additional string arguments to pass to RawTherapee. A comprehensive list of possible arguments can be found in the RawTherapee documentation at https://rawpedia.rawtherapee.com/Command-Line_Options

[]

Returns:

Name Type Description
bool bool

True if the conversion was successful, False otherwise.

Examples:

To convert a raw image file named 'my_raw_image.CR2' to JPEG format with 90% compression, apply a processing profile saved in a file called 'my_profile.pp3' and save it to a directory called 'my_images', use the following command:

>>> convert_raw('my_raw_image.CR2', output_path='my_images', profile_path='my_profile.pp3', '-j90' )

To convert a raw image file named 'my_raw_image.CR2' to 16 bit TIF format and apply a processing profile saved in a file called 'my_profile.pp3', use the following command:

>>> convert_raw('my_raw_image.CR2', output_path='my_images', profile_path='my_profile.pp3', '-t16')

To convert a raw image file named 'my_raw_image.CR2' to 8bit TIF format, use:

>>> convert_raw('my_raw_image.CR2', output_path='my_images', profile_path='my_profile.pp3', '-t', '-b8')

To specify the JPEG chroma subsampling parameter, where 1=Best compression, 2=Balanced, 3= Best quality, use:

>>> convert_raw('my_raw_image.CR2', output_path='my_images', profile_path='my_profile.pp3', '-j90', '-js3' )

To force overwrite output if presen:

>>> convert_raw('my_raw_image.CR2', output_path='my_images', profile_path='my_profile.pp3', '-j90', '-Y')

find_rawtherapee()

Find the path of the RawTherapee executable on the current operating system. If the path is not found automatically, a file dialog window will open to allow the user to select the executable manually.

Returns:

Name Type Description
str str

Path to RawTherapee executable

Raises:

Type Description
OSError

If the operating system is not supported

rebuild_dir_tree(file_list, dest_dir)

Rebuilds the directory tree of a list of files in a new location.

Given a list of file paths and a destination directory, this function extracts the relative path of each file in the list relatively to the common path to all files, and uses the relative path extracted to build a new path for copying the files maintaining the same directory tree but in the new location. If the path is not found automatically, a file dialog window will open to allow the user to select the executable manually.

Parameters:

Name Type Description Default
file_list List[Path]

A list of Path objects representing the paths to the files to be copied.

required
dest_dir Path

A Path object representing the destination directory.

required

Returns:

Type Description
List[Path]

List[Path]: A list of Path objects representing the new paths of the copied files, with the same directory tree as

List[Path]

in the original location.