Instructions for Processing Focal Male Photos
Written by Chris Skalnik on Apr 24th, 2019
These instructions were written by Christopher Skalnik while working under Beau Alward in the Fernald Lab at Stanford University.
Copyright © 2019 Stanford University, All rights reserved. Note that this work is NOT released under the same license as the rest of the site.
This page was first posted on May 9, 2019, but it had previously been hosted elsewhere on this site. I made it a blog post so its link would be more permanent.
These instructions are for processing photos of focal males from dyad assays in the Fernald Lab.
ARalpha
and place it in the home folder (~/ARalpha
).fmPhotos
so that the path to one
photo called photo1.jpg
is ~/ARalpha/fmPhotos/photo1.jpg
.python --version
and python3 --version
. If
the python --version
command prints a version starting with 3
,
you are good to go. If you need to run python3
to get that version
to print, you will need to replace python
and pip
below with
python3
and pip3
.pip
command. We will do this in later
steps.This is how we combine all the images to decide what regions to crop out.
Download the overlay
tool from GitHub by going to its GitHub page
at https://github.com/U8NWXD/overlay, clicking the
Clone or download
button, and selecting Download ZIP
. Unzip the
downloaded file in the ARalpha
directory so that you have an
overlay.py
file at the path
~/ARalpha/overlay-master/overlay/overlay.py
. If you prefer to use
git
, you can instead run:
$ git clone https://github.com/U8NWXD/overlay.git overlay-master
To install the Python dependencies that overlay
needs, run
$ cd ~/ARalpha
$ pip install -r overlay-master/requirements.txt
to tell pip
to install all the dependencies listed in the
overlay
requirements file.
overlay
The shorthand reference for how to use the overlay
tool is:
overlay.py [mean | median] img1 img2 [additional images]
This means that to compute the overlay of all our images in
~/ARalpha/fmPhotos/
by computing the median of the pixel values, we
would run the following commands:
$ cd ~/ARalpha
$ overlay-master/overlay/overlay.py median fmPhotos/*
where the fmPhotos/*
will get expanded by your terminal (technically
it's expanded by bash) into a space-separated list of all the files in
fmPhotos/
. If you wanted to use the mean instead of the median, just
replace median
in the command with mean
. The result will be a file
~/ARalpha/composite_median.jpg
or ~/ARalpha/composite_mean.jpg
which
stores the composite image. Move this image into ~/ARalpha/fmPhotos/
.
Download the batch_crop
tool from GitHub by going to its GitHub
page at https://github.com/U8NWXD/batch_crop, clicking the
Clone or download
button, and selecting Download ZIP
. Unzip the
downloaded file in the ARalpha
directory so that you have an
overlay.py
file at the path
~/ARalpha/batch_crop-master/batch_crop/batch_crop.py
. If you
prefer to use git
, you can instead run:
$ git clone https://github.com/U8NWXD/batch_crop.git batch_crop-master
To install the Python dependencies that batch_crop
needs, run
$ cd ~/ARalpha
$ pip install -r batch_crop-master/requirements.txt
to tell pip
to install all the dependencies listed in the
batch_crop
requirements file.
batch_crop
To run batch_crop
, you just need to run the command
$ cd ~/ARalpha/batch_crop-master
$ python batch_crop/batch_crop.py
This will open up a graphical interface in a window you can use. On macOS Mojave, you may need to use light mode and slightly resize the window in order to see the button labels. Thanks to the answers to this StackOverflow post for helping me figure this out: https://stackoverflow.com/q/52529403.
Now, we need to select the regions we want to crop. We will use the
composite image we created with overlay
to choose these regions. We
can load that image by clicking the Load Image
button in the
batch_crop
window and selecting the composite image.
Next, click and drag on the image to draw out a rectangle. You can change your selection by just drawing another rectangle, which will replace the earlier one. For example, we might select the pectoral fin of the fish. Because we are using a composite image, this corresponds to where most of the photographed have their pectoral fins.
To make sure you can exactly replicate this crop in the future, click on
the Save Coordinates
button to save the coordinates of your selection.
Note that coordinates are stored as relative positions, so this file
will still work for differently-sized images.
Now, we are finally ready to make the crops. Click on
Crop All Matching Images
to generate crops for every file in the same
folder and with the same file extension as the loaded image. Each crop
will be of the selected region, but re-scaled for differently-sized
images. To move these photos into a separate folder, run the commands:
$ cd ~/ARalpha/fmPhotos
$ mkdir pectoral
$ mv *_cropped.jpg pectoral
This moves all the crops into a folder called pectoral
.
If in the future you want to replicate this crop, you can click on
Load Coordinates
and load in the file you saved off earlier.
Now you can repeat these steps for any other regions you wish to crop out. These crops can then be analyzed with other tools.