Skip to content

Instantly share code, notes, and snippets.

@rcdilorenzo
Created November 3, 2018 17:32
Show Gist options
  • Save rcdilorenzo/97543dca1a5bebb17c70953c4fdccf95 to your computer and use it in GitHub Desktop.
Save rcdilorenzo/97543dca1a5bebb17c70953c4fdccf95 to your computer and use it in GitHub Desktop.
Sample code from rcd.ai blog post
#!/bin/bash
# resize-images.sh
# Preprocess Stanford Cars Dataset
# Stats for width
# ❯ ls cars_**/*.jpg |
# xargs -L1 identify -format "%w\n" |
# datamash min 1 max 1 mean 1 median 1
#
# 78 7800 700.49255483472 640
#
# Stats for height
# ❯ ls cars_**/*.jpg |
# xargs -L1 identify -format "%h\n" |
# datamash min 1 max 1 mean 1 median 1
#
# 41 5400 483.24584491813 426
function resize_images () {
mogrify -resize 640x480 \ # resize to this size
-background gray \ # fill with gray as needed
-gravity center \ # keep image centered
-extent 640x480 \ # set the image size
-format jpg \ # keep jpg format
-path resized \ # put images in a subfolder (no overwrite)
*.jpg # files to resize
}
# Make resize directories (if not exist)
mkdir -p cars_train/resized
mkdir -p cars_test/resized
# Resize train images
cd cars_train
resize_images
cd ..
# Resize test images
cd cars_test
resize_images
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment