# Advice on on-line processing of time series

**URL:** https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330
**Category:** Algorithms
**Created:** [September 9, 2022, 9:05pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330 "2022-09-09T21:05:16Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![SteveRobbins](https://discourse.itk.org/user_avatar/discourse.itk.org/steverobbins/32/2446_2.png) [@SteveRobbins](https://discourse.itk.org/u/SteveRobbins)
#### Post date: [September 9, 2022, 9:05pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/1 "2022-09-09T21:05:17Z")

</div>

I’m writing code that accepts a time series of 3D images and want to process it on-line; i.e. as they come in. I’m not seeing this topic discussed so maybe it’s too esoteric or maybe I haven’t found the right keywords.

The basic example is that I want to do things like keep statistics on the last N time points like a moving average and variability measure - say to identify noisy regions. I am about to roll my own using RingBuffer and some N-ary filters. Basically I’m wondering if there is something already out there that I’ve missed. Any advice on pitfalls or best practices would also be appreciated.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 12, 2022, 6:09pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/2 "2022-09-12T18:09:37Z")

</div>

That sounds like an esoteric topic. Do you need to keep a ring buffer of images, or only the last N statistics? 3D images are usually big.

---

<div class="post-metadata">

### Author: ![SteveRobbins](https://discourse.itk.org/user_avatar/discourse.itk.org/steverobbins/32/2446_2.png) [@SteveRobbins](https://discourse.itk.org/u/SteveRobbins)
#### Post date: [September 12, 2022, 7:57pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/3 "2022-09-12T19:57:23Z")

</div>

Edited because I mis-read your question. In truth, I only need the statistics for the last N (N around 8-10). But I do want statistics at each pixel.

I guess you’re hinting at algorithms to do on-line stats that are updateable? I’m aware of Wedford’s algorithm for mean and variance. But I don’t know how one might update to remove the oldest data as the window slides without storing the oldest image.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 12, 2022, 8:07pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/4 "2022-09-12T20:07:56Z")

</div>

What I imagined: compute statistics for image i, put the statistics into the ring buffer (stat[i]), then compute current statistics by using a for loop over stat array and combining stat[0]…stat[i] or stat[i-N]…stat[i]. At i+1, you will combine stat[i+1-N]…stat[i+1] into current statistics.

---

<div class="post-metadata">

### Author: ![SteveRobbins](https://discourse.itk.org/user_avatar/discourse.itk.org/steverobbins/32/2446_2.png) [@SteveRobbins](https://discourse.itk.org/u/SteveRobbins)
#### Post date: [September 13, 2022, 3:48pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/5 "2022-09-13T15:48:17Z")

</div>

I found some mention of “video in ITK” from a 2010 meeting: [https://www.paraview.org/Wiki/ITK/Fall\_v4\_2010\_Meeting](https://www.paraview.org/Wiki/ITK/Fall_v4_2010_Meeting)

The slides do describe some of the issues I am facing, and propose a class itk::ImageSet (ImageSequence, ImageBag) that sounds like it could be useful to me. Since I cannot find any such classes in ITK, I’m presuming the proposal did not move forward. I’d be curious to know whether the use cases in the slides were met by other means.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 13, 2022, 3:51pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/6 "2022-09-13T15:51:30Z")

</div>

@hjmjohnson might remember.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 13, 2022, 4:38pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/7 "2022-09-13T16:38:56Z")

</div>

There is the whole [ITKVideo](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Video) group that I believe came out of that work. It includes a [RingBuffer](https://itk.org/Doxygen/html/classitk_1_1RingBuffer.html). I have never used the group myself.

---

<div class="post-metadata">

### Author: ![SteveRobbins](https://discourse.itk.org/user_avatar/discourse.itk.org/steverobbins/32/2446_2.png) [@SteveRobbins](https://discourse.itk.org/u/SteveRobbins)
#### Post date: [September 26, 2022, 6:19pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/8 "2022-09-26T18:19:01Z")

</div>

Thanks! I had found the ring buffer, but not the rest of the video group, The VideoStream seems really interesting.

My use case is a stream of images from the scanner with no pre-determined number of frames – we receive images until the operator ends the scan. The VideoStream, in contrast appears to require a pre-determined number of frames – in order to set up the TemporalRegion. At least that is my current understanding based on prototyping a few things using the ImageToVideoFilter and reading the code for the VideoFileReader. If the above is incorrect, please let me know!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 26, 2022, 7:36pm UTC](https://discourse.itk.org/t/advice-on-on-line-processing-of-time-series/5330/9 "2022-09-26T19:36:21Z")

</div>

@Tom_Birdsong I think you last touched files in Video group?

@brad-t-moore might have some advice too.
