# Software Application for Automatic Detection and Analysis of Biomass in Underwater Videos
## 2 Software Application Description
### Application Core: Deepview  
The application core, named DeepViewCore, was developed using the Python programming language and is responsible for processing videos from the database. It is based on the OpenCV library [32]. This software application is available on the official Python repository [33]. Prior to the design and implementation of a functional software application version, an initial analysis of the underwater images was conducted. The presence of non-uniform illumination and noise arising from the dark current introduces errors in item detection within underwater images. It is crucial to note that the gray value of the image background varies depending on factors such as the power of the spotlights and water conditions (Figure 2a,b). This variability poses a challenge to calculating a fixed threshold through a histogram study in the detection process. DeepViewCore is a modular pipeline architecture that consists of two main stages: preprocessing and processing. This design enables seamless maintenance operations, such as replacing or adding modules, thanks to its pipeline structure. The preprocessing stage, illustrated in Figure 3, is composed of three steps: to_gray, top_hat, and de-noise. These steps allow for a more accurate estimation of the threshold level on the grayscale image, leading to improved item detection. In order to enhance the detection of ITEMS, it is essential to address two factors: correcting the non-uniform illumination and subtracting the noise due to the dark current from underwater images. For the purpose of homogenizing the background illumination, a top-hat filter was employed [34; 35]. The outcomes of this process, using a rectangular structuring element with dimensions 9 by 9, are presented in Figure 4. It can be observed that by homogenizing the image's background, the contrast between the background and the targeted items to be detected is significantly improved. Figure 3: Block diagram of the preprocessing phase. Figure 2: (a) Underwater original image; (b) Inhomogeneous illumination grayscale. Another crucial source of noise that requires consideration is the \"dark current\", which refers to the electrical current flowing through a camera sensor even in the absence of incident photons. This phenomenon is thermally induced, resulting from the spontaneous generation of electrons within the silicon material of the sensor [31]. One of the primary challenges arises from the presence of pixels in the detector exhibiting notably high dark currents, commonly referred to as \"hot pixels\". These hot pixels can emit brightness levels comparable to the signals of interest that we aim to detect. Applying a thresholding technique can effectively eliminate the hot pixels but may lead to substantial loss of image information since it sets a minimum detectable brightness level. Median filtering proves useful in eliminating hot pixels, as they are often isolated, but it can also introduce image smoothing and limit the minimum detectable size of items. To mitigate the influence of the thermally generated signal in the image, we employed a method involving the subtraction of \"dark images\". These dark images are captured under the same temperature conditions as the images being processed and are obtained from video sections recorded with the light source turned off. The processing stage takes the preprocessed frame as input, as shown in Figure 5. It includes a thresholding and binarization step, followed by a detection phase using the findContours module. The final detection algorithm identifies the items in the image by providing their coordinates (x, y), assigning a label and size, and estimating the total number of items. The implemented thresholding algorithm automatically computes the optimal threshold value using the Otsu method. However, this method encounters challenges when the signal density is low. To address this issue, it has been combined with an adaptive image equalization (AIE) process to enhance image contrast.