Main component transformation PIE SDK

1. Introduction Algorithms

     Principal component (Principal Component Analysis, PCA), also known as KL (Karhunen-Loeve) transform or the Hotelling (the Hotelling) transform, the relationship between the variables is based on the transform of a linear information as possible without losing the premise The method, used primarily for data compression and information enhancement.

  Main component forward transform, KL transform general sense is correct conversion, the process by the image statistics calculated eigenvalue, principal component configured on the basis of the covariance matrix band. The relationship between the main component and characteristic value may be selected as a small number of principal components output.

  A main component an inverse transform, if the number of the selected main component in the band with the forward transform / variables of the same number, then inverse transform the result will be completely identical to the original image. If the number is less than the number of principal components selected wavelength range corresponds to the inverse transform results suppress noise in images. Number of main component selected by the impact, each "band" inverse conversion result image with the original image bands may no longer have the physical meaning of the original image bands will vary greatly.

  PIESDK provides a positive transform and inverse transform algorithm, only need to set the parameters corresponding to the conditions can be performed, the following describes the use of two algorithms.

2. Implementation Notes arithmetic functions

2.1. Implementation steps

first step

Algorithm parameter settings

The second step

Algorithm execution

third step

The results show

2.2. Algorithm parameters

Algorithm name

Main component transformation n

C # DLL algorithm

PIE.CommonAlgo.dll

C # algorithm name

PIE.CommonAlgo.TransformForwardPCAAlgo

Parameter structure

ForwardPCA_Exchange_Info

Parameter Description

 m_strInputFile

String

Output file

m_strOutputResultFile

String

Output image path

m_strOutputStatsFile

String

Statistics output file

m_strFileTypeCode

String

Output File Type

m_nPCBands

int

Output number of bands

m_nOutDataType

int

Output File Type

0, byte (8 bits);

1, unsigned int (16);

2, shaping (16);

3, unsigned long integer (32-bit);

4, long integer (32-bit);

5, a float (32);

6, double precision floating point (64-bit)

m_eigenvalues

IList<string>

Eigenvalue - Returns

m_bPCBandsFromEigenvalus

bool

PCA band selected according to the characteristic values ​​are sorted

m_bOutputLikeEnvi

bool

Zero mean treatment

m_bCovariance

bool

Statistics using a matrix -true- covariance matrix using the correlation coefficient matrix -false-

m_accumulate_contribute

IList<string>

Percentage - Returns

 

Algorithm name

Principal component inverse transformation

C # DLL algorithm

PIE.CommonAlgo.dll

C # algorithm name

PIE.CommonAlgo.TransformInversePCAAlgo

Parameter structure

InversePCA_Exchange_Info

Parameter Description

 m_m_nOutDataType

int

Output File Type Byte

0, byte (8 bits);

1, unsigned int (16);

2, shaping (16);

3, unsigned long integer (32-bit);

4, long integer (32-bit);

5, a float (32);

6, double precision floating point (64-bit)

m_strFileTypeCode

String

Output File Format

m_strInputPcaFile

String

Enter the PCA results file

m_strInputStatsFile

String

Enter the PCA results of statistical documents

m_strOutputResultFile

String

The output file path

2.3. Sample Code

Project Path

The disc address Baidu Cloud / sample program the PIE / 10. Algorithm calls / image processing / ImageTransform

Data Path

Under Baidu cloud disc address / data sample the PIE / raster data /04.World/World.tif

Video Path

Under Baidu cloud disc address / video tutorials the PIE / 10. Algorithm calls / image processing / principal component .avi

Sample Code

 1 /// <summary>
 2 /// 主成分正变换
 3 /// </summary>
 4 /// <param name="sender"></param>
 5 /// <param name="e"></param>
 6 private void toolStripButton1_Click(object sender, EventArgs e)
 7 {
 8     //1、参数设置
 9     PIE.CommonAlgo.ForwardPCA_Exchange_Info info = new ForwardPCA_Exchange_Info();
10     info.m_strInputFile = @"D:\data\02.测试数据\World\World.tif";
11     info.m_nOutDataType = 5;//float32
12     info.m_strOutputResultFile = @"D:\PCPT.tif";//输出文件
13     info.m_strOutputStatsFile = @"D:\PCPT.pcasta";//输出统计文件
14     info.m_nPCBands = 3;//输出的主成分波段数
15     info.m_strFileTypeCode = "GTiff";//文件格式类型        
16     info.m_bOutputLikeEnvi = true;//零均值处理
17     info.m_bPCBandsFromEigenvalus = false;//是否根据特征值排序PCA波段
18     info.m_bCovariance = false;//统计使用矩阵 true 协方差矩阵 false 使用相关系矩阵  前提是
19 bPCBandsFromEigenvalus为true,设置的才有效
20     //2、创建算法对象
21     ISystemAlgo algo = AlgoFactory.Instance().CreateAlgo("PIE.CommonAlgo.dll", "PIE.CommonAlgo.TransformForwardPCAAlgo");
22     if (algo == null) return;
23     algo.Params = info;
24 
25     //3、执行算法
26     bool result = AlgoFactory.Instance().ExecuteAlgo(algo);
27     if (result != true) return;
28     ILayer layer = LayerFactory.CreateDefaultLayer(info.m_strOutputResultFile);
29     mapControlMain.ActiveView.FocusMap.AddLayer(layer);
30     mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll);         
31 } 
32 
33 
34 /// <summary>
35 /// 主成分逆变换 (对主成分正变换的结果做逆变换,得到正变换之前的影像数据)
36 /// </summary>
37 /// <param name="sender"></param>
38 /// <param name="e"></param>
39 private void toolStripButton2_Click(object sender, EventArgs e)
40 {
41     //1、参数设置
42     PIE.CommonAlgo.InversePCA_Exchange_Info info = new InversePCA_Exchange_Info();
43     info.m_strInputPcaFile = @"D:\PCPT.tif";//输入文件 主成分正变换结果
44     info.m_strInputStatsFile = @"D:\PCPT.pcasta";//pac统计文件
45     info.m_strOutputResultFile = @"D:\InversePC.tif";//逆变换结果
46     info.m_strFileTypeCode = "GTiff";//输出结果
47     info.m_nOutDataType = 5;//float32
48 
49     //2、创建算法对象
50     ISystemAlgo algo = AlgoFactory.Instance().CreateAlgo("PIE.CommonAlgo.dll", "PIE.CommonAlgo.TransformInversePCAAlgo");
51     if (algo == null) return;
52     algo.Params = info;
53 
54     //3、执行算法并加载结果图层
55     bool result = AlgoFactory.Instance().ExecuteAlgo(algo);
56     if (result != true) return;
57     ILayer layer = LayerFactory.CreateDefaultLayer(info.m_strOutputResultFile);
58     mapControlMain.ActiveView.FocusMap.AddLayer(layer);
59     mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll);      
60 }
View Code

2.4. 示例截图

 

图一、主成分正变换

 

图二:主成分逆变换

Guess you like

Origin www.cnblogs.com/PIESat/p/11202621.html