Cultural relic color extraction method based on machine learning

Through the random forest model and color histogram technology, the accuracy of color area prediction in cultural relics images is solved, the prediction accuracy and generalization ability of the model are improved, the risk of overfitting is reduced, and better color extraction of cultural relics is achieved Effect.

CN119006852APending Publication Date: 2024-11-22XIAN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411062022.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Existing single machine learning models are prone to overfitting or ignoring key features in color area predictions in artifact images, reducing the accuracy of predictions.

Method used

Using a random forest-based machine learning model, through feature extraction, model training and optimization algorithms, combining color histograms and grayscale conversion, the prediction accuracy and generalization capabilities of the model are improved, and the over-consideration is reduced by visualizing the presentation and adjustment of model parameters. Combined risk.

Benefits of technology

The prediction accuracy and generalization ability of the cultural relics color extraction model are improved, the risk of overfitting is reduced, and the adaptability and visual analysis ability of the model are enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119006852A_ABST
    Figure CN119006852A_ABST
Patent Text Reader

Abstract

The invention discloses a cultural relic color extraction method based on machine learning. By integrating the results of a plurality of decision trees, the prediction accuracy is remarkably improved, especially when data containing more noise and interference is processed. Different features and feature subsets are considered in the training process of the random forest model, so that the model can better adapt to unknown data, and the generalization ability of the model is enhanced. The random forest model is composed of a plurality of decision trees, and each decision tree is constructed based on different data sets and feature subsets, so that the over-fitting risk is effectively reduced by the mechanism. Therefore, according to the method, the prediction accuracy can be improved, the generalization ability can be enhanced, the overfitting risk can be reduced, adjustment, optimization and iteration of the model are facilitated, and a powerful basis is provided for formulating a scientific culture restoration and cultural relic repair scheme. The method has important methodological support and practice-oriented value for realizing effective protection, knowledge propagation and sustainable development of cultural heritage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of cultural relic color extraction, and specifically is a cultural relic color extraction method based on machine learning. Background Art

[0002] Cultural relic color extraction is a technology that uses modern scientific and technological means to perform non-destructive analysis of cultural relics. By accurately measuring and extracting the color of the surface of cultural relics, the age, production process, material source and other information of the cultural relics can be revealed, providing an important basis for cultural relic protection and cultural research. The principle of cultural relic color extraction is to use spectral analysis technology to measure the reflected light on the surface of the cultural relic to obtain its spectral information. Then, by comparing the spectral database, the type and content of pigments used in the cultural relic can be determined. This method can not only obtain cultural relic color information non-destructively, but also be accurate to micron-level details, which makes it possible to study the microstructure and production process of cultural relics. Cultural relic color extraction technology is of great significance in cultural relic protection.

[0003] By analyzing the composition and content of the colors of cultural relics, we can understand the preservation status and causes of damage to cultural relics, and provide a basis for formulating scientific protection plans. At the same time, by comparing and analyzing the colors of cultural relics from different eras and regions, we can reveal the exchange and integration of ancient cultures and provide a new perspective for historical research.

[0004] However, in the existing technology, a single machine learning model may not be able to accurately predict the color area in the cultural relic image, because the decision tree is prone to overfitting or ignoring certain key features, thereby reducing the accuracy of the prediction. Summary of the invention

[0005] In view of this, the main purpose of the present invention is to provide a cultural relic color extraction method based on machine learning that can improve the prediction accuracy and generalization ability of the model, reduce the risk of overfitting, facilitate model adjustment and optimization, and provide support for subsequent visualization and analysis.

[0006] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0007] A method for extracting color from cultural relics based on machine learning, comprising the following steps:

[0008] S1: Collect cultural relic image dataset;

[0009] S2: preprocessing the images collected in step S1, including scaling, cropping, and grayscale conversion, and then annotating the data set to match the color areas in the cultural relic images with the corresponding color labels;

[0010] S3: Perform feature extraction, use the color histogram method to extract color features from the preprocessed image, and then normalize the extracted features;

[0011] S4: Select a random forest machine learning model, train the random forest machine learning model using the training data set, adjust model parameters and optimize the algorithm;

[0012] S5: Use the test data set to evaluate the trained model, calculate the model's accuracy, recall, and F1 value indicators, and optimize and adjust the model based on the evaluation results;

[0013] S6: Use the optimized model to extract color from the new cultural relic image, input the extracted color features into the model, and obtain the predicted color label;

[0014] S7: According to the prediction results, the color areas in the cultural relic image are classified and labeled, and the corresponding colors are extracted;

[0015] S8: Visualize the extracted cultural relic colors and generate a color distribution map and a color histogram;

[0016] S9: By comparing with the actual cultural relic image, verify whether the extracted color is consistent with the actual situation, and evaluate and improve the results.

[0017] In a preferred embodiment, in step S1, a bicubic interpolation method is used to perform image scaling, where the bicubic interpolation method finds the 16 nearest pixel points in the original image and uses a homogeneous polynomial interpolation function to calculate the pixel values ​​in the new image;

[0018] For each pixel in the scaled image, find the nearest 4x4 pixel block in the original image; use the Bicubic interpolation function to calculate the contribution of these pixels to the new pixel value; and weighted sum these contributions to obtain the new pixel value in the scaled image.

[0019] In a preferred embodiment, in step S2, image cropping helps remove the background or other non-critical areas of the image by manually selecting the region of interest, so that the model focuses on the color characteristics of the cultural relics;

[0020] Grayscale conversion: The process of converting a color image into a grayscale image. This is achieved by combining the red, green, and blue channels with different weights. The grayscale conversion formula used is:

[0021] Gray value = 0.299*R+0.587*G+0.114*B;

[0022] R, G, and B represent the pixel values ​​of the red, green, and blue channels, respectively.

[0023] In a preferred embodiment, in step S3, a color histogram method is used to extract color features from the preprocessed image, and the specific steps are as follows:

[0024] S31: Select color space: determine which color space is used to represent the color in the image. The color space includes RGB, HSV, and Lab.

[0025] S32: Dividing the color interval: dividing the color interval into a plurality of sub-intervals according to the characteristics of the color space;

[0026] S33: Calculate the color histogram: for each pixel in the image, calculate which color interval it belongs to based on its color value; for each color interval, count the number of pixels belonging to the interval to obtain the frequency of the interval; combine the frequencies of all color intervals to obtain the color histogram of the image.

[0027] In a preferred embodiment, in step S3, the formula for calculating the color histogram is:

[0028] f(k)=f(k)+1;

[0029] Let I represent the image, H represent the color histogram, N represent the total number of pixels in the image, n represent the number of color intervals, k represent the kth color interval, and f(k) represent the frequency of the kth color interval;

[0030] For each pixel I(x,y) in the image, calculate its color value C, then calculate which color interval k it belongs to based on C, and add 1 to f(k);

[0031] Finally, the frequencies of all color intervals are combined to obtain the color histogram H of the image;

[0032] H=(f(1),f(2),...,f(n)).

[0033] In a preferred embodiment, in step S3, the extracted features are normalized using minimum-maximum standardization, and the specific steps are as follows:

[0034] S311: Calculate the maximum and minimum values: For each feature, find the maximum value (Max) and the minimum value (Min) in the data set;

[0035] S312: Apply transformation formula: For each feature value x in the data set, use the following formula for transformation:

[0036]

[0037] Among them, x normis the transformed value;

[0038] S313: Transform the dataset: Apply the above transformation to each feature of the entire dataset; after min-max normalization, all features will be scaled to the range of 0 to 1;

[0039] After min-max normalization, all features are scaled to the range of 0 to 1.

[0040] In a preferred embodiment, in step S4, a random forest model is used for training, and the specific steps are:

[0041] S41: Divide the data set into a feature matrix X and a label vector y, where X contains the color features of 1000 samples and y contains the corresponding color labels;

[0042] S42: Initialize the random forest model, set parameters nestimators = 100, max_depth = 100, max_features = 'sqrt';

[0043] S43: Constructing a random forest model: For i=1 to 100: sampling with replacement from the data set to obtain a new training subset; using this subset to train a decision tree model; adding this decision tree model to the random forest model;

[0044] S44: Training decision trees: For each decision tree, randomly select a subset from all features as candidate features; select the best features and split points based on the candidate features and Gini impurity; split the node, and repeat the above process until the stopping condition is met;

[0045] S45: Perform random forest prediction: For a new artifact image, each decision tree independently makes a color prediction; the final prediction result of the random forest is the majority vote of the prediction results of all decision trees.

[0046] In a preferred embodiment, the step S5 specifically includes the following steps:

[0047] S51: preprocess the test data set, extract and normalize the same features as the training data set;

[0048] S52: Use the trained random forest model to predict the test data set and obtain the prediction results;

[0049] S53: Calculate the accuracy, recall and F1 value based on the prediction results and actual labels;

[0050] S54: Analyzing the performance indicators, we found that the recall rate was low, indicating that the model did not predict certain colors well enough;

[0051] S55: Adjust the parameters of the random forest, such as increasing the number of decision trees or reducing the maximum depth;

[0052] S56: Retrain the random forest model using the adjusted parameters;

[0053] S57: Evaluate the retrained model using the test dataset and calculate new performance metrics;

[0054] S58: If the performance has improved, continue to use the model; otherwise, continue to adjust the parameters and repeat the evaluation process until satisfactory performance is achieved.

[0055] In a preferred embodiment, the step S7 specifically includes:

[0056] S71: for each pixel in the image, classify it into red, blue, and green color categories according to the prediction result of the model;

[0057] S72: using different colors to mark the classification results, marking pixels predicted to be red as red, blue as blue, and green as green;

[0058] S73: For each color category, extract the average RGB value of the color as the representative color of the category.

[0059] In a preferred embodiment, the step S8 specifically includes the following steps:

[0060] S81: Visual display of color areas: Display the classified and labeled cultural relics images to visually observe the distribution and area of ​​colors;

[0061] S82: Generate a color distribution map: according to the color classification result, count the number of occurrences or frequencies of each color category in the image; draw a color distribution map in a two-dimensional plane or a three-dimensional space, and use the frequency of the color category as the size or height of the point in the map;

[0062] S83: Generate a color histogram: Generate a color histogram according to the statistically obtained color frequencies; the horizontal axis of the histogram represents different color categories, and the vertical axis represents the frequency or percentage of the color category.

[0063] The cultural relic color extraction method based on machine learning of the present invention has the following beneficial effects:

[0064] This machine learning-based cultural relic color extraction method can improve the accuracy of prediction by integrating the results of multiple decision trees, especially when faced with data with more noise and interference.

[0065] The random forest model considers different features and feature subsets during the training process, which enables the model to better adapt to unknown data and thus improve generalization ability.

[0066] Since the random forest model contains multiple decision trees, each of which is built based on a different subset of the dataset and features, the risk of overfitting can be reduced.

[0067] The random forest model contains multiple decision trees, and the parameters of each decision tree, such as the maximum depth and the maximum number of features, can be adjusted as needed to improve the performance of the model.

[0068] The results of random forest prediction can be used to generate color distribution maps and color histograms, which help to intuitively display and analyze the color distribution and areas in cultural relic images, providing support for subsequent analysis and research.

[0069] In summary, the random forest prediction method plays an important role in the entire cultural relic color extraction method based on machine learning. It can improve the prediction accuracy and generalization ability of the model, reduce the risk of overfitting, facilitate model adjustment and optimization, and provide support for subsequent visualization and analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0071] Figure 1 It is a cultural relic color extraction process based on machine learning;

[0072] Figure 2 is the random forest decision model step. DETAILED DESCRIPTION

[0073] The cultural relics color extraction method based on machine learning of the present invention is further described in detail below in conjunction with the embodiments of the present invention.

[0074] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0075] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0076] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0077] like Figure 1 and Figure 2 As shown, the cultural relic color extraction method based on machine learning includes the following steps:

[0078] S1: Collect cultural relic image datasets, including pictures of cultural relics of various types and ages;

[0079] S2: Preprocessing the images collected in step S1, including scaling, cropping, grayscale conversion, etc., to eliminate noise and interference, and then annotating the data set to match the color areas in the cultural relic images with the corresponding color labels;

[0080] Corresponding color labels: In the preprocessing step, each color region in the artifact image is assigned a specific color name or code for use in subsequent machine learning model training and testing.

[0081] S3: Perform feature extraction, use the color histogram method to extract color features from the preprocessed image, and then normalize the extracted features to eliminate the dimensional influence between different features;

[0082] The color histogram is a statistical feature that represents the color distribution in an image in a numerical way and constructs a histogram by counting the number of pixels in each color interval.

[0083] S4: Select a random forest machine learning model based on the characteristics and requirements of the problem, and use the training data set to train the random forest machine learning model. By adjusting the model parameters and optimizing the algorithm, the accuracy and generalization ability of the model can be improved.

[0084] Improve the accuracy and generalization of the model by adjusting the parameters of the random forest model and the optimization algorithm. This may include adjusting the number of decision trees (nest imators), the maximum depth of the tree (max_depth), and the maximum number of features considered at each split (max_features). In addition, techniques such as cross-validation may be used to optimize the model.

[0085] Improve the accuracy and generalization ability of the model by adjusting the parameters of the random forest model and optimizing the algorithm. This step includes:

[0086] 1. Adjust the number of decision trees (n_es t imators)

[0087] The number of decision trees is one of the most important parameters of random forest. Adjusting its number can improve the performance of the model. The specific steps are as follows:

[0088] Initialize the model: Set a small initial value, such as 100 trees.

[0089] Gradually increase the number of trees, 10 or 20 trees at a time, and observe the performance changes of the model.

[0090] Performance evaluation: Use cross-validation to evaluate the accuracy of the model at each size and select the size with the best performance.

[0091] 2. Adjust the maximum depth of the tree (max_depth)

[0092] The maximum depth of the tree limits the maximum number of layers of each decision tree, thereby preventing overfitting. The specific steps are as follows:

[0093] Grid Search: Use the Grid Search method to define a set of depth values.

[0094] Cross-validation: Use cross-validation to evaluate the performance of the model at different depths and select the depth value with the best effect.

[0095] 3. Adjust the maximum number of features considered at each split (max_features)

[0096] This parameter controls the maximum number of features that can be selected at each split, balancing the diversity and accuracy of the model. The specific steps are as follows:

[0097] Different options: Set different max_features options, such as 'sqrt' (square root) and 'log2' (logarithm).

[0098] Performance evaluation: Use cross-validation to evaluate model performance under different options and select the best option.

[0099] 4. Optimization algorithms include:

[0100] Optimize other parameters to further improve model performance, including:

[0101] min_samples_split: Sets the minimum number of samples that each node needs to split.

[0102] min_samples_leaf: Sets the minimum number of samples for leaf nodes.

[0103] bootstrap: Whether to use bootstrap sampling each time the tree is built.

[0104] 5. Parameter optimization methods include:

[0105] Random search: Randomly select parameter combinations, suitable for large-scale parameter optimization.

[0106] Bayesian Optimization: Use Bayesian methods to find the optimal parameter combination in parameter space.

[0107] Additionally, techniques such as cross-validation may be used to optimize the model.

[0108] Using the K-fold cross-validation method, the data set is divided into K subsets, and K-1 subsets are used for training each time, and the remaining subset is used for validation. This process is repeated K times, and a different subset is used for validation each time. Finally, the average of the K validation results is taken as the evaluation standard of the model performance.

[0109] Optimization steps

[0110] Step 1: Divide the dataset

[0111] The dataset is divided into a training set and a test set. The training set is used for cross-validation and model training, and the test set is used for final model evaluation.

[0112] Step 2: Setting up the parameter grid

[0113] Defines a set of hyperparameter combinations that will be used for either grid search or random search.

[0114] Step 3: Perform K-fold cross validation

[0115] The performance of each parameter combination was evaluated using a cross-validation technique, and the best parameter combination was selected.

[0116] S5: Use the test data set to evaluate the trained model, calculate the model's accuracy, recall, and F1 value indicators, and optimize and adjust the model based on the evaluation results to improve the model's performance;

[0117] Adjust the parameters of the model, adjust the number of decision trees (n_est imators), adjust the maximum depth of the tree (max_depth), and adjust the maximum number of features considered at each split (max_features) to improve performance indicators. If the model performance does not meet expectations, the adjustment and evaluation process will be repeated until satisfactory performance is achieved.

[0118] For further optimization, Bayesian optimization algorithm was applied to improve the performance indicators.

[0119] S6: Use the optimized model to extract color from the new cultural relic image, input the extracted color features into the model, and obtain the predicted color label;

[0120] New artifact images refer to artifact images that have not been involved in model training before, while mobile phone artifact images may refer to artifact images used in the model training process. The purpose of new artifact images is to test the generalization ability of the model, while mobile phone artifact images are used to train and verify the performance of the model.

[0121] S7: According to the prediction results, the color areas in the cultural relic image are classified and labeled, and the corresponding colors are extracted;

[0122] According to the prediction results of the model, each pixel is classified into color categories such as red, blue, green, etc., and the classification results are labeled with different colors.

[0123] S8: Visualize the extracted cultural relic colors and generate a color distribution map and a color histogram;

[0124] S9: By comparing with the actual cultural relic image, verify whether the extracted color is consistent with the actual situation, evaluate and improve the results, and then end the entire cultural relic color extraction process based on machine learning.

[0125] Specifically, the evaluation and improvement process is as follows:

[0126] a. Calculate classification accuracy

[0127] Compare the predicted color labels with the actual color labels and calculate the classification accuracy of the model.

[0128] b. Confusion Matrix

[0129] Generate a confusion matrix to analyze the classification for each color category and identify common misclassifications.

[0130] c. Precision, recall and F1 score

[0131] The precision, recall, and F1 score are calculated for each color category to fully evaluate the model performance.

[0132] 2. Comparison with actual cultural relic images

[0133] a. Visual contrast

[0134] The predicted color labeling results are visually compared with the actual cultural relic images to evaluate whether the extracted color areas are consistent with the actual situation.

[0135] b. Quantitative comparison

[0136] Use a color distribution plot or color histogram to compare actual and predicted color distributions to quantitatively assess the accuracy of the model.

[0137] 3. Improve the model

[0138] a. Data Augmentation

[0139] Improve the generalization ability of the model by increasing the diversity of the training data set. You can use data augmentation techniques such as rotation, flipping, scaling, etc.

[0140] b. Adjust model parameters

[0141] Based on the evaluation results, the hyperparameters of the random forest model were readjusted to further optimize the model performance.

[0142] c. Use ensemble learning

[0143] Combine the prediction results of multiple models and use voting or averaging to improve the accuracy and robustness of the model.

[0144] Through the above steps, the model performance can be evaluated and improved to ensure that the extracted color features are more accurate and meet the needs of actual applications.

[0145] Evaluation and improvement of the results usually involves comparison with the actual artifact image to verify that the extracted colors are consistent with the actual situation. If the results are not accurate, the model parameters are adjusted or the algorithm is optimized, and then retested and evaluated.

[0146] The criteria for judging whether it meets the actual situation can be the following quantitative indicators:

[0147] Accuracy: The ratio of color regions correctly predicted by the model to all predicted regions.

[0148] Recall: The ratio of the color area correctly predicted by the model to the actual color area.

[0149] F1 Score: The harmonic mean of precision and recall, used to measure the accuracy of the model.

[0150] Intersection over Union (IoU): The ratio of the intersection and union of the predicted color area and the actual color area, which is used to evaluate the degree of fit between the predicted area and the actual area.

[0151] Mean Squared Error (MSE) or Structural Similarity Index (SSIM): used to compare the difference between the predicted color and the actual color.

[0152] These indicators can be calculated to obtain specific values, thereby objectively evaluating model performance instead of relying on human subjective judgment.

[0153] The specific methods for adjusting algorithms and parameters are as follows:

[0154] Adjust the number of decision trees (n_estimators):

[0155] If the model is overfitting, the number of decision trees can be reduced.

[0156] If the generalization ability of the model is insufficient, the number of decision trees can be increased.

[0157] The optimal number of trees is determined by cross-validation.

[0158] Adjust the maximum depth of the tree (max_depth):

[0159] If the model is overfitting, the maximum depth can be reduced.

[0160] If the model is underfitting, the maximum depth can be increased.

[0161] Use grid search and cross validation to find the optimal depth.

[0162] Adjust the maximum number of features considered at each split (max_features):

[0163] If the number of features is large, you can try reducing the value of max_features to increase the diversity of the model.

[0164] If the model performs poorly, you can increase the value of max_features to improve accuracy.

[0165] Adjust other parameters:

[0166] min_samples_split: If the model is overfitting, you can increase this value.

[0167] min_samples_leaf: If the model is overfitting, you can increase this value.

[0168] bootstrap: Usually set to True, but if the amount of data is large, you can try setting it to False.

[0169] Adjust the algorithm:

[0170] If the random forest model cannot meet the performance requirements, you can consider trying other machine learning algorithms, such as support vector machine (SVM), neural network, etc.

[0171] If the amount of data is very large, you can consider using deep learning algorithms such as convolutional neural networks (CNN).

[0172] If your model performs poorly on a particular type of color, consider using a feature extraction method or algorithm specific to that color.

[0173] When adjusting parameters or algorithms, each change and the corresponding results should be recorded to track which changes have a positive impact on model performance. In addition, the adjustment process should be iterative, that is, retesting and evaluation should be performed after each adjustment until satisfactory performance indicators are achieved.

[0174] Specific:

[0175] In step S1, the image is scaled using a bicubic interpolation method, which finds the 16 nearest pixels in the original image and uses a homogeneous polynomial interpolation function to calculate the pixel values ​​in the new image. For each pixel in the scaled image, the nearest 4x4 pixel block in the original image is found. The contribution of these pixels to the new pixel value is calculated using the Bicubic function bicubic interpolation function. These contributions are weighted and summed to obtain the new pixel value in the scaled image.

[0176] In step S1, image cropping helps remove the background or other non-critical areas of the image by manually selecting the region of interest, reducing noise and interference, so that the model pays more attention to the color characteristics of the cultural relics;

[0177] Grayscale conversion: The process of converting a color image into a grayscale image. This can be achieved by combining the red, green, and blue channels with different weights. The grayscale conversion formula used is:

[0178] Gray value = 0.299*R+0.587*G+0.114*B;

[0179] Here R, G, and B represent the pixel values ​​of the red, green, and blue channels respectively.

[0180] In step S3, a color histogram method is used to extract color features from the preprocessed image, and the specific steps are as follows:

[0181] S31: Select color space: determine which color space is used to represent the color in the image. The color space includes RGB, HSV, and Lab.

[0182] S32: Dividing the color interval: dividing the color interval into a plurality of sub-intervals according to the characteristics of the color space;

[0183] S33: Calculate color histogram: For each pixel in the image, calculate which color interval it belongs to based on its color value. For each color interval, count the number of pixels belonging to the interval to obtain the frequency of the interval. Combine the frequencies of all color intervals to obtain the color histogram of the image.

[0184] In step S3, the formula for calculating the color histogram is:

[0185] f(k)=f(k)+1;

[0186] Let I represent the image, HH represent the color histogram, N represent the total number of pixels in the image, n represent the number of color intervals, k represent the kth color interval, and f(k) represent the frequency of the kth color interval;

[0187] For each pixel I(x,y) in the image, calculate its color value C, then calculate which color interval k it belongs to based on C, and add 1 to f(k);

[0188] Finally, the frequencies of all color intervals are combined to obtain the color histogram H of the image;

[0189] H=(f(1),f(2),...,f(n)).

[0190] In step S3, the extracted features are normalized using minimum-maximum standardization, and the specific steps are as follows:

[0191] S311: Calculate the maximum and minimum values: For each feature, find the maximum value (Max) and the minimum value (Min) in the data set;

[0192] S312: Apply transformation formula: For each feature value x in the data set, use the following formula for transformation:

[0193]

[0194] Among them, x norm is the transformed value;

[0195] S313: Transform the dataset: Apply the above transformation to each feature of the entire dataset; after min-max normalization, all features will be scaled to the range of 0 to 1;

[0196] Transform the dataset: Apply the above transformation to each feature of the entire dataset;

[0197] After min-max normalization, all features are scaled to the range of 0 to 1.

[0198] In step S4, a random forest model is used for training, and the specific steps are as follows:

[0199] Divide the data set into a feature matrix X and a label vector y, where X contains the color features of 1000 samples and y contains the corresponding color labels;

[0200] Initialize the random forest model, set parameters nestimators = 100, max_depth = 100, max_features = 'sqrt';

[0201] Build a random forest model: For i = 1 to 100: Perform a sample with replacement from the dataset to get a new training subset. Use this subset to train a decision tree model. Add this decision tree model to the random forest;

[0202] Training decision trees: For each decision tree: Randomly select a subset of all features as candidate features. Select the best features and split points based on the candidate features and Gini impurity. Split the node and repeat the above process until the stopping condition is met;

[0203] The stopping condition is either the maximum depth of the tree or the minimum number of samples, ensuring that the tree does not overfit the data.

[0204] Perform random forest predictions: For a new artifact image, each decision tree independently makes a color prediction. The final prediction of the random forest is the majority vote of all decision tree predictions;

[0205] The step S5 specifically includes the following steps:

[0206] S51: Preprocess the test dataset, extracting and normalizing the same features as the training dataset.

[0207] S52: Use the trained random forest model to predict the test data set and obtain the prediction results.

[0208] S53: Calculate the accuracy, recall and F1 value based on the prediction results and actual labels.

[0209] The specific method for calculating precision, recall and F1 value is as follows:

[0210] Precision = True Positives / (True Positives + False Positives)

[0211] Recall = True positive examples / (True positive examples + False negative examples)

[0212] F1 value = 2*(precision*recall) / (precision+recall).

[0213] When calculating the performance indicators of machine learning models, four values ​​in the confusion matrix are usually used: true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). These values ​​can be obtained from the confusion matrix. The specific explanation is as follows:

[0214] True Positives (TP): The number of positive examples correctly predicted by the model.

[0215] False Positives (FP): The number of samples that the model incorrectly predicts as positive.

[0216] True Negatives (TN): The number of examples correctly predicted by the model as negative.

[0217] False Negatives (FN): The number of examples that the model incorrectly predicts as negative.

[0218] S54: Analyzing the performance indicators, we found that the recall rate was low, indicating that the model did not predict certain colors well.

[0219] The standard for low recall rate generally refers to the fact that the model fails to correctly predict a high proportion of positive examples among all samples that are actually positive examples, which means that the model is not able to identify certain categories well enough. Common low recall rate standards may be less than 50%, but the specific standard can be determined based on specific applications and business needs.

[0220] S55: Adjust the parameters of the random forest, such as increasing the number of decision trees or reducing the maximum depth.

[0221] S56: Retrain the random forest model using the adjusted parameters.

[0222] S57: Evaluate the retrained model using the test dataset and calculate new performance metrics.

[0223] S58: If the performance has improved, continue to use the model; otherwise, continue to adjust the parameters and repeat the evaluation process until satisfactory performance is achieved.

[0224] Satisfactory performance means that the performance indicators (accuracy, recall, F1 value) of the model have reached the preset standards, or the performance of the model is stable and has not significantly decreased after multiple adjustments and tests. Satisfactory conditions can be set according to specific application scenarios and requirements.

[0225] The step S7 specifically includes:

[0226] S71: For each pixel in the image, classify it into color categories such as red, blue, green, etc. according to the prediction results of the model.

[0227] S72: Use different colors to mark the classification results. For example, mark the pixels predicted to be red as red, the pixels predicted to be blue as blue, the pixels predicted to be green as green, and so on.

[0228] S73: For each color category, extract the average RGB value of the color as the representative color of the category.

[0229] The step S8 specifically includes the following steps:

[0230] S81: Visual display of color areas: Display the classified and labeled cultural relics images to visually observe the distribution and area of ​​colors.

[0231] S82: Generate a color distribution map: According to the color classification result, count the number of occurrences or frequencies of each color category in the image. Draw a color distribution map in a two-dimensional plane or three-dimensional space, usually using the frequency of the color category as the size or height of the point in the map.

[0232] S83: Generate a color histogram: Generate a color histogram based on the statistical color frequencies. The horizontal axis of the histogram represents different color categories, and the vertical axis represents the frequency or percentage of the color category.

[0233] In the present invention, by integrating the results of multiple decision trees, the accuracy of prediction can be improved, especially when facing data with more noise and interference. The random forest model considers different features and feature subsets during the training process, so that the model can better adapt to unknown data, thereby improving generalization ability.

[0234] Since the random forest model contains multiple decision trees, each of which is built based on a different dataset and feature subset, the risk of overfitting can be reduced. The random forest model contains multiple decision trees, and the parameters of each decision tree, such as the maximum depth, maximum number of features, etc., can be adjusted as needed to improve the performance of the model.

[0235] The results of random forest prediction can be used to generate color distribution maps and color histograms, which are helpful to intuitively display and analyze the color distribution and area in the cultural relic image, and provide support for subsequent analysis and research. In summary, the random forest prediction method plays an important role in the entire cultural relic color extraction method based on machine learning. It can improve the prediction accuracy and generalization ability of the model, reduce the risk of overfitting, facilitate model adjustment and optimization, and provide support for subsequent visualization and analysis.

[0236] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention.

Claims

1. A method for extracting cultural relics colors based on machine learning, characterized in that: The steps include: S1: Collect cultural relic image dataset; S2: preprocessing the images collected in step S1, including scaling, cropping, and grayscale conversion, and then annotating the data set to match the color areas in the cultural relic images with the corresponding color labels; S3: Perform feature extraction, use the color histogram method to extract color features from the preprocessed image, and then normalize the extracted features; S4: Select a random forest machine learning model, train the random forest machine learning model using the training data set, adjust model parameters and optimize the algorithm; S5: Use the test data set to evaluate the trained model, calculate the model's accuracy, recall, and F1 value indicators, and optimize and adjust the model based on the evaluation results; S6: Use the optimized model to extract color from the new cultural relic image, input the extracted color features into the model, and obtain the predicted color label; S7: According to the prediction results, the color areas in the cultural relic image are classified and labeled, and the corresponding colors are extracted; S8: Visualize the extracted cultural relic colors and generate a color distribution map and a color histogram; S9: By comparing with the actual cultural relic image, verify whether the extracted color is consistent with the actual situation, and evaluate and improve the results.

2. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: In step S1, a bicubic interpolation method is used to perform image scaling. The bicubic interpolation method finds the 16 nearest pixel points in the original image and uses a homogeneous polynomial interpolation function to calculate the pixel values ​​in the new image; For each pixel in the scaled image, find the nearest 4x4 pixel block in the original image; use the Bicubic function to calculate the contribution of these pixels to the new pixel value; and weighted sum these contributions to obtain the new pixel value in the scaled image.

3. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: In step S2, image cropping helps remove the background or other non-critical areas of the image by manually selecting the region of interest, so that the model focuses on the color characteristics of the cultural relics; Grayscale conversion: The process of converting a color image into a grayscale image. This is achieved by combining the red, green, and blue channels with different weights. The grayscale conversion formula used is: Gray value = 0.299*R+0.587*G+0.114*B; R, G, and B represent the pixel values ​​of the red, green, and blue channels, respectively.

4. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: In step S3, a color histogram method is used to extract color features from the preprocessed image, and the specific steps are as follows: S31: Select color space: determine which color space is used to represent the color in the image. The color space includes RGB, HSV, and Lab. S32: Dividing the color interval: dividing the color interval into a plurality of sub-intervals according to the characteristics of the color space; S33: Calculate the color histogram: for each pixel in the image, calculate which color interval it belongs to based on its color value; for each color interval, count the number of pixels belonging to the interval to obtain the frequency of the interval; combine the frequencies of all color intervals to obtain the color histogram of the image.

5. The method for extracting cultural relics colors based on machine learning according to claim 4, characterized in that: In step S3, the formula for calculating the color histogram is: f(k)=f(k)+1; Let I represent the image, H represent the color histogram, N represent the total number of pixels in the image, n represent the number of color intervals, k represent the kth color interval, and f(k) represent the frequency of the kth color interval; For each pixel I(x,y) in the image, calculate its color value C, then calculate which color interval k it belongs to based on C, and add 1 to f(k); Finally, the frequencies of all color intervals are combined to obtain the color histogram H of the image; H=(f(1),f(2),...,f(n)).

6. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: In step S3, the extracted features are normalized using minimum-maximum standardization, and the specific steps are as follows: S311: Calculate the maximum and minimum values: For each feature, find the maximum value (Max) and the minimum value (Min) in the data set; S312: Apply transformation formula: For each feature value x in the data set, use the following formula for transformation: Among them, x norm is the transformed value; S313: Transform the dataset: Apply the above transformation to each feature of the entire dataset; after min-max normalization, all features will be scaled to the range of 0 to 1; After min-max normalization, all features are scaled to the range of 0 to 1.

7. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: In step S4, a random forest model is used for training, and the specific steps are as follows: S41: Divide the data set into a feature matrix X and a label vector y, where X contains the color features of 1000 samples and y contains the corresponding color labels; S42: Initialize the random forest model, set parameters nestimators = 100, max_depth = 100, max_features = 'sqrt'; S43: Constructing a random forest model: For i=1 to 100: sampling with replacement from the data set to obtain a new training subset; using this subset to train a decision tree model; adding this decision tree model to the random forest model; S44: Training decision trees: For each decision tree, randomly select a subset from all features as candidate features; select the best features and split points based on the candidate features and Gini impurity; split the node, and repeat the above process until the stopping condition is met; S45: Perform random forest prediction: For a new artifact image, each decision tree independently makes a color prediction; the final prediction result of the random forest is the majority vote of the prediction results of all decision trees.

8. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: The step S5 specifically includes the following steps: S51: preprocess the test data set, extract and normalize the same features as the training data set; S52: Use the trained random forest model to predict the test data set and obtain the prediction results; S53: Calculate the accuracy, recall and F1 value based on the prediction results and actual labels; S54: Analyzing the performance indicators, we found that the recall rate was low, indicating that the model did not predict certain colors well enough; S55: Adjust the parameters of the random forest, such as increasing the number of decision trees or reducing the maximum depth; S56: Retrain the random forest model using the adjusted parameters; S57: Evaluate the retrained model using the test dataset and calculate new performance metrics; S58: If the performance has improved, continue to use the model; otherwise, continue to adjust the parameters and repeat the evaluation process until satisfactory performance is achieved.

9. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: The step S7 specifically includes: S71: for each pixel in the image, classify it into red, blue, and green color categories according to the prediction result of the model; S72: using different colors to mark the classification results, marking pixels predicted to be red as red, blue as blue, and green as green; S73: For each color category, extract the average RGB value of the color as the representative color of the category.

10. The method for extracting cultural relics colors based on machine learning according to claim 1, characterized in that: The step S8 specifically includes the following steps: S81: Visual display of color areas: Display the classified and labeled cultural relics images to visually observe the distribution and area of ​​colors; S82: Generate a color distribution map: according to the color classification result, count the number of occurrences or frequencies of each color category in the image; draw a color distribution map in a two-dimensional plane or a three-dimensional space, and use the frequency of the color category as the size or height of the point in the map; S83: Generate a color histogram: Generate a color histogram according to the statistically obtained color frequencies; the horizontal axis of the histogram represents different color categories, and the vertical axis represents the frequency or percentage of the color category.