A Minimalist Image Viewer

Often when I want to use Ubuntu’s eye of gnome image viewer to view image files, I find that it becomes very slow and unresponsive when trying to open an image in a directory containing many other images. Recently I decided to look for an alternative. I wanted something minimal that would open images quickly and without fuss, and this is when I discovered feh.

feh

feh is an incredibly lightweight image viewer that can be used from the terminal. Simply pass the filename of an image or directory as an argument, or even a text file containing a list of filenames, and it will open the images one-at-a-time for viewing. Installing is as simple as

sudo apt-get install feh

Montages

Despite its minimalism, feh has some nice features. Creating a montage is as simple as running

feh -m images/ -b trans -W 200

where an optional background file (or trans, for transparent) can be specified with the -b flag, and the width of the montage can be limited with the -W flag. As shown below, feh nicely tiles the images in a grid, even when they are of different shapes and sizes. example montage made with feh

Labeling Images

More related to the topic of machine learning, it is also possible to sort images into categories using feh. This is especially useful for quickly creating a dataset of class-labeled images when developing a learning model. feh allows you to specify an action, which will execute every time a key is pressed. So using this simple bash script, it is possible to iterate over all images in a directory, and copying them to the appropriate directory by pressing the number keys.

#!/usr/bin/env bash
feh \
  --cycle-once \
  --action1 \
  "cp '%f' ~/data/cats/%n" \
  --action2 \
  "cp '%f' ~/data/dogs/%n" \
  --action3 \
  "cp '%f' ~/data/birds/%n" \
  --action4 \
  "cp '%f' ~/data/bears/%n" \
  "$1"  # this is the directory from which to read images

This script may be run as ./feh_labeling.sh ~/data/all-images/, and by pressing keys 1 through 4, the currently shown image may be copied to the corresponding directory. More sophisticated tasks are also possible using feh’s actions, for more information see the Ubuntu manual entry.

Conclusion

Thanks to its quick response time and flexible features, feh has now replaced eye of gnome as my image viewer of choice. Despite its apparent minimalism, it provides some very useful features for boosting productivity when working with image files.