A method and system for classifying fish fry based on a shape feature map
By generating conformal feature maps of the fish's body outline, snout tip, and caudal peduncle center, the problem of inconsistent preprocessing rules in fish species classification was solved, achieving stable classification input and improving classification accuracy.
Patent Information
- Application Number
- CN202611641711.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-22
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies struggle to unify fish body orientation and scale, preserve head-to-body ratio, body height distribution, and visible texture under a clear and repeatable set of preprocessing rules in fish classification. This leads to inconsistencies between classification inputs during the training and usage phases, affecting classification accuracy.
Fish body masks are generated by manually annotating the fish body outline, snout tip, and caudal peduncle center. The images are then aligned under uniform coordinates and scales to generate complete fish body, outline distance, local texture, and head neighborhood maps. These are combined into a four-grid shape-preserving feature map and used to train the YOLO26 classification model, ensuring the consistency of processing rules.
It achieves consistent fish length ratios under different shooting conditions, consistent contour distance maps, local texture statistics unaffected by background interference, preservation of relative head size relationships, provides stable input for classification models, and improves classification accuracy.
Smart Images

Figure CN123161271A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and aquatic image recognition technology, specifically to a method and system for generating conformal feature maps using fish body geometric annotations and classifying fish species using a map classification model. Background Technology
[0002] Fish species classification can be used for information processing of farmed fish, sample screening, and image-assisted fish recognition. For fish species with similar appearances, when classifying based solely on the entire image, the model may utilize both fish body features and background features simultaneously. Different shooting distances, fish orientations, lighting, and background conditions can cause differences in images of the same fish species, and can also make some images of different fish species appear similar. Silver carp and bighead carp are a group of similar fish species that can be used to study this problem.
[0003] The head-to-body ratio, body height distribution, and local texture of a fish can serve as candidate information for classification, but image preprocessing can alter this information. For example, stretching fish with different aspect ratios to the same square will change the fish's proportions; cropping and enlarging the heads of each fish to the same size will weaken the differences in the relative size of the heads; and performing texture normalization in the neighborhood where the fish blends with the background will cause the background to participate in local statistics.
[0004] Recognition using both overall and local images, image alignment, distance transformation, and local contrast normalization are all existing techniques. The remaining challenge is how to unify the orientation and scale of the fish body under a clear and repeatable preprocessing rule, while preserving the head-to-body ratio, body height distribution, and visible texture, and ensuring that the training and usage phases receive consistent classification inputs. Summary of the Invention
[0005] This invention proposes a fish species classification method and system based on conformal feature maps. The method establishes a unified coordinate system and scale based on information about the fish's body outline, snout tip, and caudal peduncle center. Under this coordinate system, four types of images are generated: complete fish body, outline distance, local texture, and head neighborhood. These images are then combined into a classification input using a fixed layout.
[0006] The method includes the following steps:
[0007] 1) Collect fish images, manually label the outline, snout tip and caudal peduncle center of a single fish, generate fish body mask, and provide fish species category labels for training images;
[0008] 2) Based on the direction and distance from the snout to the center of the caudal peduncle, the image and mask are aligned in a horizontal and vertical proportion to maintain shape. A complete fish body image, contour distance map, local texture map, and head neighborhood map are generated at a uniform scale and stitched together in a fixed layout to form a four-grid shape-preserving feature map. The contour distance mapping and the head window both adopt a fixed proportion relative to the distance from the snout to the center of the caudal peduncle, and the texture statistics only use the effective pixels within the mask.
[0009] 3) Train a YOLO26 classification model using the aforementioned graph and category labels, set the optimizer, learning rate, batch size and stopping conditions, preserve the complete graph layout, and select model parameters based on the performance on the validation set;
[0010] 4) Generate a map using the same manual contour and key point annotation and the processing rules of step 2) for the image to be identified, input it into the trained model for inference, and output the fish species classification result.
[0011] Preferably, alignment employs translation, rotation, and proportional scaling, with vertical reflection applied when necessary based on the manually confirmed fish back direction. The complete fish body image retains its original color and relative proportions; the contour distance map uses a fixed distance mapping scale proportional to the uniform body length; the local texture map calculates local statistics within the effective pixels of the fish body; the head neighborhood map uses the same relative body length window for each sample, without rescaling according to the actual head size of each fish.
[0012] The system includes an image and annotation acquisition module, a map generation module, a model training module, a model storage module, and a classification module. The model storage module stores both model parameters and map generation parameters, and the classification module uses the corresponding parameters to process the images to be classified, avoiding discrepancies between input rules during the training and inference phases.
[0013] The technical advantages of this invention are as follows: First, using the same scaling ratio in both the horizontal and vertical directions ensures that the length ratio within the fish's plane does not change even when the canvas is filled. Second, the mapping scale of the contour distance map is consistent across samples, avoiding the need to normalize the body height of each fish separately and eliminate differences. Third, mask-constrained texture statistics reduce interference caused by background participation in normalization. Fourth, a fixed-ratio head window preserves the size relationship between the head and body length when displaying local details. Fifth, a fixed layout and consistent training and inference processing provide the classification model with meaningfully stable input. These advantages do not guarantee classification accuracy under arbitrary shooting conditions. Attached Figure Description
[0014] Figure 1 This is a schematic diagram of the training and classification process of this invention.
[0015] Figure 2 This is a schematic diagram illustrating the conformal alignment and four-region map structure of the present invention.
[0016] Figure 3 This is a schematic diagram of the module relationships in the fish species classification system of the present invention. Detailed Implementation
[0017] The following describes an feasible method with reference to the accompanying drawings. The listed pixel dimensions and training parameters are used to illustrate the implementation process. The preprocessing parameters should be used in conjunction with the selected model after training is completed. This embodiment uses images of silver carp and bighead carp as classification objects.
[0018] In this embodiment, the fish body outline, snout tip, and caudal peduncle center position are obtained through manual annotation during both the training and usage phases. Fish species category labels are provided separately for training images; for images to be identified, only the outline and key locations are required, and the actual fish species is not required in advance.
[0019] Step 1) Image collection and manual annotation
[0020] Collect color images showing complete or nearly complete fish bodies, prioritizing close-up side views. Images facing directly at the camera, with key parts obscured, severely curved, blurry, or severely overexposed to the point where outlines and key locations cannot be determined, are manually rejected or temporarily omitted from this morphological classification method. This screening does not utilize actual fish species labels to select image processing parameters.
[0021] Using an image annotation tool, draw a closed polygon for the target fish and label it "fish". Mark the point "snout" at the snout tip and the point "tail_base" at the center of the caudal peduncle. The snout tip is the visible position at the front of the fish's head along the longitudinal direction; the center of the caudal peduncle is the center position where the caudal fin connects to the fish body, excluding the tip of the caudal fin. Use a consistent annotation size for all images, and annotate the fish body polygon along the visible target boundary, without artificially adding occluded parts of the fish body.
[0022] This embodiment uniformly adopts a complete fish body outline including visible fins: the reliably identifiable outer edges of the trunk, dorsal fin, pectoral fin, pelvic fin, anal fin, and caudal fin are all included in the same target mask; when the fin overlaps with the trunk, only the outer boundary of the target is taken, and the invisible internal boundary is not drawn. When transparent or blurred edges cannot be reliably located, the target is occluded, the caudal fin is missing, or the target is truncated by the image boundary, the sample will not be included in the complete outline classification process of this embodiment, and will not be completed with an imagined outline. The snout is taken as the foremost point of the mouth along the longitudinal direction in the near-side view, and the center of the caudal peduncle is taken as the middle position where the base of the caudal fin connects to the trunk; neither of them is replaced by the tip of the fin.
[0023] The annotation file saves the original image dimensions, polygon vertex coordinates, and coordinates of two key points; point coordinates can be floating-point numbers. Other annotations, such as those for eyes, can be retained for manual verification, but this embodiment does not rely on eye annotations for generating the four-region atlas. For an original image containing multiple fish, the target fish and its corresponding annotation are first determined separately; each training sample corresponds to only one fish.
[0024] Check that the image and labeled dimensions correspond, that the polygon has at least three distinct finite coordinate vertices, a non-zero area, and no non-adjacent edges intersecting or overlapping, and that all coordinates are within the original image's range. The snout tip and tail stalk center must each have a valid coordinate. Set the shortest distance from a point to the closed polygon region to zero (if the point is inside or on the boundary); otherwise, use the shortest distance from the point to the boundary. This distance between two points must not exceed a tolerance δ. An example uses the coordinates from the original image. Pixels. This tolerance is allowed near the boundary; points clearly outside the target should be corrected and re-examined, not just recorded as a warning before continuing generation. Based on the original input, the distance from the snout to the center of the tail stalk must be at least 10 pixels, and the mask foreground area at least 50 pixels; these values only represent the minimum computational threshold and do not indicate sufficient recognition detail.
[0025] The category labels of the training samples are stored independently; for example, bighead carp corresponds to category 0, and silver carp corresponds to category 1. These category numbers are only labels for the classification model in this embodiment and do not represent fish species numbers in other devices or projects. The atlas generation program only reads the image, geometric annotations, and manually corrected markings related to the fish's dorsal direction; it does not read the fish species category to determine the transformation method.
[0026] Geometric validity and image quality are assessed separately. Even if the above geometric checks are passed, it is still necessary to confirm that the outline, snout, and tail stalk are identifiable in the original image, and that the head and body surface have observable details; samples with obviously low resolution, blurriness, or strong reflectivity are not included in this embodiment. The usability of the original image texture should not be judged solely based on the clarity of the magnified image. The actual screening rules for tolerance, resolution, and sharpness should be determined and fixed during the training and validation phases, and should be consistently applied to training, validation, testing, and samples to be classified, without using test labels to adjust the rules.
[0027] II. Unified Coordinates and Conformal Alignment in Step 2)
[0028] like Figure 2 As shown, let the snout tip be S, the caudal peduncle center be P, and define the longitudinal unit vector e and its perpendicular unit vector n of the fish body:
[0029] (1)
[0030] L represents the straight-line distance from the snout tip to the center of the caudal peduncle, not the total length of the fish including the caudal fin. A uniform canvas of 256×256 pixels is used, with a preset snout tip position. The distance from the tip of the snout to the center of the tail peduncle after standardization Pixel. For pixel position p in the original image, its canvas position q is:
[0031] (2)
[0032] The square brackets in equation (2) indicate that... and This is a matrix consisting of two rows. The transformation places the fish head on the left and the caudal peduncle on the right; the horizontal and vertical proportions are both equal. Therefore, fish with different aspect ratios will not be stretched into the same shape. The image coordinates adopt the convention of horizontal to the right and vertical to the bottom.
[0033] These two key points can only determine the head and tail direction, not the fish's back and belly direction alone. If manual inspection reveals inconsistencies in the fish's back orientation, then vertical reflective surfaces should be added to the corresponding samples. , Where b is 1 to indicate no reflection and -1 to indicate reflection. This selection is used synchronously for the image, mask, and head window; the images to be classified are also manually confirmed based on the direction of the visible fish backs, and are not automatically flipped according to the fish species.
[0034] First, set the pixels outside the fish mask to a neutral background with all RGB channels set to 127. Then, perform a linear interpolation transformation on the color image and a nearest-neighbor interpolation transformation on the mask. After the transformation, the pixels outside the mask are still set to 127. Check the transformed contour vertices. If any of their coordinates exceed the effective area of 1 to 254 pixels in the canvas of this embodiment, the sample is rejected and not forcibly accommodated by scaling at different ratios in the horizontal and vertical directions.
[0035] The transformation preserves the relative shape within the two-dimensional image and does not perform three-dimensional pose or perspective correction. When the fish body is severely bent or not viewed from the side, the image projection of the head-to-body ratio may no longer be suitable as a basis for comparison. Therefore, this embodiment limits the usage conditions through the aforementioned manual screening.
[0036] III. Feature Extraction and Four-Grid Map Generation in Step 2)
[0037] (a) Complete fish image. The shape-preserving aligned colored fish body and the uniform neutral background are combined to form a 256×256 pixel three-channel image, preserving the fish body color, overall outline and relative head and body size, and no longer scaling non-proportionally according to the target bounding box.
[0038] (II) Contour Distance Map. Let the aligned binary fish mask be M, with the foreground set to 1 and the background set to 0. Calculate the Euclidean distance from the foreground pixel to the background and from the background pixel to the foreground, denoted as... and Outside the corresponding region, this distance is set to zero, resulting in a signed distance d where the interior is positive and the exterior is negative.
[0039] (3)
[0040] This means that x is restricted to the range of 0 to 1. (This is from an example.) The pixel D is rounded down to 8-bit grayscale and copied to all three channels. Different samples share a and r values, and are not re-normalized based on the maximum body width or maximum internal distance of a single fish. This ensures that the same inner and outer distances of the same contour have the same grayscale meaning.
[0041] Distance representation with truncation and quantization: This embodiment hour , hour A consistent linear distance mapping across samples is used only within the truncation range, and quantization still exists after saving as 8-bit grayscale. This representation is used to preserve common scale distance information within a certain range near the boundary, and does not mean that all internal or external distance differences are fully preserved, nor does it mean that 21 pixels is the optimal truncation value.
[0042] (III) Local Texture Map. Calculate the 8-bit brightness Y from the aligned fish body image, and take the area within the fish body mask... The effective region V is defined by the pixels within V; values within V are set to 1, and all others to 0. A normalized Gaussian kernel G with a 15×15 pixel size and a standard deviation of 3 pixels is used for calculation.
[0043] (4)
[0044] (5)
[0045] In equations (4) and (5), * denotes convolution. μ and σ represent the mean and standard deviation of local brightness under mask constraints, respectively. Using brightness range to exclude obvious dark and bright areas is a screening method for usable textures in this embodiment, and is not used to recover invisible real textures. Then, the following calculations are performed:
[0046] (6)
[0047] Round T to the nearest integer, save it as an 8-bit grayscale value, and copy it to all three channels. For V = 0 or... The pixels, making This process uses effective weight normalization to exclude the background from the calculation of mean and variance, and uses the lower limit of standard deviation to limit the amplification of small noises in flat regions.
[0048] (iv) Head Neighborhood Graph. Define normalized coordinates. , When vertical reflections exist, replace v with bv. , A square window is mapped proportionally to a 256×256 pixel image, with 127 padding outside the mask. The window has a width and height of 0.5L, and uses the same relative range and output size for different samples.
[0049] The head neighborhood map can be directly generated from the original color image and the original mask through corresponding affine relationships, avoiding repeated scaling. The window size does not change based on the bounding box of each fish head; therefore, samples with heads that are relatively larger than the body still occupy a larger relative area in the head neighborhood map. The local magnification here only changes the observation scale and does not force the heads of different fish to be the same size.
[0050] IV. Model Input and Training in Step 3)
[0051] like Figure 2 As shown, the complete fish image is placed in the upper left region, the contour distance image in the upper right region, the local texture image in the lower left region, and the head neighborhood image in the lower right region, forming a 512×512 pixel three-channel map. All four regions retain complete content, without simulating the classification input of ordinary natural images through random cropping.
[0052] Before generating the atlas, training, validation, and independent test sets are determined based on the original images. The same original image and its transformed versions must not be distributed across different sets. If the captured individual or sequence can be identified, the same individual or the same consecutive capture sequence is grouped into the same set to reduce evaluation bias caused by nearly identical images. The same set of alignment and atlas parameters is used for training, validation, testing, and actual classification.
[0053] In this embodiment, the pre-training parameters of the YOLO26 classification model yolo26n-cls are used as initialization, and the number of classification output nodes is set to 2. The model is an image classification model, and its output is the category score of the fish species to which the image belongs.
[0054] The model input uses a complete 512×512 image, converting pixel values to floating-point numbers between 0 and 1, and arranging channels according to the requirements of the classification network. During training transformation, no random cropping, rotation, flipping, or color perturbation is performed on the completed image to avoid region misalignment and changes in the meaning of distance and texture values; the same input transformation is used for validation and inference.
[0055] This embodiment uses a complete 512×512 pixel three-channel image as the model input, keeping the position, size, and all content of the four regions unchanged. Pixel values are proportionally converted to floating-point numbers from 0 to 1, and the channels are arranged according to the network input requirements to form an input tensor. The same conversion rules are used for training, validation, and inference. The generated image is not cropped, randomly erased, rotated, flipped, or subjected to color perturbations that change the meaning of distance and texture map values, nor is image preprocessing repeated. The fixed size refers to the square image that has already been conformally aligned and stitched, and is not used to directly stretch the original fish image to a square.
[0056] The AdamW optimizer was used, with an initial learning rate of 0.001, a batch size of 4, a maximum number of training epochs of 30, an early stopping patience value of 10 epochs, and a fixed random seed of 42. Class labels were used as the supervision target, and cross-entropy loss was employed to update network parameters. The model was saved based on the classification performance on the validation set; the independent test set was not involved in parameter updates or model selection. The above settings provide the training conditions for this embodiment and should not be construed as superior to other parameter settings.
[0057] The model file includes a table mapping category numbers to fish species names, canvas size, preset snout position, uniform distance 'a', distance mapping ratio 'κ', texture calculation parameters, head window range, background values, and four-region layout. If the atlas generation rules are modified, the corresponding model should be re-evaluated; the atlas generated by the new rules should not be directly input into the old model and considered equivalent.
[0058] V. Image recognition in step 4)
[0059] For newly acquired fish images, the fish body outline, snout tip, and caudal peduncle center are manually annotated, filtered according to the same conditions as during training, and atlases are generated using equations (1) to (6) and a fixed head window. This process does not require the annotator to provide the actual fish species category in advance.
[0060] Load the classification model parameters saved during the training phase, perform forward inference on the graph, obtain the output scores of the two categories, select the category with the higher score as the classification result in this embodiment, and simultaneously output the corresponding score for manual verification. The model weights are not updated during the inference process; if subsequent expansion of training data is required, it should be treated as a separate retraining process.
[0061] When a valid outline or key point is missing, or when the image fails the aforementioned geometric check, a prompt will be given to supplement the annotation or replace the image, and no classification result will be given for the unqualified atlas.
[0062] VI. System Implementation
[0063] like Figure 3 As shown, the image and annotation acquisition module receives the color image and manual annotation required in step 1); the atlas generation module performs shape-preserving alignment, feature image generation and four-grid stitching in step 2); the model training module performs step 3); the model storage module saves the model, category correspondence table and atlas parameters; the classification module performs step 4), performs forward inference on the atlas to be identified generated according to the same rules, without updating the model weights.
[0064] The above modules can be implemented by programs on the same computing device, or they can run separately on data annotation and model training devices. Manual annotation is an operation explicitly reserved in this embodiment; the system does not require segmentation masks or keypoint prediction models to be pre-existing components.
[0065] To check the processing rules, the same image and annotations can be synchronously translated, rotated, and scaled proportionally, and then the position and proportion of fish in the generated atlas can be compared. The consistency of pixel size, background value outside the mask, and training inference parameters across atlas regions can also be checked. To compare classification performance, controls should be set up under the same data partitioning, including original fish classification, fish-only alignment classification, and four-region atlas classification, and the performance of each category should be reported. The evaluation method is given here; accuracy improvement should not be inferred from control experiments that have not been conducted.
[0066] The specific parameters in the embodiments of this invention can be adjusted while maintaining the same coordinate definition, scale constraints, and consistency between training and inference. For different fish species or shooting conditions, qualified samples should be reselected and the corresponding classification model should be trained. It cannot be assumed that the model can recognize untrained categories simply because the input is a fish image.
[0067] The specific embodiments of the present invention have been described above with reference to the accompanying drawings, which are used to explain the technical solutions and are not an exhaustive list of all embodiments. Those skilled in the art can make corresponding adjustments to the specific embodiments based on this specification. The scope of protection of the present invention is determined by the content of the claims, and the specification and drawings can be used to interpret the content of the claims.
Claims
1. A fish species classification method based on conformal feature maps, characterized in that, Includes the following steps: 1) Collect fish images, manually label the outline, snout tip and caudal peduncle center of a single fish, generate fish body masks, and provide fish species category labels for training images; 2) Based on the direction and distance from the snout to the center of the caudal peduncle, the image and mask are aligned in a horizontal and vertical proportion to maintain shape. A complete fish body image, contour distance map, local texture map, and head neighborhood map are generated at a uniform scale and stitched together in a fixed layout to form a four-grid shape-preserving feature map. The contour distance mapping and the head window both adopt a fixed proportion relative to the distance from the snout to the center of the caudal peduncle, and the texture statistics only use the effective pixels within the mask. 3) Train a YOLO26 classification model using the aforementioned graph and category labels, set the optimizer, learning rate, batch size and stopping conditions, preserve the complete graph layout, and select model parameters based on the performance on the validation set; 4) Generate a map using the same manual contour and key point annotation and the processing rules of step 2) for the image to be identified, input it into the trained model for inference, and output the fish species classification result.
2. The fish species classification method based on conformal feature maps according to claim 1, characterized in that, Step 2) includes the following steps: Using the snout tip as a reference and the line connecting the snout tip to the center of the caudal peduncle as the longitudinal axis, the length of the line is uniformly set to a preset distance. The color image and the fish body mask are translated, rotated, and scaled proportionally in the same way, so that the snout tip and the center of the caudal peduncle are located at preset positions on a unified canvas. The pixels outside the mask are set to a uniform background value to obtain a complete fish body image. The Euclidean distances from the inside of the mask to the background and from the outside of the mask to the foreground are calculated separately to form a signed distance where the inside is positive and the outside is negative. The mapping range is determined by a fixed ratio of the distance from the snout to the center of the caudal peduncle. The signed distances are linearly mapped to grayscale and the values that exceed the range are limited to generate a contour distance map. The map is not renormalized according to the maximum body width or maximum internal distance of a single fish. Local brightness normalization is performed within the fish mask to generate a local texture map. The local brightness normalization includes: selecting pixels within the mask whose brightness is between preset upper and lower limits as the effective region; using a Gaussian kernel to weight the effective region and its brightness statistics; and calculating the local brightness mean and standard deviation using the effective weights and normalization; dividing the difference between the pixel brightness and the local mean by the standard deviation which is not less than the preset lower limit; mapping the pixel brightness to grayscale after limiting; and setting pixels outside the effective region or with insufficient effective weights to neutral grayscale. Using the snout tip as a reference, the head window is determined according to a fixed ratio of the distance from the snout tip to the center of the caudal peduncle. The window content is mapped proportionally to a fixed output size to obtain a head neighborhood map. The window is not redefined according to the head bounding box of a single fish. The complete fish body image, contour distance image, local texture image, and head neighborhood image are processed into three-channel images of 256×256 pixels, and placed in the upper left, upper right, lower left, and lower right regions respectively. They are then stitched together to form a four-grid image of 512×512 pixels. Both grayscale images are copied to the three channels. Fish species category labels are not used in the image generation process.
3. The fish species classification method based on conformal feature maps according to claim 1, characterized in that, Step 3) includes the following steps: The original images are divided into non-overlapping training and validation sets, and atlases are generated according to the same rules in step 2). The atlases are used as model inputs and fish species category labels are used as supervision targets. The network was initialized using the pre-trained parameters of the YOLO26 classification model, and the number of classification output nodes was set to the number of training fish species. The AdamW optimizer was used with an initial learning rate of 0.001, a batch size of 4, a maximum number of training epochs of 30, and an early stopping patience value of 10 epochs. The model parameters were updated with cross-entropy loss, and the model was selected and saved based on the classification performance on the validation set. Training, validation, and inference all employ input transformation that preserves the complete graph, without performing cropping, rotation, flipping, or color perturbation that alters the meaning of distance and texture map values on the stitched graph; Save the selected model parameters along with the graph generation parameters and category correspondence table for use in step 4). Do not update the model weights during inference.
