Cutting out snails made easy (part 1)

Jens Dobberthin

By Jens Dobberthin
16.07.2018 | 20 minutes reading time

At the last Coding da Vinci hackathon , the SnailSnap team showed you how to get sluggish yourself. In the first part of our series of blog entries on programming we show you how to cut the snails out automatically and then use them creatively.

The collection Mollusca of the Museum für Naturkunde Berlin is a real eye-catcher. With about 5 million pieces it is one of the most extensive collections of the museum. But the sheer abundance of the collection can only be guessed when we programme something. At the end of this blog entry, you have all the material for a video that shows you the beauty of the collection.

Here you can have a look at it:

Snaiils video, Licence: CC-BY-SA

In order to follow the instructions below, you need some knowledge of Linux. If you get stuck at some point, ask someone who can help you.

You can find the source code for the snail-cutting tool on GitHub . For this blog we’re using a customized version to make things a little easier. Open a terminal and enter the following:

$ git clone https://github.com/jdobber/mollex
$ cd mollex
$ meson --buildtype=debug build
$ ninja -C build

Now you should find the program mollex in the directory build. To use it, we have to download the image files (scans) with the snails. You can view the scans in a gallery on the web. Fortunately, you don’t have to download them all one by one, because there is a small shell script, which does the work. Before you start the script, be aware that you are now downloading a few gigabytes (16 GB to be precise). So make sure that you have enough space on your hard disk before you enter the following into the terminal:

$ ./crawl.sh

Next you will need the metadata for the scans. The meta data indicates e.g. which snail is in which image file. You get the metadata as follows:

$ wget http://gbif.naturkundemuseum-berlin.de/CDV2018/Mollusken/Metadaten/species_list.csv

The mollex program expects the images in the directory images and stores the cut out snails in the directory out. So we prepare everything for this:

$ ln -s data/gbif.naturkundemuseum-berlin.de/CDV2018/Mollusken/Arten images
$ mkdir out

But now you are ready and can start cutting the snails out:

$ ./src/mollex

This may take a while, but in the end the snails are well cut out in the directory out. If you don’t want to wait that long, you can always abort. You can also do the following with a small subset of the snails.

But how do we get to our little video? To get a feeling for how many there actually are, we want to show them one by one. In addition, there should be a small counter and a progress bar as visual feedback. After all, we want to know how many snails are still waiting for us. And for the biology fans among us we will of course also display the scientific name.

For the implementation we use Processing , a free software, which is often used by artists for programming.

Our mollex program has written the file meta_file.csv into the directory out. We have to read this file in, because then we can assign the individual image files to the correct scientific name. But beforehand we have to convert all ; into , so that Processing can process the file. It works like this:

sed -i 's/;/,/g' out/meta_file.csv

Now we are ready for our sketch in Processing. Start Processing and copy the following code:

 1String path = "/home/jens/spielwiese/experimental/mollex/out/";
 2String metaFile = path + "meta_file.csv";
 3
 4PImage img= null;
 5int counter = 0 ;
 6int width = 854;
 7int height = 480;
 8int x = width / 2;
 9int y = height / 2;
10
11boolean rec = false;
12boolean stopped = false;
13
14Table table;
15String imageName;
16String sciName;
17String[] strList;
18String prefix = "http://coll.mfn-berlin.de/u/";
19
20int maxCounts = 100;
21int steps = 10;
22int progressBarWidth = 0;
23
24void setup() {
25
26  table = loadTable(metaFile, "header");
27  maxCounts = table.getRowCount() - 1;
28
29  steps = width / maxCounts;
30
31  println(table.getRowCount() + " total rows in table");
32  size(854, 480);  
33}  
34
35void draw() {
36
37  if (!stopped) {
38    background(0);
39    img = loadImage(path + table.getRow(counter).getString("Image"));
40
41    imageMode(CENTER);
42    image(img, x, y);    
43
44
45    textSize(18);
46    textAlign(CENTER, BOTTOM);
47    text(table.getRow(counter).getString("Scientific Name"), x, height - 40);
48
49    strList = split(table.getRow(counter).getString("Image"), "_");
50    textSize(12);
51    textAlign(CENTER, BOTTOM);
52    text(prefix + strList[0] + "_" + strList[1] + "_" + strList[2], x, height - 20);
53
54
55    textSize(12);
56    textAlign(LEFT, TOP);
57    text(table.getRow(counter).getString("Class") + " >> " +
58      table.getRow(counter).getString("Family") + " >> " +
59      table.getRow(counter).getString("Genus") + " >> " +
60      table.getRow(counter).getString("Species"),
61      20, 10);
62    textAlign(RIGHT, TOP);
63    text(maxCounts - counter, width - 40, 10);
64
65    strokeWeight(4);
66    fill(0, 154, 186);
67    rect(0, height - 10, width - map(counter, 0, maxCounts, 0, width), height);
68
69    fill(255);      
70
71    if (rec) {
72      saveFrame("output/mol_####.tif");
73    }
74
75    delay(500);
76
77    counter += 1;
78    if (counter > maxCounts)
79    {
80      counter = 0;
81    }
82  }
83}
84
85void keyPressed() {
86  if (key == 'r' || key == 'R') {
87    rec = !rec;
88  }
89  println(rec);
90  if (key == 's' || key == 'S') {
91    stopped = !stopped;
92  }
93}

In line 1 you have to adjust the path so that Processing can find your cut snails. In line 27 you can set maxCounts to 10 (or another value), then only the first 10 snails will be displayed and not all of them.

Everything clear so far? Then you can press the play button.

With the s button you can stop or continue the run. With r you can record the single frames and create a video from them. The frames are saved in the directory out/frames.

Play a little with the code. Maybe you have other ideas what you can do with snails. Then write us . We are curious.

In the next part, we show you how to get the exact coordinates of the snails in the original frames.