Algorithms were developed in C++ to determine the position of the center of mass of the swim bladder for each fish. A background image was initialized as the average of the first 2000 frames and subsequently updated at regular intervals during each session. For each frame, the image of each swim channel was processed in parallel in real time during image acquisition. The corresponding portion of the current background image was first subtracted from each channel image. The result was rectified, smoothed with a median 3x3 filter, eroded using a kernel size 2, pixel values scaled up to maximize contrast, and then thresholded to yield a binary image. Contours were extracted from the binary image with the border following algorithm of Suzuki and Abe [46 (link)] as implemented in OpenCV [47 ] and their centers of mass calculated and recorded for subsequent off-line analysis. As multiple contours were sometimes found in the same frame, a custom Python script using Markov chains was applied in a post-processing step to determine in this case which of the resulting candidate positions to accept as the most likely true position given the previous history.
Free full text: Click here