Why I made it
A research lab at a Swiss university studies how cells deal with bacteria. They film cells under a microscope for about two hours, one picture every 30 seconds, with bacteria that glow. Each time a cell takes in a bacterium, they want to know when it went in, and whether the cell broke it down or still had it at the end of the film.
Until now, someone sat with each film and scored it by hand, frame by frame, in a spreadsheet. One film is a few hundred frames with hundreds of cells, so that takes hours. It looked like work a computer should do, so I built it.
How it works
Functional explanation, with a video
A full analysis of a real film, from start to finish. The steps under the video follow along, and you can click one to jump there.
The window, part by partA closer look at what each part of the screen does.
1. Setting up
Load a film and choose how it's analysed. Click or hover a number.
- Load TIF File. Open a film straight from the microscope. The app shows its name, the number of frames and the size.
- Event Joining. Whether to join the pieces of one event that got split, for example when a bacterium goes out of focus for a moment. From gentle up to “Super aggressive”.
- Shared Cells. How long a bacterium may also be counted in a neighbouring cell before the event no longer counts. The ⓘ buttons explain each setting.
- Bacteria Detection. What counts as a bacterium. Here, only spots with a bright core that reaches at least yellow.
- Bacteria Tracking. How a bacterium is followed from frame to frame. “Own velocity” looks where its own recent motion says it will be.
- Cell Accuracy. Find the cells in every frame, the most accurate, or every third frame, about three times faster.
2. Reviewing
The app after an analysis of a real film. Click or hover a number.
- Run Analysis goes through the whole film. The smaller buttons redo only one step, which is much faster after changing a setting.
- Inspect. Click anywhere on the image to see what the app found at that spot.
- Export. How many events were found, confirmed and rejected, and the button that saves the Excel file.
- The film. Every event gets a box with its number and when it started. The selected one is blue.
- Moving through the film one frame or ten at a time, and choosing what to draw: cells, bacteria, events.
- The list of events. Here the researcher can add an event the app missed, merge two, split one, or undo.
- Confirm or reject. Confirmed events turn green, rejected ones are crossed out but kept. REVIEW marks the ones worth a second look.
Technical explanation
You open a film and press Run Analysis. The app goes through four steps:
- Detect the bacteria in every frame, by their bright core.
- Follow them from frame to frame, through short gaps and crossings.
- Find the cells, and keep track of each one for the whole film.
- Call the events. A bacterium that goes inside a cell starts an event. If it disappears, that's a kill, timed from the frame it went in. If it's still there when the film ends, it's a failed kill.
Then a researcher goes through the events, starting with the clearest ones. They can confirm, reject, move the start or end frame, split one event in two, or add one the app missed. Their review is saved next to the film, and the result is an Excel file with every event.
Under the hood it's Python. The cells are found by a deep learning model (Cellpose). Running it on every frame took too long on a normal Mac, so it runs on every third frame and the frames in between reuse the nearest result: the frames are 30 seconds apart and a cell only moves a couple of pixels in that time. The bacteria are found with classic image processing and linked into tracks with trackpy. A set of rules decides what counts as an event, for example when two bacteria are in the same cell and you can't tell which one was killed.
Working with the researchers
The app only helps if it fits the way the lab already works. The Excel file has the same columns as the sheet they used to fill in by hand, plus the outcome as a number they can count and average. The settings use their words, like "failed kill" and "shared cells", not mine.
Most of the work came from their feedback. They sent films and told me where the app was wrong: an event split in two because a bacterium went out of focus for a moment, a failed kill missed in a crowded part of the film, a bacterium that only passed by a cell counted as eaten. Each of those became a rule or a setting, and a new version for them to try.
| Event | Frame start | Frame end | Duration (frames) | Duration (min) | Outcome | Outcome code |
|---|---|---|---|---|---|---|
| 1 | 12 | 27 | 15 | 7.5 | Killed | 1 |
| 2 | 31 | 241 | 210 | 105.0 | Failed kill | 0 |
| 3 | 48 | 59 | 11 | 5.5 | Killed | 1 |
Measuring, not guessing
With image analysis it's easy to change a setting, look at one frame and decide it looks better. I wanted numbers instead. I made a reference set of frames with every cell outlined, and every version of the app is scored against it: how many cells it finds, how many it invents, and how well the outlines match.
That changed the decisions. My first approach used classic image processing, and tuning it with the reference set raised its score from 0.61 to 0.78. Measuring also showed why it still went wrong: two touching cells were often seen as one, because one of them never got a starting point. Fixing that halved the number of merged cells. In the end the numbers showed that a small deep learning model was clearly better, and fast enough when it only runs on every third frame. That is what the app uses now.
Every Excel file also records which version of the app made it, so any result can be traced back to the exact code that counted it.
Shipping it properly
The researchers aren't programmers, so it had to install like any other Mac app. It's signed and notarised by Apple, so it opens without a security warning, and there are builds for both Apple silicon and the older Intel Macs the lab actually has.
Everything runs on their own Mac. No film, image or result ever leaves it, which matters for unpublished research. The app checks its licence offline when it starts, and a small server on Cloudflare only hands out renewed licences, so if it's down nobody is blocked. The only thing it sends is anonymous usage counts, and the product site says exactly what and why.
The lab is now using it on their own films.