A hyperspectral detection method for medical foreign matter
By performing factor analysis and band screening on hyperspectral images of medicines and foreign bodies, abnormal pixels are screened out, and the categories of foreign bodies are determined. This solves the detection error problem caused by the large number of bands in hyperspectral images in the existing technology, and achieves accurate detection of medical foreign bodies. .
Patent Information
- Application Number
- CN202410781206.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-18
AI Technical Summary
The existing medical foreign body detection methods have a large number of bands and high correlation of hyperspectral images, which results in a lot of redundant information. Direct use of high-dimensional data for testing results in low data mining efficiency and large amount of calculation, which in turn leads to detection errors.
By obtaining hyperspectral images of drugs and foreign bodies, perform factor analysis to obtain independent factor vectors and common factor vectors of drugs and foreign bodies, screen target bands, compare the band images of drugs and foreign bodies under the target band, screen out abnormal pixels, and determine the final Foreign matter category enables accurate detection of foreign matter in medicines.
It reduces the error in medical foreign matter detection, improves the accuracy and efficiency of detection, reduces the amount of calculation, and achieves accurate detection of foreign matter.
Smart Images

Figure CN118347954B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of detection technology utilizing spectral properties, and in particular to a hyperspectral detection method for medical foreign matter. Background Art
[0002] In the pharmaceutical production process, foreign matter such as glass, stone chips, hair, and rubber chips often appear, which poses a potential risk to pharmaceutical safety. Therefore, pharmaceutical foreign matter inspection has become an inevitable task in the pharmaceutical process. Due to the rich spectral information brought by the high spectral resolution of hyperspectral technology, hyperspectral technology is often used in existing methods for pharmaceutical foreign matter detection.
[0003] At present, the common method for detecting foreign bodies in medicines is to input the collected hyperspectral images into the trained multi-scale attention mechanism autoencoder network for testing, obtain the reconstructed test image, calculate the reconstruction error between the reconstructed test image and the medical hyperspectral test image, and obtain the foreign body detection result according to the reconstruction error and the preset threshold. There are the following problems in foreign body detection using this method: there are too many bands in the hyperspectral image, the correlation between the bands is large, there is a lot of redundant information, and directly using high-dimensional data for testing has low data mining efficiency and excessive calculation, which will lead to errors in the detection of medical foreign bodies. Summary of the invention
[0004] In order to solve the technical problem of errors in the detection of foreign matter in medicine, the purpose of the present invention is to provide a hyperspectral detection method for foreign matter in medicine. The technical solution adopted is as follows:
[0005] Acquire hyperspectral images of drugs and foreign bodies respectively;
[0006] According to the spectral curve of each pixel point in the hyperspectral image, a complete spectral curve corresponding to the hyperspectral image is obtained; based on the band image corresponding to the hyperspectral image of the foreign body, the foreign body is classified to obtain the spectral foreign body category;
[0007] Perform factor analysis on the complete spectral curves of the hyperspectral images of drugs and foreign bodies to obtain drug-independent factor vectors and foreign body-independent factor vectors; perform analysis on the band images of different bands corresponding to the hyperspectral images of drugs to obtain the band common factor vectors and band independent factor vectors of drugs;
[0008] According to the differences between the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector, the band is screened to obtain the target band; the hyperspectral image of the drug is compared with the band image of the foreign body under the target band, and abnormal pixels are screened out from the hyperspectral image of the drug;
[0009] According to the abnormal pixel points, the final foreign body category is determined from the spectral foreign body category; based on the final foreign body category, the foreign body in the medicine is determined.
[0010] Preferably, the step of screening the bands to obtain the target bands according to the differences among the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector comprises:
[0011] Compare the values of the elements at the same position in the drug-independent factor vector and the foreign-independent factor vector of each foreign body, obtain the degree of distinction of each element value in the drug-independent factor vector, and construct the degree of distinction sequence corresponding to the drug-independent factor vector;
[0012] Calculate the difference between the band common factor sequence corresponding to the band common factor vector and the discrimination degree sequence, recorded as the common difference;
[0013] The mean value of the elements in the band independent factor vector of each band image is obtained as the representation value of each band image; the representation value sequence of the drug is constructed based on the representation values of the band images of different bands corresponding to the drug; the difference between the distinction degree sequence and the representation value sequence of each drug is calculated and recorded as the independent difference;
[0014] The sum of the common difference and the independent difference is taken as the difference sum; the ratio of the common difference to the difference sum is calculated as the common matching degree; the ratio of the independent difference to the difference sum is calculated as the independent matching degree;
[0015] Based on the dynamic time warping algorithm, the elements in the band independent factor sequence and the discrimination degree sequence are matched to obtain the dynamic time warping distance as the band discrimination ability;
[0016] When the common matching degree is greater than the independent matching degree, the information entropy of the band common factor sequence is used as the importance of the band; when the common matching degree is less than or equal to the independent matching degree, the band discrimination ability is used as the importance of the band;
[0017] According to the importance of the bands, the bands are screened to obtain the target bands.
[0018] Preferably, the step of comparing the values of the elements at the same position in the drug-independent factor vector and the foreign-matter-independent factor vector of each foreign body to obtain the degree of distinction of each element value in the drug-independent factor vector includes:
[0019] An arbitrary position is selected as the target position. When the element value at the target position of the drug-independent factor vector is greater than the element value at the target position of all foreign-matter-independent factor vectors, the difference between the element value at the target position of the drug-independent factor vector and the maximum element value at the target position of all foreign-matter-independent factor vectors is taken as the first difference, and the ratio of the first difference to the maximum element value at the target position of all foreign-matter-independent factor vectors is taken as the degree of discrimination.
[0020] When the element value at the target position of the drug-independent factor vector is less than the element value at the target position of all foreign-matter-independent factor vectors, the difference between the element value at the target position of the drug-independent factor vector and the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the second difference, and the ratio of the second difference to the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the degree of discrimination;
[0021] When the element value at the target position of the drug independent factor vector is not greater than the element value at the target position of all foreign matter independent factor vectors, and the element value at the target position of the drug independent factor vector is not less than the element value at the target position of all foreign matter independent factor vectors, the degree of differentiation of the target position of the drug independent factor vector is recorded as the preset second threshold.
[0022] Preferably, the foreign matter is classified based on the band image corresponding to the hyperspectral image of the foreign matter to obtain the spectral foreign matter category, including:
[0023] Calculate the mean pixel value of all pixels in the band image corresponding to the hyperspectral image; construct the band value sequence of each foreign object from the mean pixel value of the band images of different bands of the hyperspectral image corresponding to each foreign object; calculate the sequence similarity of the band value sequence of each foreign object, and classify the foreign objects with sequence similarity greater than a preset similarity threshold into the same category, so as to obtain at least two spectral foreign object categories.
[0024] Preferably, the factor analysis of the complete spectral curves of the hyperspectral images of the drug and the foreign body to obtain the drug-independent factor vector and the foreign body-independent factor vector includes:
[0025] The complete spectral curve of the hyperspectral image of the drug and the complete spectral curve of the hyperspectral image of each foreign body in the same spectral foreign body category are used as the input data of the first factor analysis, and the drug independent factor vector and foreign body independent factor vector are obtained through factor analysis.
[0026] Preferably, the analysis of band images of different bands corresponding to the hyperspectral image of the drug to obtain the band common factor vector and band independent factor vector of the drug includes:
[0027] For the band image of any band corresponding to the hyperspectral image of the drug, the pixel values of the pixel points of the band image are converted into band vectors according to a preset order; the band vectors of the band images of different bands corresponding to the hyperspectral image of the drug are used as the input data of the second factor analysis, and the band common factor vector and band independent factor vector of the drug are obtained through the factor analysis method.
[0028] Preferably, the step of comparing the hyperspectral image of the drug with the band image of the foreign matter in the target band and screening out abnormal pixels from the hyperspectral image of the drug includes:
[0029] Any pixel point in the hyperspectral image of the drug is selected as the target pixel point, and the mean value of the similarity of the spectral curves of the target pixel point in the hyperspectral image and the pixel point at the same position in the band images of all target bands is calculated as the abnormality degree of the target pixel point; the abnormal pixel points are screened out from the hyperspectral image of the drug according to the abnormality degree.
[0030] Preferably, determining the final foreign body category from the spectral foreign body category according to the abnormal pixel point includes:
[0031] Select any abnormal pixel point in the hyperspectral image of the drug as the target abnormal pixel point, select any normal pixel point in the hyperspectral image of the drug as the target normal pixel point, select any foreign matter as the target foreign matter, and construct an abnormal distinction band sequence from the pixel values of the pixel points at the same position as the target abnormal pixel point in the band images of different bands corresponding to the target foreign matter; construct a normal distinction band sequence from the pixel values of the pixel points at the same position as the target normal pixel point in the band images of different bands corresponding to the drug;
[0032] The mean value of the similarity between the abnormal discrimination band sequence of the target abnormal pixel point of the target foreign object and the normal discrimination band sequence of all normal pixels is calculated as the discrimination rate of the target foreign object at the target abnormal pixel point; the foreign object corresponding to the minimum discrimination rate at the target abnormal pixel point is taken as the foreign object corresponding to the target abnormal pixel point, and the category corresponding to the foreign object is taken as the final foreign object category.
[0033] Preferably, obtaining a complete spectral curve corresponding to the hyperspectral image according to the spectral curve of each pixel point in the hyperspectral image includes:
[0034] The spectral curves of each pixel in the hyperspectral image are connected end to end to obtain the complete spectral curve corresponding to the hyperspectral image.
[0035] Preferably, the determining of foreign matter in the medicine based on the final foreign matter category comprises:
[0036] The foreign matter in the final foreign matter category is considered as a foreign matter in the drug.
[0037] The embodiments of the present invention have at least the following beneficial effects:
[0038] The present invention first obtains hyperspectral images of drugs and foreign bodies and corresponding complete spectral curves respectively; since there are many types of foreign bodies, the foreign bodies are first classified based on the band images corresponding to the hyperspectral images of the foreign bodies, and different spectral foreign body categories are obtained, thereby reducing the subsequent calculation amount; the drug independent factor vector, the foreign body independent factor vector, the band common factor vectors and the band independent factor vectors of different bands corresponding to the hyperspectral images of the drugs are respectively obtained, the drug independent factor vector reflects the difference between the drugs and foreign bodies, and the band common factor vector and the band independent factor vector reflect the common characteristics and distinguishing characteristics of drugs in different bands. Therefore, we can further combine the differences between drugs and foreign bodies, the common features and distinguishing features of drugs in different bands to screen out the target band. The spectral image corresponding to the target band can more accurately reflect the presence of foreign bodies in the drugs; compare the hyperspectral image of the drug and the band image of the foreign body under the target band, and screen out abnormal pixels from the hyperspectral image of the drug; determine the final foreign body category from the spectral foreign body category based on the abnormal pixels; determine the foreign body in the drug based on the final foreign body category, and realize accurate detection of foreign bodies in the drug, thereby reducing the detection error of medical foreign bodies. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are 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.
[0040] Figure 1 A method flow chart of a hyperspectral detection method for medical foreign matter provided by one embodiment of the present invention;
[0041] Figure 2 A schematic diagram of a drug independent factor vector and a foreign body factor vector corresponding to foreign bodies in spectral foreign body category A provided by one embodiment of the present invention;
[0042] Figure 3 A schematic diagram of DTW matching of a band-independent factor sequence and a discrimination degree sequence provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0043] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the hyperspectral detection method of medical foreign matter proposed by the present invention, its specific implementation method, structure, characteristics and effects are described in detail as follows in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0044] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0045] The embodiment of the present invention provides a specific implementation method of a hyperspectral detection method for medical foreign matter, which is applicable to medical foreign matter detection scenarios. In order to solve the technical problem of errors in the detection of medical foreign matter, the present invention analyzes the spectral characteristics of medicine and foreign matter, obtains the band combination with the maximum separability of medicine and different spectral foreign matter categories, and then calculates the maximum separability of medicine and different spectral foreign matter categories through the band combination, so as to achieve accurate detection of foreign matter.
[0046] The specific scheme of the hyperspectral detection method for medical foreign matter provided by the present invention is described in detail below with reference to the accompanying drawings.
[0047] See also Figure 1 , which shows a flowchart of a method for hyperspectral detection of medical foreign matter provided by an embodiment of the present invention, the method comprising the following steps:
[0048] Step S100, acquiring hyperspectral images of the medicine and the foreign matter respectively.
[0049] The purpose of the present invention is to identify foreign bodies in medicines through the high spectral resolution of hyperspectral data, so it is necessary to first obtain hyperspectral images of medicines and different foreign bodies. Since the reduced dimensionality bands obtained by the traditional PCA dimensionality reduction method may not be able to distinguish medicines and different foreign bodies well. Therefore, the present invention calculates the best distinguishing bands between medicines and different foreign bodies, and utilizes the high degree of distinction effect on these bands to achieve accurate detection of foreign bodies. Since there are many types of foreign bodies, in order to reduce the amount of calculation, the foreign bodies can be classified by the similarity of the spectral curves of the foreign bodies to obtain different spectral foreign body categories.
[0050] First, hyperspectral images of drugs and different foreign bodies are acquired through a hyperspectral camera. One drug corresponds to one hyperspectral image, and one foreign body also corresponds to one hyperspectral image.
[0051] Step S200, obtaining a complete spectral curve corresponding to the hyperspectral image according to the spectral curve of each pixel point in the hyperspectral image; classifying the foreign matter based on the band image corresponding to the hyperspectral image of the foreign matter to obtain a spectral foreign matter category.
[0052] For the same object, there are also differences in the spectral curves at different positions, but the differences are smaller for different objects. Therefore, although the spectral curve of each pixel point in each hyperspectral image can represent the spectral situation of the object, there are errors. Therefore, the present invention first obtains the hyperspectral images of the medicine and the foreign matter, and then obtains a curve by connecting the spectral curves of each pixel point in the hyperspectral image end to end, and the curve is called the complete spectral curve corresponding to the hyperspectral image; that is, the spectral curves of each pixel point in the hyperspectral image are connected end to end to obtain the complete spectral curve corresponding to the hyperspectral image.
[0053] If the foreign bodies are calculated directly through the complete spectral curve, the number of categories obtained is too large, which cannot effectively achieve the purpose of reducing the amount of calculation. Therefore, the similarity is calculated for the average spectral curve of each foreign body, and then the category is obtained, which is called the spectral foreign body category.
[0054] Based on the complete spectral curve of the foreign matter, the foreign matter is classified to obtain the spectral foreign matter category, specifically:
[0055] Since each pixel point in the hyperspectral image corresponding to each foreign object can represent the spectral characteristics of the foreign object, the pixel value mean of all pixel points in the band image corresponding to the hyperspectral image is first calculated; the band value sequence of each foreign object is formed by the pixel value mean of the band image of different bands of the hyperspectral image corresponding to each foreign object; the sequence similarity of the band value sequence of each foreign object is calculated, and the foreign objects with sequence similarity greater than the preset similarity threshold are classified into the same category to obtain at least two spectral foreign object categories. In the embodiment of the present invention, the value of the preset first threshold is 0.8, and in other embodiments, the implementer adjusts the value according to the actual situation.
[0056] Step S300, factor analysis is performed on the complete spectral curves of the hyperspectral images of the drug and the foreign matter to obtain a drug-independent factor vector and a foreign matter-independent factor vector; band images of different bands corresponding to the hyperspectral images of the drug are analyzed to obtain a band common factor vector and a band independent factor vector of the drug.
[0057] The drug-independent factor vector obtained by factor analysis of drugs and different spectral foreign matter categories represents the spectral features of the drug's spectral curve that other foreign matters do not have. It is the independent factor feature of the drug and is also called the drug-independent factor vector.
[0058] The common factor vector obtained by factor analysis of different band data of a drug can represent the common characteristics of all band data of the drug, which is called the band common characteristics of the drug, also called the band common factor vector of the drug.
[0059] The drug independent factor vector represents the distinguishing features between the drug and other foreign bodies, and the drug band common factor vector represents the characteristics of the drug. Therefore, it is only necessary to extract the distinguishing features from the drug band common factor vector to serve as the basis for foreign body detection.
[0060] Since the purpose of the present invention is to obtain the best distinguishing band between drugs and different spectral foreign matter categories through analysis, the best distinguishing band is the band where the difference between the two is large. For example: the reflectivity of water in the near-infrared band is 0, while the reflectivity of vegetation in the near-infrared band is large, so the near-infrared band can be used as the best distinguishing band between water and vegetation to distinguish the two. Therefore, it is first necessary to extract the distinguishing features of drugs and foreign matter in different spectral foreign matter categories, and the distinguishing features refer to the large difference in the values of drugs and foreign matter in this feature. Factor analysis is a method for extracting common features and independent features, and the distinguishing features correspond to the independent features in factor analysis. Therefore, the factor analysis method is used to extract the independent features of drugs and different spectral foreign matter categories. The independent features correspond to the drug independent factor vector and the foreign matter independent factor vector in the factor analysis process, that is, the drug independent factor vector and the foreign matter independent factor vector can represent the distinguishing features of drugs and foreign matter in a certain spectral foreign matter category.
[0061] Therefore, we first perform factor analysis on the complete spectral curves of the hyperspectral images of drugs and foreign bodies to obtain drug independent factor vectors and foreign body independent factor vectors. Specifically:
[0062] The complete spectral curve of the hyperspectral image of the drug and the complete spectral curve of the hyperspectral image of each foreign body in the same spectral foreign body category are used as the input data of the first factor analysis. The independent factor vector of each data is obtained through factor analysis, that is, the drug independent factor vector and the foreign body independent factor vector are obtained through factor analysis.
[0063] The complete spectral curves corresponding to the hyperspectral images of different bands of the drug are analyzed to obtain the common factor vectors of the drug bands and the independent factor vectors of different hyperspectral images:
[0064] For the band image of any band corresponding to the hyperspectral image of the drug, the pixel values of the pixel points of the band image are converted into band vectors according to a preset order. In the embodiment of the present invention, the preset order is a serpentine order from left to right and from top to bottom. That is, the pixel values of the pixel points in the band image of any band corresponding to the hyperspectral image of the drug are converted into vector form according to a serpentine order from left to right and from top to bottom, and the band vectors corresponding to all bands of the drug are used as input data for the second factor analysis, that is, a vector data is used as an input data, and the common factor vector of all data is obtained through the second factor analysis. The common factor vector represents the common features in the different band data of the drug, and all complete spectral vectors correspond to a common factor vector, which is called the band common factor vector of the drug. At the same time, the band independent factor vectors of different bands of the drug can also be obtained, and one data corresponds to an independent factor vector. The independent factor vector of each data represents the unique features of the band, that is, the features that other bands do not have, which is called the band independent factor vector of the drug.
[0065] Step S400, based on the differences among the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector, the band is screened to obtain the target band; the hyperspectral image of the drug and the band image of the foreign body under the target band are compared, and abnormal pixels are screened out from the hyperspectral image of the drug.
[0066] The drug-independent factor vector and the band common factor vector are further matched using the dynamic time warping (DTW) algorithm to obtain the distinguishing bands of drugs and different spectral foreign matter categories.
[0067] The drug-independent factor vector is obtained through the first factor analysis. Since the input data of the first factor analysis are the complete spectral curves of the hyperspectral image of the drug and the complete spectral curves of the hyperspectral image of the foreign body, the drug-independent factor vector obtained represents the different characteristics of the drug and the foreign body.
[0068] The band common factor vector of a drug represents the common features of the drug in different bands. Combining the unique band independent factor vectors of different bands contained in the band common factor vector of the drug can represent all the features of the drug.
[0069] The drug-independent factor vector represents the feature obtained by subtracting the intersection feature of the drug and foreign matter from all the features of the drug. Therefore, the information of the drug-independent factor vector must be contained in the information of the band common factor vector and the band independent factor vector of the drug.
[0070] Compared with the value of the element at the corresponding position in the drug-independent factor vector and the foreign-independent factor vector, if the value is larger or smaller, the value can be used as a distinguishing feature between drugs and foreign bodies, and the distinguishing effect is better. Therefore, first, by comparing the element value at each position in the drug-independent factor vector with the element value at each position in the foreign-independent factor vector, the extreme effect of each element value is obtained. The better the extreme effect, the stronger the distinguishing property of the feature. The step of calculating the extreme effect of each element value in the drug-independent factor vector is to calculate the degree of distinction of each element in the drug-independent factor vector. Therefore, the element values at the same position in the drug-independent factor vector and the foreign-independent factor vector of each foreign body are compared to obtain the degree of distinction of each element value in the drug-independent factor vector. Specifically:
[0071] Select an arbitrary position as the target position. When the element value at the target position of the drug independent factor vector is greater than the element value at the target position of all foreign body independent factor vectors, the difference between the element value at the target position of the drug independent factor vector and the maximum element value at the target position of all foreign body independent factor vectors is taken as the first difference, and the ratio of the first difference to the maximum element value at the target position of all foreign body independent factor vectors is taken as the degree of distinction.
[0072] When the element value at the target position of the drug-independent factor vector is less than the element value at the target position of all foreign-matter-independent factor vectors, the difference between the element value at the target position of the drug-independent factor vector and the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the second difference, and the ratio of the second difference to the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the degree of discrimination;
[0073] When the element value at the target position of the drug-independent factor vector is not greater than the element value at the target position of all foreign-matter-independent factor vectors, and the element value at the target position of the drug-independent factor vector is not less than the element value at the target position of all foreign-matter-independent factor vectors, the degree of differentiation of the target position of the drug-independent factor vector is recorded as the preset second threshold. In the embodiment of the present invention, the value of the preset second threshold is 0, and in other embodiments, the implementer adjusts the value according to the actual situation. Thus, the degree of differentiation corresponding to each element value in the drug-independent factor vector is obtained, and a sequence of degrees of differentiation corresponding to the drug-independent factor vector is constructed.
[0074] See also Figure 2 , Figure 2Schematic diagram of drug-independent factor vector and foreign body factor vector corresponding to foreign bodies in spectral foreign body category A. For example, the element at the first position of the drug independent factor vector is 50, which is the maximum value compared with the element value at the first position of the foreign body factor vector corresponding to the foreign body in the spectral foreign body category, and the maximum element value at the first position of the foreign body independent factor vector corresponding to the foreign body is 16, then the degree of distinction is (50-16) / 16=2.125; when the element at the second position of the drug independent factor vector is 8, it is the minimum value compared with the element value at the second position of each foreign body in the spectral foreign body category, and the minimum element value at the second position of the foreign body independent factor vector of the foreign body is 21, the degree of distinction is (8-21) / 21=-0.619; when the element value at the third position of the drug independent factor vector of the drug is 33, compared with the element value at the third position of the foreign body independent factor vector of the foreign body in the spectral foreign body category, it is not the maximum value, that is, it is not greater than the maximum value at the target position of the foreign body independent factor vector, nor less than the minimum value at the target position of the foreign body independent factor vector, then it is not considered as a distinguishing feature between drugs and foreign bodies, and the degree of distinction corresponding to the third position is recorded as 0.
[0075] The degree of differentiation of the element value at each position in the drug independent factor vector is obtained by calculation, and the degree of differentiation also reflects the differentiation of the drug element and foreign matter at the corresponding position. The degree of differentiation sequence refers to the degree of differentiation of foreign matter in different characteristics between drugs and spectral foreign matter categories. The larger the element value at each position, the greater the degree of differentiation.
[0076] Since the information for distinguishing drugs and foreign bodies is partly distinguished by the common information of all bands and partly distinguished by the independent information of each band, it is necessary to calculate the proportion of independent information and common information in the distinguishing information, and then prepare for the subsequent selection of discriminative bands.
[0077] The proportion of independent information and public information is obtained by DTW distance calculation. If the proportion of independent information is large, the curve formed by the independent factor vector matches the discrimination curve to a greater extent, that is, the DTW distance is small. The process of calculating the proportion of independent information and public information is as follows:
[0078] Calculate the difference between the band common factor sequence corresponding to the band common factor vector and the discrimination degree sequence, which is recorded as the common difference. In the embodiment of the present invention, the difference between the two sequences is the dynamic time warping distance calculated by the dynamic time warping algorithm, also recorded as the DTW distance. Calculate the DTW distances between the band common factor vector and the band independent factor vector of the drug and the discrimination degree sequence respectively, and convert the discrimination degree sequence into a discrimination degree vector. The DTW distance of the discrimination degree vector corresponding to the band common factor vector and the discrimination degree sequence is relatively easy to obtain, because the data of the two are consistent and are in vector form. The DTW distance between the band common factor vector and the discrimination degree sequence is represented by u.
[0079] However, the band-independent factor vector is a band-independent factor vector corresponding to one band. Therefore, the mean of all elements in the band-independent factor vector of each band is first calculated as the representation value of the independence of the band. The larger the representation value, the greater the information content of the independent feature of the band. The representation values of different bands can form a sequence, which is recorded as the representation value sequence. The DTW distance between the representation value sequence and the distinction degree sequence is calculated and represented by v. That is, the mean of the elements in the band-independent factor vector of each band image is obtained as the representation value of each band image; the representation value sequence of the drug is constructed from the representation values of the band images of different bands corresponding to the drug; the difference between the distinction degree sequence and the representation value sequence of each drug is calculated and recorded as the independent difference.
[0080] The sum of the common difference and the independent difference is taken as the difference sum; the ratio of the common difference to the difference sum is calculated as the common matching degree; and the ratio of the independent difference to the difference sum is calculated as the independent matching degree.
[0081] That is, the ratio of u and u+v is calculated as the ratio of public information, which is called the public matching degree U of the band public factor vector, and the ratio of v and u+v is calculated as the ratio of public information, which is called the independent matching degree V of the band independent factor vector. The matching degree is respectively regarded as the proportion of independent information and public information, which reflects how much distinguishing information is contained in public information and independent information respectively. U represents the proportion of public information, and V represents the proportion of public independent information. The larger the DTW distance, the smaller the matching degree.
[0082] Combined with the matching information of independent features, corresponding matching information will be obtained during the DTW calculation process. The discrimination degree sequence corresponds to the sequence with a large number of element values above, and the band-independent factor sequence of the band-independent factor vector corresponds to the sequence with a small number of element values below. The independent information of each band can be obtained directly, so what is calculated is the matching of each independent factor in the band-independent factor sequence. Through the matching information in DTW, the matching of each element value in the band-independent factor sequence and each element value in the discrimination degree sequence can be obtained. Please refer to Figure 3 , Figure 3 The figure is a schematic diagram of DTW matching between band-independent factor sequence and discrimination degree sequence, where A is an element value in the band-independent factor sequence, a1, a2, and a3 are three element values in the discrimination degree sequence, and A corresponds to a1, a2, and a3, that is, A matches a1, a2, and a3. At this time, the larger the values of a1, a2, and a3 are, the larger the discrimination value of the matching corresponding to A is, which reflects that the band corresponding to A can better match drugs and other bands than other bands. The value of each element in the band-independent factor sequence can be obtained by calculation, and the elements in the band-independent factor curve and the discrimination degree curve are matched based on the DTW algorithm to obtain the DTW distance of each band-independent factor sequence. The DTW distance is negatively correlated and normalized to obtain the band discrimination ability of the band-independent factor sequence. The larger the value of the band discrimination ability is, the stronger the discrimination ability of the corresponding band is.
[0083] The proportion of public information of all bands and the proportion of independent information of each band are calculated, that is, the matching degree of the band common factor vector, the matching degree of the band independent factor vector, and the distinguishing ability of the independent information of each band are obtained. Compared with public information, when the proportion of independent information is larger, for a band, the proportion of independent information is larger, the distinguishing ability of the independent information is larger, and the importance of the band is greater. Because when the proportion of independent information of a band is larger, it reflects that the band can better distinguish between drugs and foreign bodies. On the contrary, when compared with independent information, the proportion of public information is larger, for a band, the public information content is larger, and the importance of the band is greater.
[0084] Therefore, we further calculated the importance of different bands, specifically:
[0085] When the proportion of public information is large, the band with larger information entropy is selected. The larger the information entropy, the greater the importance of the band. Therefore, when the public matching degree is greater than the independent matching degree, the information entropy of the band public factor sequence is used as the importance of the band.
[0086] When the proportion of independent information is large, the band with greater band discrimination ability of independent information is selected. The greater the discrimination ability, the greater the importance of the band. When the common matching degree is less than or equal to the independent matching degree, the band discrimination ability is used as the importance of the band.
[0087] According to the importance of the bands, the bands are screened to obtain the target bands. Specifically: in the order of importance from large to small, a preset first number of bands are screened from all the bands, and the screened bands are used as target bands. In the embodiment of the present invention, the value of the preset first number is 15, and in other embodiments, the implementer adjusts the value according to the actual situation. According to the importance, the priority of the band selection is determined. For example, when selecting 15 bands from 152 bands to distinguish between drugs and foreign matter, the bands are selected according to the priority of importance, that is, the bands are selected in order from large to small importance. It should be noted that since the selection conditions for the bands are different in different embodiments, the size of the number of bands selected is no longer limited here.
[0088] When actually calculating whether there is a foreign body in a drug, first obtain the hyperspectral image of the drug, then obtain the spectral curve of each pixel, calculate the sum of the similarities between the spectral curve of each pixel and the spectral curve of the pixel at the same position in the band image of the target band, considering that the foreign body content in the drug is small, and the spectral curve of the drug pixel is similar to the spectral curve of all drug pixels, and there are many drug pixels, so the sum of the similarities of the drug pixels is large, while the foreign body pixel is only similar to the spectral curve of the foreign body pixel, and there are few foreign body pixels, so the sum of the similarities of the foreign body pixels is small, through this property, the abnormal pixel can be found, and the sum of the similarities between each pixel and all other pixels at the same position in the band image of different target bands is calculated and then averaged, and the average obtained is used as the abnormal degree of the target pixel. The pixel whose abnormal degree is less than the preset third threshold is regarded as the abnormal pixel. In the embodiment of the present invention, the value of the preset third threshold is 0.3, and the value can be adjusted by the implementer according to the actual situation in other embodiments.
[0089] That is, the hyperspectral image of the drug is compared with the band image of the foreign body in the target band, and abnormal pixels are screened out from the hyperspectral image of the drug. Specifically: any pixel in the hyperspectral image of the drug is selected as the target pixel, and the mean of the similarity of the spectral curves of the target pixel in the hyperspectral image and the pixel at the same position in the band images of all target bands is calculated as the abnormality degree of the target pixel; the abnormal pixels are screened out from the hyperspectral image of the drug according to the abnormality degree. The abnormal pixels are screened out from the hyperspectral image of the drug according to the abnormality degree. Among them, the abnormal pixels are screened out from the hyperspectral image of the drug according to the abnormality degree, specifically: the pixels on the hyperspectral image of the drug whose abnormality degree is less than the preset third threshold are regarded as abnormal pixels.
[0090] Step S500, determining the final foreign matter category from the spectral foreign matter category according to the abnormal pixel points; and determining the foreign matter in the medicine based on the final foreign matter category.
[0091] Select any abnormal pixel point in the hyperspectral image of the drug as the target abnormal pixel point, select any normal pixel point in the hyperspectral image of the drug as the target normal pixel point, select any foreign matter as the target foreign matter, and construct an abnormal distinction band sequence from the pixel values of the pixel points at the same position as the target abnormal pixel point in the band images of different bands corresponding to the target foreign matter; construct a normal distinction band sequence from the pixel values of the pixel points at the same position as the target normal pixel point in the band images of different bands corresponding to the drug;
[0092] The mean value of the similarity between the abnormal discrimination band sequence of the target abnormal pixel point of the target foreign object and the normal discrimination band sequence of all normal pixels is calculated as the discrimination rate of the target foreign object at the target abnormal pixel point; the foreign object corresponding to the minimum discrimination rate at the target abnormal pixel point is taken as the foreign object corresponding to the target abnormal pixel point, and the category corresponding to the foreign object is taken as the final foreign object category.
[0093] Based on the final foreign matter category, the foreign matter in the medicine is determined. Specifically, the foreign matter in the final foreign matter category is regarded as the foreign matter in the medicine.
[0094] In view of the problem that the data after dimensionality reduction cannot well distinguish between medicines and foreign bodies when identifying medical foreign bodies in traditional methods using PCA method to reduce the dimensionality of hyperspectral data, the present invention proposes a hyperspectral detection method for medical foreign bodies, which analyzes the spectral characteristics of medicines and foreign bodies to obtain the band combination with the maximum class separability between medicines and different spectral foreign body categories, and then calculates the maximum separability between medicines and different spectral foreign body categories through the band combination, thereby realizing accurate detection of foreign bodies.
[0095] In summary, the present invention first obtains hyperspectral images and corresponding complete spectral curves of drugs and foreign bodies respectively; based on the band images corresponding to the hyperspectral images of foreign bodies, the foreign bodies are classified to obtain spectral foreign body categories; factor analysis is performed on the complete spectral curves of the hyperspectral images of drugs and foreign bodies to obtain drug independent factor vectors and foreign body independent factor vectors; band images of different bands corresponding to the hyperspectral images of drugs are analyzed to obtain band common factor vectors and band independent factor vectors of drugs; according to the differences between the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector, the band is screened to obtain the target band; the hyperspectral image of the drug and the band image of the foreign body under the target band are compared to screen out abnormal pixel points from the hyperspectral image of the drug; according to the abnormal pixel points, the final foreign body category is determined from the spectral foreign body category; based on the final foreign body category, the foreign body in the drug is determined to achieve accurate detection of foreign body in the drug.
[0096] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0097] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
Claims
1. A hyperspectral detection method for medical foreign matter, characterized in that: The method comprises the following steps: Acquire hyperspectral images of drugs and foreign bodies respectively; According to the spectral curve of each pixel point in the hyperspectral image, a complete spectral curve corresponding to the hyperspectral image is obtained; based on the band image corresponding to the hyperspectral image of the foreign body, the foreign body is classified to obtain the spectral foreign body category; Perform factor analysis on the complete spectral curves of the hyperspectral images of drugs and foreign bodies to obtain drug-independent factor vectors and foreign body-independent factor vectors; perform analysis on the band images of different bands corresponding to the hyperspectral images of drugs to obtain the band common factor vectors and band independent factor vectors of drugs; According to the differences between the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector, the band is screened to obtain the target band; the hyperspectral image of the drug is compared with the band image of the foreign body under the target band, and abnormal pixels are screened out from the hyperspectral image of the drug; According to the abnormal pixel points, the final foreign body category is determined from the spectral foreign body category; based on the final foreign body category, the foreign body in the medicine is determined; The method of screening the bands to obtain the target bands according to the differences among the drug independent factor vector, the foreign body independent factor vector, the band common factor vector and the band independent factor vector includes: Compare the values of the elements at the same position in the drug-independent factor vector and the foreign-independent factor vector of each foreign body, obtain the degree of distinction of each element value in the drug-independent factor vector, and construct the degree of distinction sequence corresponding to the drug-independent factor vector; Calculate the difference between the band common factor sequence corresponding to the band common factor vector and the discrimination degree sequence, recorded as the common difference; The mean value of the elements in the band independent factor vector of each band image is obtained as the representation value of each band image; the representation value sequence of the drug is constructed based on the representation values of the band images of different bands corresponding to the drug; the difference between the distinction degree sequence and the representation value sequence of each drug is calculated and recorded as the independent difference; The sum of the common difference and the independent difference is taken as the difference sum; the ratio of the common difference to the difference sum is calculated as the common matching degree; the ratio of the independent difference to the difference sum is calculated as the independent matching degree; Based on the dynamic time warping algorithm, the elements in the band independent factor sequence and the discrimination degree sequence are matched to obtain the dynamic time warping distance as the band discrimination ability; When the common matching degree is greater than the independent matching degree, the information entropy of the band common factor sequence is used as the importance of the band; when the common matching degree is less than or equal to the independent matching degree, the band discrimination ability is used as the importance of the band; According to the importance of the bands, the bands are screened to obtain the target bands; The step of comparing the values of the elements at the same position in the drug-independent factor vector and the foreign-matter-independent factor vector of each foreign body to obtain the degree of distinction of each element value in the drug-independent factor vector includes: An arbitrary position is selected as the target position. When the element value at the target position of the drug-independent factor vector is greater than the element value at the target position of all foreign-matter-independent factor vectors, the difference between the element value at the target position of the drug-independent factor vector and the maximum element value at the target position of all foreign-matter-independent factor vectors is taken as the first difference, and the ratio of the first difference to the maximum element value at the target position of all foreign-matter-independent factor vectors is taken as the degree of discrimination. When the element value at the target position of the drug-independent factor vector is less than the element value at the target position of all foreign-matter-independent factor vectors, the difference between the element value at the target position of the drug-independent factor vector and the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the second difference, and the ratio of the second difference to the minimum element value at the target position of all foreign-matter-independent factor vectors is taken as the degree of discrimination; When the element value at the target position of the drug independent factor vector is not greater than the element value at the target position of all foreign body independent factor vectors, and the element value at the target position of the drug independent factor vector is not less than the element value at the target position of all foreign body independent factor vectors, the degree of differentiation of the target position of the drug independent factor vector is recorded as the preset second threshold value; Wherein, determining the final foreign body category from the spectral foreign body category according to the abnormal pixel point includes: Select any abnormal pixel point in the hyperspectral image of the drug as the target abnormal pixel point, select any normal pixel point in the hyperspectral image of the drug as the target normal pixel point, select any foreign matter as the target foreign matter, and construct an abnormal distinction band sequence from the pixel values of the pixel points at the same position as the target abnormal pixel point in the band images of different bands corresponding to the target foreign matter; construct a normal distinction band sequence from the pixel values of the pixel points at the same position as the target normal pixel point in the band images of different bands corresponding to the drug; The mean value of the similarity between the abnormal discrimination band sequence of the target abnormal pixel point of the target foreign object and the normal discrimination band sequence of all normal pixels is calculated as the discrimination rate of the target foreign object at the target abnormal pixel point; the foreign object corresponding to the minimum discrimination rate at the target abnormal pixel point is taken as the foreign object corresponding to the target abnormal pixel point, and the category corresponding to the foreign object is taken as the final foreign object category.
2. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The foreign matter is classified based on the band image corresponding to the hyperspectral image of the foreign matter to obtain the spectral foreign matter category, including: Calculate the mean pixel value of all pixels in the band image corresponding to the hyperspectral image; construct the band value sequence of each foreign object from the mean pixel value of the band images of different bands of the hyperspectral image corresponding to each foreign object; calculate the sequence similarity of the band value sequence of each foreign object, and classify the foreign objects with sequence similarity greater than a preset similarity threshold into the same category, so as to obtain at least two spectral foreign object categories.
3. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The complete spectral curves of the hyperspectral images of the drugs and foreign bodies are subjected to factor analysis to obtain drug-independent factor vectors and foreign body-independent factor vectors, including: The complete spectral curve of the hyperspectral image of the drug and the complete spectral curve of the hyperspectral image of each foreign body in the same spectral foreign body category are used as the input data of the first factor analysis, and the drug independent factor vector and foreign body independent factor vector are obtained through factor analysis.
4. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The band images of different bands corresponding to the hyperspectral image of the drug are analyzed to obtain the band common factor vector and band independent factor vector of the drug, including: For the band image of any band corresponding to the hyperspectral image of the drug, the pixel values of the pixel points of the band image are converted into band vectors according to a preset order; the band vectors of the band images of different bands corresponding to the hyperspectral image of the drug are used as the input data of the second factor analysis, and the band common factor vector and band independent factor vector of the drug are obtained through the factor analysis method.
5. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The step of comparing the hyperspectral image of the drug with the band image of the foreign body in the target band and screening out abnormal pixels from the hyperspectral image of the drug includes: Any pixel point in the hyperspectral image of the drug is selected as the target pixel point, and the mean value of the similarity of the spectral curves of the target pixel point in the hyperspectral image and the pixel point at the same position in the band images of all target bands is calculated as the abnormality degree of the target pixel point; the abnormal pixel points are screened out from the hyperspectral image of the drug according to the abnormality degree.
6. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The method of obtaining a complete spectral curve corresponding to the hyperspectral image according to the spectral curve of each pixel point in the hyperspectral image includes: The spectral curves of each pixel in the hyperspectral image are connected end to end to obtain the complete spectral curve corresponding to the hyperspectral image.
7. The hyperspectral detection method for medical foreign matter according to claim 1, characterized in that: The foreign matter in the drug is determined based on the final foreign matter category, including: The foreign matter in the final foreign matter category is considered as a foreign matter in the drug.
