/// <summary> /// 通过欧式距离,使用KS算法选择有效光谱 /// </summary> /// <param name="spectrumYDatas">主机光谱,一行一条Y轴数据</param> /// <param name="specRows">光谱数量</param> /// <param name="specCols">每条光谱的数据点数</param> /// <param name="selectNumber">需要选择多少条光谱</param> /// <returns>选中光谱的序号(int),大小=selectNumber</returns> public static int[] KSEuclideanSelectSample(double[] spectrumYDatas, int specRows, int specCols, int selectNumber) { try { if (spectrumYDatas == null || selectNumber < 1 || specRows < selectNumber || spectrumYDatas.Length != specRows * specCols) { throw new Exception("Invalid parameters"); } IntPtr retptr = IntPtr.Zero; if (CommonMethod.Is64BitVersion()) { retptr = KSEuclideanSelectSample64(spectrumYDatas, specRows, specCols, selectNumber); } else { retptr = KSEuclideanSelectSample32(spectrumYDatas, specRows, specCols, selectNumber); } if (retptr == IntPtr.Zero) { ErrorString = GetErrorMessage(); return(null); } return(CommonMethod.CopyDataArrayFromIntptrAndFree <int>(ref retptr, selectNumber)); } catch (Exception ex) { ErrorString = ex.Message; return(null); } }
/// <summary> /// 从主机光谱中选择用于仪器校准的光谱 /// </summary> /// <param name="masterData">主机光谱,一行一条光谱,第一行是X轴数据,后面是Y轴数据</param> /// <param name="specRows">光谱数量</param> /// <param name="specCols">每条光谱的数据点数</param> /// <param name="selectNumber">需要选择多少条光谱</param> /// <returns>选中光谱的序号(int),大小=selectNumber</returns> public static int[] SelectStandardSpectrum(double[] masterData, int specRows, int specCols, int selectNumber) { try { if (masterData == null || selectNumber < 1 || specRows < selectNumber || masterData.Length != specRows * specCols) { throw new Exception("Invalid parameters"); } IntPtr retptr = IntPtr.Zero; if (CommonMethod.Is64BitVersion()) { retptr = SDSelectStandardSpectrum64(masterData, specRows, specCols, selectNumber); } else { retptr = SDSelectStandardSpectrum32(masterData, specRows, specCols, selectNumber); } if (retptr == IntPtr.Zero) { ErrorString = GetErrorMessage(); return(null); } return(CommonMethod.CopyDataArrayFromIntptrAndFree <int>(ref retptr, selectNumber)); } catch (Exception ex) { ErrorString = ex.Message; return(null); } }
/// <summary> /// 使用光谱校正系数,校正光谱 /// </summary> /// <param name="coefData">光谱校正系数(BYTE)</param> /// <param name="slaveData">光谱数据</param> /// <param name="specRows">光谱的数量</param> /// <param name="specCols">每条光谱数据数量</param> /// <param name="withXDatas">是否包含X轴数据</param> /// <returns>校正后的光谱,与slaveData大小相同</returns> public static double[] ApplyCoefficient(byte[] coefData, double[] slaveData, int specRows, int specCols, bool withXDatas) { try { if (coefData == null || slaveData == null || specRows < 1) { throw new Exception("Invalid parameters"); } if (!IsValidCoef(coefData, specCols)) { throw new Exception("Invalid parameters"); } IntPtr retptr = IntPtr.Zero; if (CommonMethod.Is64BitVersion()) { retptr = SDApplyCoefficient64(coefData, slaveData, specRows, specCols, withXDatas); } else { retptr = SDApplyCoefficient32(coefData, slaveData, specRows, specCols, withXDatas); } if (retptr == IntPtr.Zero) { ErrorString = GetErrorMessage(); return(null); } return(CommonMethod.CopyDataArrayFromIntptrAndFree <double>(ref retptr, specCols * specRows)); } catch (Exception ex) { ErrorString = ex.Message; return(null); } }
/// <summary> /// 根据主机光谱创建辅机的校准系数 /// </summary> /// <param name="algorithmType">校准算法</param> /// <param name="masterData">主机数据(一条光谱一行Y轴数据)</param> /// <param name="slaveData">辅机数据(一条光谱一行Y轴数据)</param> /// <param name="specRows">光谱的行数</param> /// <param name="specCols">每条光谱的数据点数量</param> /// <param name="windowSize">校准窗口大小(PDS), RANK(SST)</param> /// <param name="tolerance">校准偏差(PLS)</param> /// <param name="firstX">起始波数</param> /// <param name="lastX">结束波数</param> /// <param name="withXDatas">是否包含X轴数据</param> /// <returns>校准系数</returns> public static byte[] GetCoefficient(enumAlgorithmType algorithmType, double[] masterData, double[] slaveData, int specRows, int specCols, int windowSize, double tolerance, double firstX, double lastX, bool withXDatas) { if (masterData == null || slaveData == null || specRows < 2 || specCols < windowSize + 1 || windowSize < 1 || masterData.Length != specRows * specCols || masterData.Length != slaveData.Length) { ErrorString = "Invalid Parameters"; return(null); } try { IntPtr retptr = IntPtr.Zero; int datasize = 0; switch (algorithmType) { case enumAlgorithmType.PDS: if (CommonMethod.Is64BitVersion()) { retptr = PDSCoefficient64(masterData, slaveData, specRows, specCols, windowSize, firstX, lastX, withXDatas, ref datasize); } else { retptr = PDSCoefficient32(masterData, slaveData, specRows, specCols, windowSize, firstX, lastX, withXDatas, ref datasize); } break; case enumAlgorithmType.PLS: if (CommonMethod.Is64BitVersion()) { retptr = PLSCoefficient64(masterData, slaveData, specRows, specCols, windowSize, tolerance, firstX, lastX, withXDatas, ref datasize); } else { retptr = PLSCoefficient32(masterData, slaveData, specRows, specCols, windowSize, tolerance, firstX, lastX, withXDatas, ref datasize); } break; case enumAlgorithmType.SST: if (CommonMethod.Is64BitVersion()) { retptr = SSTCoefficient64(masterData, slaveData, specRows, specCols, windowSize, firstX, lastX, withXDatas, ref datasize); } else { retptr = SSTCoefficient32(masterData, slaveData, specRows, specCols, windowSize, firstX, lastX, withXDatas, ref datasize); } break; default: break; } if (retptr == IntPtr.Zero) { ErrorString = GetErrorMessage(); return(null); } return(CommonMethod.CopyDataArrayFromIntptrAndFree <byte>(ref retptr, datasize)); } catch (Exception ex) { ErrorString = ex.Message; return(null); } }