In this subsection, we describe the main procedure of our proposed water color identification algorithm, which includes four stages: (1) image color correction, (2) image segmentation, (3) candidate patch extraction, and (4) color identification of candidate patches.
2.2.1. Image Color Correction
Owing to the diverse changes in outdoor lighting conditions, errors may occur while identifying the water color unless the image color can be corrected. To make the correction easy and stable, we used a color checkerboard to correct the color information of the captured image. Because the information of 24 color blocks on this checkerboard is known, a transformation for restoring the colors to their ideal values for capture can be found. Thus, the color of each image shot was corrected using this transformation. In our method, the checkerboard is first localized using the four ArUco markers. Given an image containing ArUco markers, the position and ID number of each marker can be easily obtained using the algorithm in [
38]. Furthermore, the popular open-source library OpenCV provides an ArUco module for generating and detecting these markers [
37]. From the relative positions of the four markers, the region of interest (ROI) was extracted and then normalized to a predefined size. Consequently, 24 smaller color blocks were obtained simply from this normalized ROI because the layout of the checkerboard was designed by us.
Figure 4 shows the results of the extraction of the ROI and its 24 small color blocks.
Let
be the mean
value of all pixels inside the
-th small color block, where
. It is first converted into the CIE
color model via the following transformation formulae:
where
,
,
, and
For an image captured at timestamp
, there are 24 vectors
for
representing 24 color blocks. Let
be the ground truth of the
-th color block, which can be derived from the
values listed in
Table 1, and (1)–(3). We assume that there exists a transformation matrix
denoted by:
which can be applied to correct the real-world captured
back to the ground truth
. Consequently, the matrix
can be estimated using the least-squares error method as follows:
Equation (5) can be abbreviated as
. Vector
that is reshaped from
is solved using a pseudo-inverse.
Therefore, the color correction of an image can be implemented, by the steps of pseudocode summarized in the following Algorithm 1.
Figure 5 shows the results before and after color correction for a real scene. The image obtained after performing color correction is closer to that of the human eye.
Algorithm 1: Proposed color correction algorithm (Pseudocode) |
Input: an image capture (), with the size of image width () and image height () |
Output: an image after color correction |
1: | , , , //Initialize four marker positions |
2: | //Initialize ArUco marker dictionary |
3: | //Detect ArUco markers, return their positions and IDs by OpenCV |
4: | ) //Find transformation matrix (geometric homography) by OpenCV |
5: | //Normalize the ROI into the size pixels by OpenCV |
6: | Detect 24 color blocks in normalized ROI //Use OpenCV APIs to detect color blocks |
7: | for each color block in 1 to 24 do: |
8: | Calculate its mean value: , , |
9: | Convert to value from : , , through Equations (1)–(3). |
10: | end for |
11: | Calculate transformation matrix through Equations (4) and (6). |
12: | for every pixel in do: |
13: | Convert its value to |
14: | Compute the color-corrected value as |
15: | Transform the corrected value back to color model. |
16: | end for |
2.2.2. Image Segmentation and Candidate Patch Extraction
Before water color identification, it is critical to obtain an image patch that covers only the water surface. For a simpler description, we consider the image on the right in
Figure 5 as an example for describing the proposed method. It can be observed that there are some undesired objects, such as waterwheels and foams, that should be excluded during the process of water color identification. Therefore, in this subsection, we introduce a method for cropping several small patches that cover only the water surface. Our proposed method comprises two main stages: segmentation of the water region and extraction of water-only image patches.
Generally, several types of objects may appear in aquaculture ponds. In this study, we first implemented a pixel-level segmentation method based on the improved YOLACT architecture [
32]. Here, the implemented YOLACT-based model was further modified. To obtain precise segmentation results for a large capture, the backbone of this model was replaced by a ResNet-200 [
39], whose input achieved 700 × 700 pixels. Except for the water region, we additionally define three classes: the waterwheel, color checkerboard, and foams on water, which are further excluded while performing water segmentation. Certainly, these classes can be modified according to the needs of different aquaculture farms.
Figure 6 shows examples of these three classes, and
Figure 7 shows the results of the implemented segmentation method. For ease of observation, the water region is not illustrated. Therefore, the candidates of water patches used for color identification can be extracted from the segmented water regions without other undesired objects.
This step extracts a certain number of candidate image patches, which are classified in terms of their colors, from the water regions. According to our observational experience at many experimental sites, the distant part of the image is often affected by light reflection and refraction. Therefore, we prevented cropping the water patch in the upper one-third of the image. Let
denote an image patch with the size of
pixels; its position is generated randomly within the lower two-thirds of an image, as shown in
Figure 8. Assuming that there are
groups of foams and
represents the minimum distance from the patch
to the
-th foam contour, for
. Every
can be easily calculated by the well-known connected component labeling and image geometry techniques. Next, we define the intensity variable as the standard deviation
of the intensities of all the pixels within the patch, formulated as follows:
where
denotes every pixel in the patch, which is converted into grayscale with the pixel values
. A small intensity deviation implies that the patch is flat (or called textureless). The selection criterion for whether a specified patch is selected as a candidate for color identification is presented below.
“The farther the patch is distant from the foams and the flatter the patch texture is, the higher the probability that the patch will be selected as a candidate”.
In this study, a fuzzy inference system (FIS) is proposed to determine the above probability. Let
and
be the two antecedent variables of our proposed FIS, and
be its consequent variable. Here,
represents the minimal distance between the patch and all foams, and
implicitly expresses the flatness of the patch. Assuming that
ranges in
and
ranges in
, where
is the length of the diagonal of the lower two-thirds of the image and
for gray images. The fuzzy sets of the antecedent variables are depicted in
Figure 9, in which triangular and trapezoidal functions are selected as the membership functions. For the consequent variable,
is represented by equally spaced triangular membership functions, as shown in
Figure 10. The linguistic terms in Figs. 9 and 10 include: very small (VS), small (S), medium (M), large (L), and very large (VL). The parameters for defining the five fuzzy sets of antecedent variables were
and
. For simplicity, we only attempted to determine the values of
and
, and set
; meanwhile, the other parameters were equally spaced between them.
Table 2 lists the parameters determined by the trial-and-error method used in this study.
According to the aforementioned selection criterion for a water-only image patch, we used the variables
and
as two inputs in the proposed FIS and objectively constructed fuzzy rules using the above linguistic terms. For example:
The consequent variable
indicates the degree to which a specified crop is considered a water-only patch for the subsequent color identification process. All 25 fuzzy rules are listed in
Table 3. The
-th fuzzy rule can be formally written in the following format.
Here,
, and
,
, and
were selected from the fuzzy sets of
,
, and
, respectively. Whereas an input pair
enters the FIS and fires some fuzzy rules, the crisp output derived by the proposed FIS is obtained using the minimum inference engine and center-of-gravity defuzzification method [
40], as follows:
and
where
is the minimum operator and
is the universe of discourse of the consequent variable. Therefore, the derived degree
is proportional to its selection as a candidate for any specified image patch. The steps for extracting a certain number of candidate patches can be performed using the following Algorithm 2, which is summarized by pseudocode.
Algorithm 2: Proposed water-only candidate extraction algorithm (pseudocode) |
Input: a color-corrected image (), with the size of image width () and image height () |
Output: candidates for water-only patches. |
1: | //Initialize parameters |
2: | //Initialize a counter |
3: | //Initialize the threshold |
4: | while do: |
5: | , //Randomly generate pixel in lower 2/3 part |
6: | , , , //Determine the coordinates of corners |
7: | Crop the patch , whose upper-left corner is and the lower-right corner is |
8: | for in 1 to do: |
9: | //Set the minimum of s to be |
10: | end for |
11: | Calculate through Equations (7) and (8) |
12: | Import the input pair into the proposed FIS |
13: | Derive the crisp output of the FIS |
14: | if then do: |
15: | |
16: | n ← n + 1 |
17: | end if |
18: | end while |
2.2.3. Color Identification
In this subsection, a learning-based color identification method is applied to each of the candidate patches. Thus, most of the identified results can be regarded as the representative water color of the aquaculture pond. The classes of water color identification were divided into six major colors, including green, brown, red, yellow, dark, and blue, indexed in order from 001 to 006. They can be further subdivided into 19 types.
Table 4 lists the codes of these water colors, which match the aquatic product production and sales resume system provided by the FA-COA, Taiwan. In addition, there is another color type known as the unknown class. These color codes can vary according to national regulations.
To perform the task of color identification, a deep learning-based model with parts of feature extraction and classification was used in this study. Numerous backbones with deep architectures have verified the effectiveness of feature extraction. During the pre-research stage, we evaluated several popular feature extraction backbones, including VGG-16, VGG-19 [
33], ResNet-50 [
35], InceptionV3 [
41], and MobileNet [
42]. ResNet-50 was finally selected as the image extractor of our proposed model because it performed well in feature extraction in the experiments. This image extractor was followed by a fully connected network designed to perform classification.
Figure 11 illustrates the architecture of the proposed method for color identification. The details of its implementation and performance evaluation are described in
Section 3.3.