Skip to content

Commit

Permalink
Merge pull request #1684 from mdchia/master
Browse files Browse the repository at this point in the history
Adding README and reformatting of DJI image binner script
  • Loading branch information
pierotofy authored Aug 7, 2023
2 parents e84c77d + 820ea4a commit 9d15982
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
26 changes: 26 additions & 0 deletions contrib/exif-binner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# exif_binner.py

Bins multispectral drone images by spectral band, using EXIF data. Also verifies that each bin is complete (i.e. contains all expected bands) and can log errors to a CSV file. Excludes RGB images by default.

## Requirements

- [Pillow](https://pillow.readthedocs.io/en/stable/installation.html) library for reading images and EXIF data.
- [tqdm](https://github.com/tqdm/tqdm#installation) for progress bars - can be removed

## Usage

```
exif_binner.py <args> <path to folder of images to rename> <output folder>
```

Optional arguments:

- `-b`/`--bands <integer>`: Number of expected bands per capture. Default: `5`
- `-s`/`--sequential <True/False>`: Use sequential capture group in filenames rather than original capture ID. Default: `True`
- `-z`/`--zero_pad <integer>`: If using sequential capture groups, zero-pad the group number to this many digits. 0 for no padding, -1 for auto padding. Default: `5`
- `-w`/`--whitespace_replace <string>`: Replace whitespace characters with this character. Default: `-`
- `-l`/`--logfile <filename>`: Write processed image metadata to this CSV file
- `-r`/`--replace_filename <string>`: Use this instead of using the original filename in new filenames.
- `-f`/`--force`: Do not ask for processing confirmation.
- `-g`/`--no_grouping`: Do not apply grouping, only validate and add band name.
- Show these on the command line with `-h`/`--help`.
25 changes: 14 additions & 11 deletions contrib/exif-binner/exif_binner.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/usr/bin/env python3

# Originally developed by Ming Chia at the Australian Plant Phenomics Facility (Australian National University node)

# Usage:
# exif_binner.py <args> <path to folder of images to rename> <output folder>

# standard libraries
import sys
import os


import PIL
from PIL import Image, ExifTags
import shutil
from tqdm import tqdm
import re
import csv

import math
import argparse
parser = argparse.ArgumentParser()

# Usage:
# python exif_binner.py <args> <path to folder of images to rename> <output folder>
# other imports
import PIL
from PIL import Image, ExifTags
from tqdm import tqdm # optional: see "swap with this for no tqdm" below

parser = argparse.ArgumentParser()

# required args
parser.add_argument("file_dir", help="input folder of images")
Expand Down Expand Up @@ -77,9 +79,8 @@

print("Indexing images ...")

# Uses tqdm() for the progress bar, if not needed swap with
# for filename in os.listdir(file_dir):

# for filename in os.listdir(file_dir): # swap with this for no tqdm
for filename in tqdm(os.listdir(file_dir)):
old_path = os.path.join(file_dir, filename)
file_name, file_ext = os.path.splitext(filename)
Expand Down Expand Up @@ -143,6 +144,7 @@

# now sort and identify valid entries
if not args.no_grouping:
# for this_img in images: # swap with this for no tqdm
for this_img in tqdm(images):
if not this_img["valid"]: # prefiltered in last loop
continue
Expand All @@ -166,6 +168,7 @@
identifier = ""

# then do the actual copy
# for this_img in images: # swap with this for no tqdm
for this_img in tqdm(images):
old_path = os.path.join(file_dir, this_img["name"])
file_name, file_ext = os.path.splitext(this_img["name"])
Expand Down

0 comments on commit 9d15982

Please sign in to comment.