XOR of consecutive frames

234 views
Skip to first unread message

Nikolas Karalis

unread,
Apr 2, 2016, 9:05:57 AM4/2/16
to Bonsai Users
I would like to calculate the XOR between the current frame and the previous frame.
However, I cannot figure out how I can at each frame get these two frames and feed them to the XOR operator.
Any ideas?

Thanks in advance!

goncaloclopes

unread,
Apr 2, 2016, 10:11:55 AM4/2/16
to Bonsai Users
You can do something like this, with Skip set to 1:


In general for this pattern you Zip a stream that skips the first element with the normal stream and then apply the operation. Remember that Zip always combines the two input streams pairwise, no matter when the inputs arrive and produces an output only when new pairs are formed.


In this case the first stream is [F1, F2, F3, ...] and the second stream is [F0, F1, F2, ...] so you end up with [(F1,F0),(F2,F1),(F3,F2), ...].

There are also ways to generalize comparisons across N frames but I'll leave that as an exercise.


Hope this helps,

Hideki Miwa

unread,
Sep 28, 2019, 5:35:59 AM9/28/19
to Bonsai Users
Hi everyone,

Let me join a discussion about this topic.
Using the "Xor" operator, I'm trying to calculate the change in the mouse body area between two frames during behavior tests, including tail suspension test, forced swim test, and fear conditioning test to detect the freezing behaviors (I want to define "freezing" behaviors when the area is under an area size for my freezing criteria).

I've made a workflow like the attached file, but it doesn't looks like work well.
I used "Count" as the output value for calculating the mouse area. The value was not close to zero even when the mouse stopped the movement.

Furthermore, I used the "ImageData" as the direct output from "Xor" operation but the value was so large that I could not understand what it actually meant.

What's wrong with my workflow?
I will appreciate your help with this situation.

Best,
Hideki

2016年4月2日土曜日 23時11分55秒 UTC+9 goncaloclopes:
xor freezing.jpg

Gonçalo Lopes

unread,
Oct 31, 2019, 7:26:50 PM10/31/19
to Hideki Miwa, Bonsai Users
Hi Hideki,

Maybe you have found a different way to solve this problem already, but the easiest way to detect whether there are changes over time in the image is to directly use the BackgroundSubtraction node, with AdaptationRate property set to 1. In this case, background subtraction will compute every pixel change frame-by-frame over time. If you set some small value in the Threshold property to filter out camera noise, you can then use Sum to compute total area motion. Something like this:

image.png

You can then use the LessThan operator to search for moments of quietude. If you need a bigger time window, you can filter the result of Sum with a low-pass filter, like so:

image.png

Make sure to set the filter SampleRate and Cutoff to match desired frequencies (e.g. if your camera is a 30Hz camera, SampleRate and KernelLength should be 30, and Cutoff should be in Hz for the filter as well).

Hope this helps!


--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/3081de41-f879-42e1-8c23-595342ca16ec%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages