Converts raw to jpg. This functions are not required for competitors but was developed to prepare the dataset for the competition.
dropbox_path = Path("/tf/airt/data/testing/raw")

get_suffixes[source]

get_suffixes(path:"input directory containing images", verbose:""=True)

Returns all unique suffixes

actual = get_suffixes(dropbox_path)

expected = set([".jpg", ".xmp", ".tif", ".cr2", ".mov", ".info"])

assert actual == expected, f"{actual} != {expected}"
['.tif', '.info', '.xmp', '.jpg', '.mov', '.cr2']
actual = get_rand_file_with_suff(dropbox_path, ".JpG")
display(actual)

assert isinstance(actual, Path)
assert actual.exists()
assert actual.is_file()
assert actual.suffix.lower() == ".jpg"
Path('/tf/airt/data/testing/raw/070728_10_1_0012.JPG')
display(get_one_image_for_each_suffix(dropbox_path))
assert len(get_suffixes(dropbox_path, verbose=False)) == len(
    get_one_image_for_each_suffix(dropbox_path)
)
[Path('/tf/airt/data/testing/raw/Grga_18062007_1_1_001-1.tif'),
 Path('/tf/airt/data/testing/raw/ZbThumbnail.info'),
 Path('/tf/airt/data/testing/raw/070828_20_1_0040.JPG.xmp'),
 Path('/tf/airt/data/testing/raw/070728_10_1_0012.JPG'),
 Path('/tf/airt/data/testing/raw/MVI_3536.MOV'),
 Path('/tf/airt/data/testing/raw/140830_47_1_1113.CR2')]
expected_path = Path("../../data/testing/raw")
actual = create_sample_test_dir_if_needed()
assert expected_path.exists()
assert len(actual) > 0
actual
[Path('../../data/testing/raw/070828_20_1_0040.JPG.xmp'),
 Path('../../data/testing/raw/ZbThumbnail.info'),
 Path('../../data/testing/raw/Grga_18062007_1_1_001-1.jpg'),
 Path('../../data/testing/raw/070728_9_1_0012.JPG'),
 Path('../../data/testing/raw/140830_47_1_1113.CR2'),
 Path('../../data/testing/raw/Grga_18062007_1_1_001-1.tif'),
 Path('../../data/testing/raw/070728_10_1_0012.JPG'),
 Path('../../data/testing/raw/MVI_3536.MOV'),
 Path('../../data/testing/raw/.ipynb_checkpoints')]
with TemporaryDirectory() as src_dir:
    src_dir = Path(src_dir) / "raw"
    copytree("../../data/testing/raw/", src_dir)
    tif_path = [x for x in src_dir.glob("*.tif")][0]
    new_tif = tif_path.parent / (tif_path.stem + "_copy" + tif_path.suffix)
    print(f"NEW tif {new_tif}")
    copy(tif_path, new_tif)
    before_files = [x for x in src_dir.glob("*")]
    jpg_before = [x for x in before_files if x.suffix.lower() == ".jpg"]
    for image_path in src_dir.glob("*"):
        dst, msg = convert_image_to_jpg_darktable(image_path, remove_src=True)
        assert not dst or dst.exists()
        print(msg)
    after_files = [x for x in src_dir.glob("*")]
    assert len(before_files) == len(after_files) + 2
    display(sorted(before_files))
    display(sorted(after_files))
    jpg_after = [x for x in after_files if x.suffix.lower() == ".jpg"]
    assert len(jpg_after) == len(jpg_before) + 2

    for img_after in jpg_after:
        if img_after.suffix.lower() == ".jpg":
            print(img_after)
            display(Image.open(img_after).resize((300, 200)))
NEW tif /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.tif
Processing /tmp/tmpfcvln3_9/raw/070828_20_1_0040.JPG.xmp
Converted error 256, image path /tmp/tmpfcvln3_9/raw/070828_20_1_0040.JPG.xmp.
Processing /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.tif
Converted /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.tif to /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.jpg.
Processing /tmp/tmpfcvln3_9/raw/ZbThumbnail.info
Converted error 256, image path /tmp/tmpfcvln3_9/raw/ZbThumbnail.info.
Processing /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg
Skiped path /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Processing /tmp/tmpfcvln3_9/raw/070728_9_1_0012.JPG
Skiped path /tmp/tmpfcvln3_9/raw/070728_9_1_0012.JPG because it is already a JPEG.
Processing /tmp/tmpfcvln3_9/raw/140830_47_1_1113.CR2
Converted /tmp/tmpfcvln3_9/raw/140830_47_1_1113.CR2 to /tmp/tmpfcvln3_9/raw/140830_47_1_1113.jpg.
Processing /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.tif
Removed /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.tif because /tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg exists.
Processing /tmp/tmpfcvln3_9/raw/070728_10_1_0012.JPG
Skiped path /tmp/tmpfcvln3_9/raw/070728_10_1_0012.JPG because it is already a JPEG.
Processing /tmp/tmpfcvln3_9/raw/MVI_3536.MOV
Removed /tmp/tmpfcvln3_9/raw/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Processing /tmp/tmpfcvln3_9/raw/.ipynb_checkpoints
Converted error 35584, image path /tmp/tmpfcvln3_9/raw/.ipynb_checkpoints.
[Path('/tmp/tmpfcvln3_9/raw/.ipynb_checkpoints'),
 Path('/tmp/tmpfcvln3_9/raw/070728_10_1_0012.JPG'),
 Path('/tmp/tmpfcvln3_9/raw/070728_9_1_0012.JPG'),
 Path('/tmp/tmpfcvln3_9/raw/070828_20_1_0040.JPG.xmp'),
 Path('/tmp/tmpfcvln3_9/raw/140830_47_1_1113.CR2'),
 Path('/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg'),
 Path('/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.tif'),
 Path('/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.tif'),
 Path('/tmp/tmpfcvln3_9/raw/MVI_3536.MOV'),
 Path('/tmp/tmpfcvln3_9/raw/ZbThumbnail.info')]
[Path('/tmp/tmpfcvln3_9/raw/.ipynb_checkpoints'),
 Path('/tmp/tmpfcvln3_9/raw/070728_10_1_0012.JPG'),
 Path('/tmp/tmpfcvln3_9/raw/070728_9_1_0012.JPG'),
 Path('/tmp/tmpfcvln3_9/raw/070828_20_1_0040.JPG.xmp'),
 Path('/tmp/tmpfcvln3_9/raw/140830_47_1_1113.jpg'),
 Path('/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg'),
 Path('/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.jpg'),
 Path('/tmp/tmpfcvln3_9/raw/ZbThumbnail.info')]
/tmp/tmpfcvln3_9/raw/140830_47_1_1113.jpg
/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1.jpg
/tmp/tmpfcvln3_9/raw/070728_9_1_0012.JPG
/tmp/tmpfcvln3_9/raw/070728_10_1_0012.JPG
/tmp/tmpfcvln3_9/raw/Grga_18062007_1_1_001-1_copy.jpg

convert_files_with_darktable[source]

convert_files_with_darktable(root_path:"input directory containing images to convert", remove_src:"input True if you want to delete the images "=True)

Calls the convert_image_to_jpg() function on all images in the path

with TemporaryDirectory() as src_dir:
    src_dir = Path(src_dir) / "raw"
    copytree("../../data/testing/raw/", src_dir)
    copytree("../../data/testing/raw/", src_dir / "jedan")
    copytree("../../data/testing/raw/", src_dir / "jedan" / "dva")
    copytree("../../data/testing/raw/", src_dir / "tri")
    copytree("../../data/testing/raw/", src_dir / "tri" / "cetiri")
    files_before = list(src_dir.glob("**/*"))

    # the main thing
    convert_files_with_darktable(src_dir, remove_src=True)

    files_after = list(src_dir.glob("**/*"))

    assert (
        len(files_before) == len(files_after) + 10
    ), f"len({files_before}) != len({files_after})"
[  39/40] Processing /tmp/tmp286mcg1e/raw/tri/cetiri/ZbThumbnail.info [Elapsed Time: 0:00:10] ||100.00% (Time:  0:00:10) 1) 01) 
Conversion completed 40/40
Skiped path /tmp/tmp286mcg1e/raw/070728_10_1_0012.JPG because it is already a JPEG.
Skiped path /tmp/tmp286mcg1e/raw/070728_9_1_0012.JPG because it is already a JPEG.
Converted error 256, image path /tmp/tmp286mcg1e/raw/070828_20_1_0040.JPG.xmp.
Converted /tmp/tmp286mcg1e/raw/140830_47_1_1113.CR2 to /tmp/tmp286mcg1e/raw/140830_47_1_1113.jpg.
Skiped path /tmp/tmp286mcg1e/raw/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Removed /tmp/tmp286mcg1e/raw/Grga_18062007_1_1_001-1.tif because /tmp/tmp286mcg1e/raw/Grga_18062007_1_1_001-1.jpg exists.
Removed /tmp/tmp286mcg1e/raw/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Converted error 256, image path /tmp/tmp286mcg1e/raw/ZbThumbnail.info.
Skiped path /tmp/tmp286mcg1e/raw/jedan/070728_10_1_0012.JPG because it is already a JPEG.
Skiped path /tmp/tmp286mcg1e/raw/jedan/070728_9_1_0012.JPG because it is already a JPEG.
Converted error 256, image path /tmp/tmp286mcg1e/raw/jedan/070828_20_1_0040.JPG.xmp.
Converted /tmp/tmp286mcg1e/raw/jedan/140830_47_1_1113.CR2 to /tmp/tmp286mcg1e/raw/jedan/140830_47_1_1113.jpg.
Skiped path /tmp/tmp286mcg1e/raw/jedan/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Removed /tmp/tmp286mcg1e/raw/jedan/Grga_18062007_1_1_001-1.tif because /tmp/tmp286mcg1e/raw/jedan/Grga_18062007_1_1_001-1.jpg exists.
Removed /tmp/tmp286mcg1e/raw/jedan/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Converted error 256, image path /tmp/tmp286mcg1e/raw/jedan/ZbThumbnail.info.
Skiped path /tmp/tmp286mcg1e/raw/jedan/dva/070728_10_1_0012.JPG because it is already a JPEG.
Skiped path /tmp/tmp286mcg1e/raw/jedan/dva/070728_9_1_0012.JPG because it is already a JPEG.
Converted error 256, image path /tmp/tmp286mcg1e/raw/jedan/dva/070828_20_1_0040.JPG.xmp.
Converted /tmp/tmp286mcg1e/raw/jedan/dva/140830_47_1_1113.CR2 to /tmp/tmp286mcg1e/raw/jedan/dva/140830_47_1_1113.jpg.
Skiped path /tmp/tmp286mcg1e/raw/jedan/dva/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Removed /tmp/tmp286mcg1e/raw/jedan/dva/Grga_18062007_1_1_001-1.tif because /tmp/tmp286mcg1e/raw/jedan/dva/Grga_18062007_1_1_001-1.jpg exists.
Removed /tmp/tmp286mcg1e/raw/jedan/dva/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Converted error 256, image path /tmp/tmp286mcg1e/raw/jedan/dva/ZbThumbnail.info.
Skiped path /tmp/tmp286mcg1e/raw/tri/070728_10_1_0012.JPG because it is already a JPEG.
Skiped path /tmp/tmp286mcg1e/raw/tri/070728_9_1_0012.JPG because it is already a JPEG.
Converted error 256, image path /tmp/tmp286mcg1e/raw/tri/070828_20_1_0040.JPG.xmp.
Converted /tmp/tmp286mcg1e/raw/tri/140830_47_1_1113.CR2 to /tmp/tmp286mcg1e/raw/tri/140830_47_1_1113.jpg.
Skiped path /tmp/tmp286mcg1e/raw/tri/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Removed /tmp/tmp286mcg1e/raw/tri/Grga_18062007_1_1_001-1.tif because /tmp/tmp286mcg1e/raw/tri/Grga_18062007_1_1_001-1.jpg exists.
Removed /tmp/tmp286mcg1e/raw/tri/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Converted error 256, image path /tmp/tmp286mcg1e/raw/tri/ZbThumbnail.info.
Skiped path /tmp/tmp286mcg1e/raw/tri/cetiri/070728_10_1_0012.JPG because it is already a JPEG.
Skiped path /tmp/tmp286mcg1e/raw/tri/cetiri/070728_9_1_0012.JPG because it is already a JPEG.
Converted error 256, image path /tmp/tmp286mcg1e/raw/tri/cetiri/070828_20_1_0040.JPG.xmp.
Converted /tmp/tmp286mcg1e/raw/tri/cetiri/140830_47_1_1113.CR2 to /tmp/tmp286mcg1e/raw/tri/cetiri/140830_47_1_1113.jpg.
Skiped path /tmp/tmp286mcg1e/raw/tri/cetiri/Grga_18062007_1_1_001-1.jpg because it is already a JPEG.
Removed /tmp/tmp286mcg1e/raw/tri/cetiri/Grga_18062007_1_1_001-1.tif because /tmp/tmp286mcg1e/raw/tri/cetiri/Grga_18062007_1_1_001-1.jpg exists.
Removed /tmp/tmp286mcg1e/raw/tri/cetiri/MVI_3536.MOV because .mov is in ['.mov', '.mp4']
Converted error 256, image path /tmp/tmp286mcg1e/raw/tri/cetiri/ZbThumbnail.info.