bv is a small tool to quickly view high-resolution multi-band imagery directly in your iTerm 2. It was designed for visualising very large images located on a remote machine over a low-bandwidth connection. It subsamples and compresses the image sends it over the wire as a base64-encoded PNG (hence the name "bv") that iTerm 2 inlines in your terminal.
Now, go and compare the above to old-school rendering or my other tool tv. Welcome to 2017!
Here are a number of examples that show how this tool can be used.
Display a 3.5 billion pixel single-band image (3.3GB) using only 467KB over a SSH connection.
Display a six-band image (7.2GB) using only 1.1MB over a SSH connection. Here,
we put bands 5-4-3 into the RGB channels using -b 5 -b 4 -b 3
(ordering
matters) and set the width of the output image to be 600 pixels using -w 600
.
You can also specify a single band to display (e.g., -b 1
).
You can subset images using gdal_translate
syntax which is -srcwin xoff yoff xsize ysize
. For example, only displaying a small 1000x1000 area of the same large image above.
This allows you to quickly identify regions of your image and then paste the same options
into gdal_translate
to complete your desired workflow. For example:
remote$ gdal_translate tasmania-2014.tif -b 5 -b 4 -b 3 -srcwin 12000 11000 1000 1000 -of PNG -ot UInt16 -scale 0 4000 ~/out.png
Input file size is 20000, 16000
0...10...20...30...40...50...60...70...80...90...100 - done.
remote$
Sometimes you might have a single-band image that only contains classes
(integers). Different color maps can be applied to these single-band images
using the -cm
option and any choice from matplotlib's
colormaps.
The bv tool can read from URLs (see the Trump image above). It can also
parse URLs on stdin
, this allows you to do
things like this to quicky
display available Landsat images roughly over Dubai.
remote$ landsat search --lat 25 --lon 55 --latest 3 | bv -urls -
Filenames can be read from stdin
. For example:
ls -1 *.tif | bv -w 100 -
The level of compression can be changed using the -zlevel
option (0-9).
If your bands are located in seperate images then you can stack them and display them in the RGB channels using
bv -stack RED.tif GREEN.tif BLUE.tif
There is also the -revstack
option to do it in reverse order.
The subsampling algorithm can be changed using the -r
option (same syntax as GDAL). The available subsamplings are:
- Nearest
- Average
- Cubic Spline
- Cubic
- Mode
- Lanczos
- Bilinear
For single-band images, you can specify the color value to set as the alpha channel. This is sometimes useful for machine learning outputs where you want to not display certain classes. You can add multiple of these with different values.
The bv tool will display PDF, EPS, and PNG output inline with out any
changes to those files. If you want to disable this behaviour you can pass the
-nop
option allow GDAL to subsample, etc.
You can save your default configuration by setting an alias in your ~/.profile
file. For example, I do:
alias bv='bv -w 800'
It is just a single-file script so all you'll need to do it put it in your
PATH
. Dependencies are Python 3, GDAL 2, Numpy, Matplotlib, and iTerm 2. I've
found that the best way to install these dependencies are:
# Python 3
brew install python3
# Numpy and matplotlib
pip3 install numpy matplotlib
# GDAL 2
brew install gdal --HEAD --without-python
pip3 install gdal