In this tutorial quantitative analysis by means of Perception Studio and by means of Matlab is described.
|Table of Contents|
In many industries quantitative measurement of spectral information gives an valued input e.g. for quality inspection. This page summarizes an example on modelling the API (active pharmaceutical ingredient) of pills.
The aim is to find a model which allows the measurement of the amount of the chemical ingredient in pills. As a result the achieved model is applied onto the measurement data and result in a gray-value image, where its pixel values correspond to the quantity (to the amount) of the modelled substance. Of course such a model can get applied in real-time to enable industrial real time inspection e.g. in the field of pharmaceutical production.
In this tutorial pills of different Ibuprofen content are investigated by a NIR line-scan camera FX17 of Specim compliant for CCI processing. After a short exploratory analysis, the CCI-Constrain method is used for modeling, after that Matlab is used to do chemometric modelling.
Data, Samples & Measurement
Start the project
Install the example project by double click on the downloaded file and follow the instructions of the installer.
Open the Perception Studio program (e.g. from a link on your desktop) and change to the Start perspective.
Switch to example projects and select Ibuprofen pills from the list shown in the Start perspective.
Now, all data are loaded into the Perception Studio program, please give the system some seconds time to load all the data (watch the progress bar).
Exploratory analysis of the data
Change to the Explore perspective and select the HS cube ibuprofen from the project browser.
In the Explore perspective the Hyperspectral data loaded (data set ibuprofen) is visualized by an image in the center of the perspective as well as a spectra view on the bottom and a cube intersection view to the right.
Explore spectral information
The loaded example data come along with some predefined spectra sets. Have a look in the spectra view and study the shown spectra sets.
The reflectance measurement was done in the NIR range (~950-1700nm). Spectral bands are strong correlated to the varying Ibuprofen content in the range 1115-1230nm.
Explore the nature of information nested
Preview Feature - find candidates for a proper preprocessing
In the following illustration the preview of the data is shown.
|without||1st derivative||2nd derivative|
Without preprocessing the pills are hardly distinguishable in the image above by their color information. By applying the 1st derivative the varying Ibuprofen content get visible by a greenish color gradient. The 2nd derivative shows clear distances between pills of different Ibuprofen content.
So the Preview feature correlates to the varying Ibuprofen content when preprocessing "1st derivative" or "2nd derivative" is applied.
This indicates "1st der" or "2nd der" are potential candidates for a proper preprocessing when the extraction of the Ibuprofen content is aimed.
Statistical Features - judge the quality of spectra
Various statistical feature can get selected out from the ribbon menu on the top of Perception Studios Model perspective.
The statistical maximum of the 1st derivative of the pills show uncertainties on the border of the pills (light area).
Position the mouse onto such an area and study the spectral information.
The spectra of an "uncertain" pixel is shown above in white color.
As you can see, the spectra hardly correspond to the spectra from the center of the pill. It is good practice to keep out such pixels from further investigation - the spectral response seem to be distorted by measurement errors and therefore seem to be not trustful.
For more information on exploratory investigation of hyperspectral data see Exploratory analysis of plastics.
Model the application relevant information
In this tutorial our aim is to model the Ibuprofen concentration of available pills. The measurement of pills are available two times. One from side 1 (top side) and the second one from side 2 (bottom side) of each pill. Side 1 of all pills are used for training, side 2 is used to validate the developed model later on.
Perception Studio - CCI-Constrain Method
The following procedure describes the modelling process by means of the CCI-Constrain method.
Switch to Perception Studios Model perspective and select Constrain as CCI method from the ribbon menu on the top of this perspective.
As you can see the modelling process automatically results in an image which describes the Ibuprofen content by the color red.
This is because the user-given color of selected spectra sets was chosen in correspondence to the concentration of Ibuprofen in the pills. The spectra set of 73.6% Ibuprofen is deep-red, while the spectra set of 23.4% is shown by a light-red color.
To do the chemometric modelling, we need to assign nominal quantitative values to the spectra sets. In case of the CCI-Constrain method, just constrain (e.g.) gray-values, which correspond to the nominals values of the pills, to the spectra.
In the illustration above, the gray-values 74, 60, 49 and 23 got assigned to the spectra (click on the color field below Constraint to specify a color or gray value).
Because of the results from the exploratory investigation, the preprocessing 1st derivative was selected (in the ribbon above).
Validation of results
To validate the results gained, move your mouse over the resulting image and inspect the images gray-values. As you can see, the gray-value correspond to "constrained" gray-values.
E.g. fine-tune the model to be more sensitive in order to reach a better match between your expectations (constrained values) and the results. To do so, move the slider from left to right. Be sure to find a setting which is a good trade-of of "robustness" and "sensitiveness".
The images gained for different preprocessing are analyzed statistically in the illustration below (by means of Matlab).
|1st derivative - sensitivety 4||2nd derivative - sensitivety 4|
|1st derivative||2nd derivative|
The measurement results obtained by 1st derivative and 2nd derivative are more or less comparable.
Since the noise in the results is more in value when 2nd derivative is applied (standard deviation is more in value), the model obtained by applying the 1st derivative as preprocessing method might is preferred.
For more information on modeling see Model Hyperspectral Information
Matlab - Statistics Toolbox
In this section, the possibility to do the modelling work within Matlab is discussed. When imported back into Perception Studio, the model can get applied e.g. in real-time (Perception Core).
Step 1 - Select spectra and apply preprocessing
Select spectra from objects and apply spectral preprocessing within Perception Studio before export to Matlab.
Because of experience gained in the beginning exploratory step, „1st derivative“ is used.
Step 2 - Export of data
Select the data (the cube) within Perception Studios project browser (most left in the Explore or the Model perspective).
Beforehand export, be sure the data is properly preprocessed.
Export Spectra Sets (ASCII)
Select "Spectra Sets Text File (*.sst)" to be the target file format and confirm.
Export Hyperspectral Cube data
Select "Matlab Binary (*.mat)" to be the target file format and confirm.
In the export options dialog select Processed and confirm. By this, preprocessed data (like it is shown in the Perception Studio program) get exported.
Step 3 - Data import, modelling and export of the model from Matlab
Get helper functions used in this tutorial:
Download the data used in this tutorial.
Copy and run the following code in Matlab.
[svSpecSet , svCoordMap]= LoadSpectraSet; %load the spectra sets from file. [C,p,u] = LoadHSData; %load the hyperspectral cube from file. %get all spectra in form of a matrix in X and %interpret the spectra sets name as nominal value in Y X=; Y=; for i=1:length(svSpecSet) I = svSpecSet(i).I; X = cat(1,X,I); V = str2num( svSpecSet(i).name ); V = repmat( V , [size(I,1) , 1] ); Y = cat(1,Y,V); end %apply mean centering XMeanCenter = mean( X , 1 ); X = X - repmat( XMeanCenter , [size(X,1) , 1] ); %calculate PLS regression [XL,YL,XS,YS,Beta] = plsregress( X , Y , 4 ); B0 = Beta(1); B = Beta(2:end); %Apply linear model B to the cube. X = reshape( permute(C,[1 3 2]) , [size(C,1)*size(C,3),size(C,2)] ); %bring cube in the form objects x variables. X = X - repmat( XMeanCenter , [size(X,1) , 1] ); %mean center the spectra Y_ = X*B+B0; %apply model Y_ = reshape( Y_ , [size(C,1),size(C,3)] ); %reshape so the output is an "image". %Show the prediction image: figure; imagesc(Y_); colorbar colormap gray %export the model as a Studio compliant CCI-model: B0=[B0 B0 B0]; B = repmat(B',[3,1]); K = [1 1 1]; D = [0 0 0]; XMeanCenter = repmat(XMeanCenter,[3,1]); name='ibuprofen_SimPLS'; autoscale=0; SaveCCIModel(B,B0,K,D,XMeanCenter,name,autoscale);
Step 4 - Import and apply the model in Studio
To load and to apply user designed models, the CCI-Design method can get used.
Switch to CCI-Design in Perception Studios Model perspective.
Import the Matlab model by a click on the button right to the Preset combo box.
The model is imported and applied to the hyperspectral cube selected.
E.g. click on Save Model button to get the model available e.g. for real-time processing.
© 2018 2019 by Perception Park GmbH
The content of this page and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact Perception Park and delete copied material. Perception Park GmbH, Nikolaiplatz 4 / 3Wartingergasse 42, A-8020 8010 Graz; Austria; FN 400381x