3using System.Collections.Generic;
8using System.Runtime.InteropServices;
9using System.Runtime.Serialization;
24 float[] m_rgReadDataF =
null;
35 m_nChannels = nChannels;
38 m_rgReadDataF = rgData;
46 get {
return m_rgReadDataF; }
47 set { m_rgReadDataF = value; }
57 return m_rgReadDataF.Length;
66 get {
return m_nChannels; }
74 get {
return m_nWidth; }
82 get {
return m_nHeight; }
92 List<SimpleTemporalDatum> m_rgItems;
99 m_rgItems =
new List<SimpleTemporalDatum>(nCapacity);
114 if (rgData ==
null && sd.
RealDataD !=
null)
117 for (
int i = 0; i < rgData.Length; i++)
134 get {
return m_rgItems.Count; }
144 get {
return m_rgItems[nIdx]; }
163 int m_nOriginalLabel = 0;
168 byte[] m_rgByteData =
null;
169 float[] m_rgRealDataF =
null;
170 double[] m_rgRealDataD =
null;
171 bool m_bIsRealData =
false;
172 DateTime m_dt = DateTime.MinValue;
173 int m_nOriginalBoost = 0;
175 bool m_bAutoLabeled =
false;
177 int m_nVirtualID = 0;
179 byte[] m_rgDataCriteria =
null;
181 byte[] m_rgDebugData =
null;
183 string m_strDesc =
null;
185 int m_nOriginalSourceID = 0;
301 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel = -1, DateTime? dtTime =
null,
int nBoost = 0,
bool bAutoLabeled =
false,
int nIdx = -1,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
303 m_nChannels = nChannels;
306 m_nOriginalLabel = nLabel;
308 m_dt = dtTime.GetValueOrDefault(DateTime.MinValue);
309 m_nOriginalBoost = nBoost;
311 m_bAutoLabeled = bAutoLabeled;
312 m_nVirtualID = nVirtualID;
313 m_bIsRealData = bIsReal;
315 m_nImageID = nImageID;
316 m_nSourceID = nSourceID;
317 m_nOriginalSourceID = nOriginalSourceID;
337 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime, List<byte> rgData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
339 m_nChannels = nChannels;
342 m_nOriginalLabel = nLabel;
345 m_nOriginalBoost = nBoost;
347 m_bAutoLabeled = bAutoLabeled;
348 m_nVirtualID = nVirtualID;
349 m_bIsRealData = bIsReal;
351 m_nImageID = nImageID;
352 m_nSourceID = nSourceID;
353 m_nOriginalSourceID = nOriginalSourceID;
356 throw new ArgumentException(
"The data sent is not real, but the bIsReal is set to true!");
358 m_rgByteData = rgData.ToArray();
378 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime, List<double> rgfData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
380 m_nChannels = nChannels;
383 m_nOriginalLabel = nLabel;
386 m_nOriginalBoost = nBoost;
388 m_bAutoLabeled = bAutoLabeled;
389 m_nVirtualID = nVirtualID;
390 m_bIsRealData = bIsReal;
392 m_nImageID = nImageID;
393 m_nSourceID = nSourceID;
394 m_nOriginalSourceID = nOriginalSourceID;
397 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
399 m_rgRealDataD = rgfData.ToArray();
419 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime, List<float> rgfData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
421 m_nChannels = nChannels;
424 m_nOriginalLabel = nLabel;
427 m_nOriginalBoost = nBoost;
429 m_bAutoLabeled = bAutoLabeled;
430 m_nVirtualID = nVirtualID;
431 m_bIsRealData = bIsReal;
433 m_nImageID = nImageID;
434 m_nSourceID = nSourceID;
435 m_nOriginalSourceID = nOriginalSourceID;
438 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
440 m_rgRealDataF = rgfData.ToArray();
460 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime,
byte[] rgData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
462 m_nChannels = nChannels;
465 m_nOriginalLabel = nLabel;
468 m_nOriginalBoost = nBoost;
470 m_bAutoLabeled = bAutoLabeled;
471 m_nVirtualID = nVirtualID;
472 m_bIsRealData = bIsReal;
474 m_nImageID = nImageID;
475 m_nSourceID = nSourceID;
476 m_nOriginalSourceID = nOriginalSourceID;
479 throw new ArgumentException(
"The data sent is not real, but the bIsReal is set to true!");
481 m_rgByteData = rgData;
501 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime,
double[] rgdfData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
503 m_nChannels = nChannels;
506 m_nOriginalLabel = nLabel;
509 m_nOriginalBoost = nBoost;
511 m_bAutoLabeled = bAutoLabeled;
512 m_nVirtualID = nVirtualID;
513 m_bIsRealData = bIsReal;
515 m_nImageID = nImageID;
516 m_nSourceID = nSourceID;
517 m_nOriginalSourceID = nOriginalSourceID;
520 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
522 m_rgRealDataD = rgdfData;
542 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime,
float[] rgfData,
int nBoost,
bool bAutoLabeled,
int nIdx,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
544 m_nChannels = nChannels;
547 m_nOriginalLabel = nLabel;
550 m_nOriginalBoost = nBoost;
552 m_bAutoLabeled = bAutoLabeled;
553 m_nVirtualID = nVirtualID;
554 m_bIsRealData = bIsReal;
556 m_nImageID = nImageID;
557 m_nSourceID = nSourceID;
558 m_nOriginalSourceID = nOriginalSourceID;
561 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
563 m_rgRealDataF = rgfData;
582 public SimpleDatum(
bool bIsReal,
int nChannels,
int nWidth,
int nHeight,
int nLabel, DateTime dtTime,
int nBoost = 0,
bool bAutoLabeled =
false,
int nIdx = -1,
int nVirtualID = 0,
int nImageID = 0,
int nSourceID = 0,
int nOriginalSourceID = 0)
584 m_nChannels = nChannels;
587 m_nOriginalLabel = nLabel;
590 m_nOriginalBoost = nBoost;
592 m_bAutoLabeled = bAutoLabeled;
593 m_nVirtualID = nVirtualID;
594 m_bIsRealData = bIsReal;
596 m_nImageID = nImageID;
597 m_nSourceID = nSourceID;
598 m_nOriginalSourceID = nOriginalSourceID;
600 m_rgRealDataD =
null;
601 m_rgRealDataF =
null;
614 public SimpleDatum(
int nChannels,
int nWidth,
int nHeight,
float[] rgf,
int nOffset,
int nCount,
bool bDataIsReal =
true)
616 m_nChannels = nChannels;
619 m_nOriginalLabel = 0;
620 m_nOriginalBoost = 0;
621 m_dt = DateTime.MinValue;
622 m_bAutoLabeled =
false;
627 m_nOriginalSourceID = 0;
630 int nLen = nChannels * nWidth * nHeight;
632 throw new Exception(
"The channel x width x height should equal the count!");
636 m_bIsRealData =
true;
637 m_rgRealDataF =
new float[nCount];
640 Array.Copy(rgf, nOffset, m_rgRealDataF, 0, nCount);
644 m_bIsRealData =
false;
645 m_rgByteData =
new byte[nCount];
647 for (
int i = 0; i < nCount; i++)
649 m_rgByteData[i] = Math.Min(Math.Max((
byte)rgf[nOffset + i], (
byte)0), (
byte)255);
662 m_nChannels = nChannels;
665 m_nOriginalLabel = 0;
666 m_nOriginalBoost = 0;
667 m_dt = DateTime.MinValue;
668 m_bAutoLabeled =
false;
673 m_nOriginalSourceID = 0;
684 m_nWidth = data.
Width;
686 m_nOriginalLabel = -1;
688 m_bIsRealData =
false;
690 m_rgByteData = data.
Bytes;
700 m_nWidth = data.
Width;
702 m_nOriginalLabel = -1;
704 m_bIsRealData =
true;
706 m_rgRealDataD = data.
Values;
727 Copy(d,
false, nHeight, nWidth);
757 m_nChannels *= rg.Count;
761 if (m_nChannels != rg.Count)
762 throw new Exception(
"Currently channel alignment is only allowed on single channel data.");
770 double[] rgData =
new double[m_nChannels *
Height *
Width];
772 for (
int h = 0; h <
Height; h++)
774 for (
int w = 0; w <
Width; w++)
776 int nIdxSrc = (h *
Width) + w;
777 int nIdxDst = nIdxSrc * m_nChannels;
779 for (
int c = 0; c < m_nChannels; c++)
781 rgData[nIdxDst + c] = rg[c].RealDataD[nIdxSrc];
786 m_rgRealDataD = rgData;
790 float[] rgData =
new float[m_nChannels *
Height *
Width];
792 for (
int h = 0; h <
Height; h++)
794 for (
int w = 0; w <
Width; w++)
796 int nIdxSrc = (h *
Width) + w;
797 int nIdxDst = nIdxSrc * m_nChannels;
799 for (
int c = 0; c < m_nChannels; c++)
801 rgData[nIdxDst + c] = rg[c].RealDataF[nIdxSrc];
806 m_rgRealDataF = rgData;
810 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
816 byte[] rgData =
new byte[m_nChannels *
Height *
Width];
818 for (
int h = 0; h <
Height; h++)
820 for (
int w = 0; w <
Width; w++)
822 int nIdxSrc = (h *
Width) + w;
823 int nIdxDst = nIdxSrc * m_nChannels;
825 for (
int c = 0; c < m_nChannels; c++)
827 rgData[nIdxDst + c] = rg[c].ByteData[nIdxSrc];
832 m_rgByteData = rgData;
833 m_rgRealDataF =
null;
834 m_rgRealDataD =
null;
840 bool bReal = rg[0].IsRealData;
842 int nItemCount = m_nChannels / rg.Count;
848 m_rgRealDataD =
new double[m_nChannels *
Height *
Width];
851 for (
int i = 0; i < rg.Count; i++)
853 Array.Copy(rg[i].
RealDataD, 0, m_rgRealDataD, nDstIdx, nItemCount);
854 nDstIdx += nItemCount;
859 m_rgRealDataF =
new float[m_nChannels *
Height *
Width];
862 for (
int i = 0; i < rg.Count; i++)
864 Array.Copy(rg[i].
RealDataF, 0, m_rgRealDataF, nDstIdx, nItemCount);
865 nDstIdx += nItemCount;
870 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
875 m_rgByteData =
new byte[m_nChannels *
Height *
Width];
876 m_rgRealDataD =
null;
877 m_rgRealDataF =
null;
879 for (
int i = 0; i < rg.Count; i++)
881 Array.Copy(rg[i].
ByteData, 0, m_rgByteData, nDstIdx, nItemCount);
882 nDstIdx += nItemCount;
893 get {
return m_nHitCount; }
894 set { m_nHitCount = value; }
902 get {
return m_tag; }
903 set {
m_tag = value; }
924 if (m_rgRealDataD !=
null)
925 return m_rgRealDataD.Min(p => p);
926 else if (m_rgRealDataF !=
null)
927 return m_rgRealDataF.Min(p => p);
929 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
933 if (m_rgByteData !=
null)
934 return (
double)m_rgByteData.Min(p => p);
950 if (m_rgRealDataD !=
null)
951 return m_rgRealDataD.Max(p => p);
952 else if (m_rgRealDataF !=
null)
953 return m_rgRealDataF.Max(p => p);
955 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
959 if (m_rgByteData !=
null)
960 return (
double)m_rgByteData.Max(p => p);
974 public void Clip(
int nDataLen,
int? nNewChannel,
int? nNewHeight,
int? nNewWidth)
976 if (m_rgByteData !=
null && m_rgByteData.Length > nDataLen)
978 byte[] rgData =
new byte[nDataLen];
979 Array.Copy(m_rgByteData, rgData, nDataLen);
980 m_rgByteData = rgData;
982 if (m_rgRealDataD !=
null && m_rgRealDataD.Length > nDataLen)
984 double[] rgData =
new double[nDataLen];
985 Array.Copy(m_rgRealDataD, rgData, nDataLen);
986 m_rgRealDataD = rgData;
988 if (m_rgRealDataF !=
null && m_rgRealDataF.Length > nDataLen)
990 float[] rgData =
new float[nDataLen];
991 Array.Copy(m_rgRealDataF, rgData, nDataLen);
992 m_rgRealDataF = rgData;
995 m_nChannels = nNewChannel.GetValueOrDefault(m_nChannels);
996 m_nHeight = nNewHeight.GetValueOrDefault(m_nHeight);
997 m_nWidth = nNewWidth.GetValueOrDefault(m_nWidth);
1006 List<int> rgIdx =
new List<int>();
1010 if (m_rgRealDataD !=
null)
1012 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1014 if (m_rgRealDataD[i] != 0)
1018 else if (m_rgRealDataF !=
null)
1020 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1022 if (m_rgRealDataF[i] != 0)
1028 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1033 for (
int i = 0; i < m_rgByteData.Length; i++)
1035 if (m_rgByteData[i] != 0)
1048 if (m_rgByteData !=
null)
1049 Array.Clear(m_rgByteData, 0, m_rgByteData.Length);
1051 if (m_rgRealDataD !=
null)
1052 Array.Clear(m_rgRealDataD, 0, m_rgRealDataD.Length);
1054 if (m_rgRealDataF !=
null)
1055 Array.Clear(m_rgRealDataF, 0, m_rgRealDataF.Length);
1066 bool bDifferent =
false;
1069 throw new Exception(
"Both simple datums must have the same number of elements!");
1071 if (m_rgByteData !=
null)
1073 for (
int i = 0; i < m_rgByteData.Length; i++)
1077 if (sd.m_rgByteData !=
null)
1078 nVal = m_rgByteData[i] - sd.m_rgByteData[i];
1079 else if (sd.m_rgRealDataD !=
null)
1080 nVal = (int)m_rgByteData[i] - (
int)sd.m_rgRealDataD[i];
1081 else if (sd.m_rgRealDataF !=
null)
1082 nVal = (int)m_rgByteData[i] - (
int)sd.m_rgRealDataF[i];
1088 if (bSetNegativeToZero && nVal < 0)
1092 m_rgByteData[i] = (byte)nVal;
1096 if (m_rgRealDataD !=
null)
1098 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1100 if (sd.m_rgRealDataD !=
null)
1101 m_rgRealDataD[i] -= sd.m_rgRealDataD[i];
1102 else if (sd.m_rgRealDataF !=
null)
1103 m_rgRealDataD[i] -= sd.m_rgRealDataF[i];
1104 else if (sd.m_rgByteData !=
null)
1105 m_rgRealDataD[i] -= sd.m_rgByteData[i];
1107 if (m_rgRealDataD[i] != 0)
1111 if (bSetNegativeToZero && m_rgRealDataD[i] < 0)
1112 m_rgRealDataD[i] = 0;
1117 if (m_rgRealDataF !=
null)
1119 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1121 if (sd.m_rgRealDataD !=
null)
1122 m_rgRealDataF[i] -= (float)sd.m_rgRealDataD[i];
1123 else if (sd.m_rgRealDataF !=
null)
1124 m_rgRealDataF[i] -= sd.m_rgRealDataF[i];
1125 else if (sd.m_rgByteData !=
null)
1126 m_rgRealDataF[i] -= sd.m_rgByteData[i];
1128 if (m_rgRealDataF[i] != 0)
1132 if (bSetNegativeToZero && m_rgRealDataF[i] < 0)
1133 m_rgRealDataF[i] = 0;
1148 bool bDifferent =
false;
1151 throw new Exception(
"Both simple datums must have the same number of elements!");
1153 if (m_rgByteData !=
null)
1155 if (sd.m_rgByteData ==
null)
1156 throw new Exception(
"Both simple datums must have the same type of data!");
1158 for (
int i = 0; i < m_rgByteData.Length; i++)
1160 m_rgByteData[i] = (byte)Math.Abs(m_rgByteData[i] - sd.m_rgByteData[i]);
1161 if (m_rgByteData[i] != 0)
1166 if (m_rgRealDataD !=
null)
1168 if (sd.m_rgRealDataD ==
null)
1169 throw new Exception(
"Both simple datums must have the same type of data!");
1171 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1173 m_rgRealDataD[i] = Math.Abs(m_rgRealDataD[i] - sd.m_rgRealDataD[i]);
1174 if (m_rgRealDataD[i] != 0)
1179 if (m_rgRealDataF !=
null)
1181 if (sd.m_rgRealDataF ==
null)
1182 throw new Exception(
"Both simple datums must have the same type of data!");
1184 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1186 m_rgRealDataF[i] = Math.Abs(m_rgRealDataF[i] - sd.m_rgRealDataF[i]);
1187 if (m_rgRealDataF[i] != 0)
1201 public void Scale(
double dfScale,
double dfMin = -
double.MaxValue,
double dfMax =
double.MaxValue)
1203 if (m_rgByteData !=
null)
1205 for (
int i = 0; i < m_rgByteData.Length; i++)
1207 int nVal = (int)(m_rgByteData[i] * dfScale);
1208 if (nVal < (
int)dfMin)
1210 else if (nVal > (
int)dfMax)
1212 m_rgByteData[i] = (byte)nVal;
1216 if (m_rgRealDataD !=
null)
1218 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1220 m_rgRealDataD[i] *= dfScale;
1221 if (m_rgRealDataD[i] < dfMin)
1222 m_rgRealDataD[i] = dfMin;
1223 else if (m_rgRealDataD[i] > dfMax)
1224 m_rgRealDataD[i] = dfMax;
1228 if (m_rgRealDataF !=
null)
1230 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1232 m_rgRealDataF[i] *= (float)dfScale;
1233 if (m_rgRealDataF[i] < dfMin)
1234 m_rgRealDataF[i] = (float)dfMin;
1235 else if (m_rgRealDataF[i] > dfMax)
1236 m_rgRealDataF[i] = (float)dfMax;
1247 public void ScalePow(
double dfScalePow,
double dfMin = -
double.MaxValue,
double dfMax =
double.MaxValue)
1249 if (m_rgByteData !=
null)
1251 for (
int i = 0; i < m_rgByteData.Length; i++)
1253 int nVal = (int)((
double)Math.Pow(m_rgByteData[i], dfScalePow));
1254 if (nVal < (
int)dfMin)
1256 else if (nVal > (
int)dfMax)
1258 m_rgByteData[i] = (byte)nVal;
1262 if (m_rgRealDataD !=
null)
1264 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1266 m_rgRealDataD[i] = Math.Pow(m_rgRealDataD[i], dfScalePow);
1267 if (m_rgRealDataD[i] < dfMin)
1268 m_rgRealDataD[i] = dfMin;
1269 else if (m_rgRealDataD[i] > dfMax)
1270 m_rgRealDataD[i] = dfMax;
1274 if (m_rgRealDataF !=
null)
1276 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1278 m_rgRealDataF[i] = (float)(Math.Pow(m_rgRealDataF[i], dfScalePow));
1279 if (m_rgRealDataF[i] < dfMin)
1280 m_rgRealDataF[i] = (float)dfMin;
1281 else if (m_rgRealDataF[i] > dfMax)
1282 m_rgRealDataF[i] = (float)dfMax;
1296 m_bIsRealData = d.m_bIsRealData;
1297 m_nLabel = d.m_nLabel;
1298 m_nOriginalLabel = d.m_nOriginalLabel;
1299 m_nChannels = d.m_nChannels;
1300 m_nHeight = nHeight.GetValueOrDefault(d.m_nHeight);
1301 m_nWidth = nWidth.GetValueOrDefault(d.m_nWidth);
1305 m_rgRealDataD =
Utility.Clone<
double>(d.m_rgRealDataD);
1306 m_rgRealDataF =
Utility.Clone<
float>(d.m_rgRealDataF);
1307 m_rgByteData =
Utility.Clone<
byte>(d.m_rgByteData);
1311 m_rgRealDataD = d.m_rgRealDataD;
1312 m_rgRealDataF = d.m_rgRealDataF;
1313 m_rgByteData = d.m_rgByteData;
1317 m_nOriginalBoost = d.m_nOriginalBoost;
1318 m_nBoost = d.m_nBoost;
1319 m_bAutoLabeled = d.m_bAutoLabeled;
1320 m_nImageID = d.m_nImageID;
1321 m_nVirtualID = d.m_nVirtualID;
1322 m_nGroupID = d.m_nGroupID;
1323 m_nIndex = d.m_nIndex;
1324 m_strDesc = d.m_strDesc;
1325 m_rgDataCriteria = d.m_rgDataCriteria;
1326 m_dataCriteriaFormat = d.m_dataCriteriaFormat;
1327 m_rgDebugData = d.m_rgDebugData;
1328 m_debugDataFormat = d.m_debugDataFormat;
1329 m_nSourceID = d.m_nSourceID;
1330 m_nOriginalSourceID = d.m_nOriginalSourceID;
1334 m_nAnnotationType = d.m_nAnnotationType;
1335 m_rgAnnotationGroup =
null;
1337 if (d.m_rgAnnotationGroup !=
null)
1343 m_rgAnnotationGroup.
Add(g.
Clone());
1354 m_nHeight = d.m_nHeight;
1355 m_nWidth = d.m_nWidth;
1356 m_nChannels = d.m_nChannels;
1357 m_rgByteData = d.m_rgByteData;
1358 m_bIsRealData = d.m_bIsRealData;
1359 m_rgRealDataD = d.m_rgRealDataD;
1360 m_rgRealDataF = d.m_rgRealDataF;
1376 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1390 if (m_bIsRealData && m_rgRealDataD ==
null && m_rgRealDataF ==
null)
1392 else if (!m_bIsRealData && m_rgByteData ==
null)
1398 if (m_rgRealDataD ==
null && m_rgRealDataF ==
null && m_rgByteData ==
null)
1412 int nC = m_nChannels;
1415 int nXStart = nW - nLastColumns;
1416 List<T> rg =
new List<T>();
1421 for (
int c = 0; c < nC; c++)
1423 for (
int y = 0; y < nH; y++)
1425 for (
int x = nXStart; x < nW; x++)
1427 int nIdxImg = (c * (nH * nW)) + (y * nW) + x;
1428 rg.Add((T)Convert.ChangeType(
ByteData[nIdxImg], typeof(T)));
1443 if (nLastColumsToRetain <= 0 || nLastColumsToRetain >= m_nWidth)
1446 int nC = m_nChannels;
1449 int nMaskWid = nW - nLastColumsToRetain;
1451 for (
int c = 0; c < nC; c++)
1453 for (
int y = 0; y < nH; y++)
1455 for (
int x = 0; x < nMaskWid; x++)
1457 int nIdxImg = (c * (nH * nW)) + (y * nW) + x;
1458 ByteData[nIdxImg] = (byte)nMaskingValue;
1470 public void SetData(List<byte> rgByteData,
int nLabel,
bool bAllowVirtualOverride =
false)
1472 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1473 throw new Exception(
"Cannot set the data of a virtual item!");
1476 m_bIsRealData =
false;
1477 m_rgByteData = rgByteData.ToArray();
1478 m_rgRealDataD =
null;
1479 m_rgRealDataF =
null;
1489 public void SetData(List<double> rgRealData,
int nLabel,
bool bAllowVirtualOverride =
false)
1491 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1492 throw new Exception(
"Cannot set the data of a virtual item!");
1495 m_bIsRealData =
true;
1496 m_rgByteData =
null;
1497 m_rgRealDataF =
null;
1498 m_rgRealDataD = rgRealData.ToArray();
1508 public void SetData(List<float> rgRealData,
int nLabel,
bool bAllowVirtualOverride =
false)
1510 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1511 throw new Exception(
"Cannot set the data of a virtual item!");
1514 m_bIsRealData =
true;
1515 m_rgByteData =
null;
1516 m_rgRealDataD =
null;
1517 m_rgRealDataF = rgRealData.ToArray();
1532 m_rgByteData =
new byte[rgb.Length];
1533 Array.Copy(rgb, m_rgByteData, rgb.Length);
1534 m_bIsRealData =
false;
1535 m_rgRealDataD =
null;
1536 m_rgRealDataF =
null;
1550 m_rgRealDataF =
null;
1551 m_rgRealDataD =
new double[rgdf.Length];
1552 Array.Copy(rgdf, m_rgRealDataD, rgdf.Length);
1553 m_rgByteData =
null;
1554 m_bIsRealData =
true;
1568 m_rgRealDataD =
null;
1569 m_rgRealDataF =
new float[rgf.Length];
1570 Array.Copy(rgf, m_rgRealDataF, rgf.Length);
1571 m_rgByteData =
null;
1572 m_bIsRealData =
true;
1589 m_nLabel = m_nOriginalLabel;
1601 if (m_rgRealDataD !=
null)
1602 return m_rgRealDataD.Length;
1603 else if (m_rgRealDataF !=
null)
1604 return m_rgRealDataF.Length;
1606 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1609 return m_rgByteData.Length;
1620 if (m_rgRealDataD !=
null && m_rgRealDataD.Length > 0)
1623 if (m_rgRealDataF !=
null && m_rgRealDataF.Length > 0)
1640 if (m_rgRealDataD !=
null)
1641 return (T)Convert.ChangeType(m_rgRealDataD[nIdx], typeof(T));
1642 else if (m_rgRealDataF !=
null)
1643 return (T)Convert.ChangeType(m_rgRealDataF[nIdx], typeof(T));
1645 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1649 return (T)Convert.ChangeType(m_rgByteData[nIdx], typeof(T));
1662 if (m_rgRealDataD !=
null)
1663 return m_rgRealDataD[nIdx];
1664 else if (m_rgRealDataF !=
null)
1665 return m_rgRealDataF[nIdx];
1667 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1671 return m_rgByteData[nIdx];
1684 if (m_rgRealDataD !=
null)
1685 return (
float)m_rgRealDataD[nIdx];
1686 else if (m_rgRealDataF !=
null)
1687 return m_rgRealDataF[nIdx];
1689 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1693 return m_rgByteData[nIdx];
1708 if (m_rgRealDataD !=
null)
1709 dfVal = m_rgRealDataD[nIdx];
1710 else if (m_rgRealDataF !=
null)
1711 dfVal = m_rgRealDataF[nIdx];
1713 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1715 return (
byte)Math.Min(Math.Max(0, dfVal), 255);
1719 return m_rgByteData[nIdx];
1734 if (m_rgRealDataD !=
null)
1736 if (m_rgRealDataD.Length == 0)
1739 if (typeof(T) == typeof(
double))
1740 return (T[])Convert.ChangeType(m_rgRealDataD.ToArray(), typeof(T[]));
1742 T[] rg =
new T[m_rgRealDataD.Length];
1743 for (
int i = 0; i < rg.Length; i++)
1745 rg[i] = (T)Convert.ChangeType(m_rgRealDataD[i], typeof(T));
1750 else if (m_rgRealDataF !=
null)
1752 if (m_rgRealDataF.Length == 0)
1755 if (typeof(T) == typeof(
float))
1756 return (T[])Convert.ChangeType(m_rgRealDataF.ToArray(), typeof(T[]));
1758 T[] rg =
new T[m_rgRealDataF.Length];
1759 for (
int i = 0; i < rg.Length; i++)
1761 rg[i] = (T)Convert.ChangeType(m_rgRealDataF[i], typeof(T));
1773 if (m_rgByteData ==
null || m_rgByteData.Length == 0)
1776 T[] rg =
new T[m_rgByteData.Length];
1778 for (
int i = 0; i < rg.Length; i++)
1780 rg[i] = (T)Convert.ChangeType(m_rgByteData[i], typeof(T));
1797 public static byte[]
GetByteData(
byte[] rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1799 if (nImagePadX == 0 && nImagePadY == 0)
1802 return PadData<byte>(
new List<byte>(rgData), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1815 public static Tuple<double[], float[]>
GetRealData(
byte[] rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1817 Tuple<double[], float[]> rgRealData =
GetRealData(rgData);
1819 double[] rgRealDataD = rgRealData.Item1;
1820 float[] rgRealDataF = rgRealData.Item2;
1822 if (rgRealDataD !=
null)
1823 rgRealDataD = PadData<double>(rgRealDataD.ToList(), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1825 rgRealDataF = PadData<float>(rgRealDataF.ToList(), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1827 return new Tuple<double[], float[]>(rgRealDataD, rgRealDataF);
1841 public static T[]
PadData<T>(List<T> rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1844 int nCount = nChannels * (nHeight * (nImagePadX + nWidth) + (nImagePadY * nImagePadX));
1845 T[] rgDataNew =
new T[nCount];
1847 for (
int c = 0; c < nChannels; c++)
1849 for (
int y = 0; y < nHeight; y++)
1851 for (
int i = 0; i < nImagePadX; i++)
1853 rgDataNew[nDstIdx] = (T)Convert.ChangeType(0.0, typeof(T));
1857 for (
int x = 0; x < nWidth; x++)
1859 int nIdx = (c * nWidth * nHeight) + (y * nWidth) + x;
1861 rgDataNew[nDstIdx] = rgData[nIdx];
1866 for (
int i = 0; i < nImagePadY; i++)
1868 for (
int x = 0; x < nWidth + nImagePadX; x++)
1870 rgDataNew[nDstIdx] = (T)Convert.ChangeType(0.0, typeof(T));
1894 if (m_rgRealDataD !=
null)
1895 return GetByteData(
new List<double>(m_rgRealDataD));
1896 else if (m_rgRealDataF !=
null)
1897 return GetByteData(
new List<float>(m_rgRealDataF));
1899 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1912 int nCount = rgData.Count;
1913 int nSize =
sizeof(double);
1916 int nDataCount =
sizeof(int) +
sizeof(
int) + (nSize * rgData.Count);
1917 byte[] rgByte =
new byte[nDataCount];
1919 byte[] rg = BitConverter.GetBytes(nCount);
1920 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1921 nOffset += rg.Length;
1923 rg = BitConverter.GetBytes(nSize);
1924 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1925 nOffset += rg.Length;
1927 foreach (
double df
in rgData)
1929 rg = BitConverter.GetBytes(df);
1930 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1931 nOffset += rg.Length;
1947 int nCount = rgData.Count;
1948 int nSize =
sizeof(float);
1951 int nDataCount =
sizeof(int) +
sizeof(
int) + (nSize * rgData.Count);
1952 byte[] rgByte =
new byte[nDataCount];
1954 byte[] rg = BitConverter.GetBytes(nCount);
1955 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1956 nOffset += rg.Length;
1958 rg = BitConverter.GetBytes(nSize);
1959 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1960 nOffset += rg.Length;
1962 foreach (
float df
in rgData)
1964 rg = BitConverter.GetBytes(df);
1965 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1966 nOffset += rg.Length;
1979 double[] rgDataD =
null;
1980 float[] rgDataF =
null;
1983 int nCount = BitConverter.ToInt32(rgData, nIdx);
1985 int nSize = BitConverter.ToInt32(rgData, nIdx);
1989 if (nSize !=
sizeof(
float) && nSize !=
sizeof(
double))
1992 nSize =
sizeof(double);
1995 if (nSize ==
sizeof(
double))
2000 return new Tuple<double[], float[]>(rgDataD, rgDataF);
2011 List<double> rgData0 =
new List<double>();
2013 while (nIdx < rgData.Length)
2015 rgData0.Add(BitConverter.ToDouble(rgData, nIdx));
2019 return rgData0.ToArray();
2030 List<float> rgData0 =
new List<float>();
2032 while (nIdx < rgData.Length)
2034 rgData0.Add(BitConverter.ToSingle(rgData, nIdx));
2038 return rgData0.ToArray();
2050 m_nWidth != d.
Width)
2051 throw new Exception(
"Datum dimmensions do not match!");
2054 throw new Exception(
"Datum counts do not match!");
2058 d1.m_rgRealDataD =
null;
2059 d1.m_rgRealDataF =
null;
2060 d1.m_rgByteData =
null;
2064 if (m_rgRealDataD !=
null)
2066 d1.m_rgRealDataD =
new double[m_rgRealDataD.Length];
2068 for (
int i = 0; i < m_rgRealDataD.Length; i++)
2070 d1.m_rgRealDataD[i] = m_rgRealDataD[i] + d.
GetDataAtD(i);
2073 else if (m_rgRealDataF !=
null)
2075 d1.m_rgRealDataF =
new float[m_rgRealDataF.Length];
2077 for (
int i = 0; i < m_rgRealDataF.Length; i++)
2079 d1.m_rgRealDataF[i] = m_rgRealDataF[i] + d.
GetDataAtF(i);
2084 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2087 d1.m_bIsRealData =
true;
2091 d1.m_rgByteData =
new byte[m_rgByteData.Length];
2092 d1.m_bIsRealData =
false;
2094 for (
int i = 0; i < m_rgByteData.Length; i++)
2097 d1.m_rgByteData[i] = (byte)Math.Min(Math.Max(0, nVal), 255);
2113 throw new ArgumentOutOfRangeException(
"dfVal", 0,
"Cannot divide the simple datums by zero!");
2117 d1.m_rgRealDataD =
null;
2118 d1.m_rgRealDataF =
null;
2119 d1.m_rgByteData =
null;
2123 if (m_bIsRealData && !bConvertToByte)
2125 if (m_rgRealDataD !=
null)
2127 d1.m_rgRealDataD =
new double[nCount];
2128 d1.m_bIsRealData =
true;
2130 for (
int i = 0; i < nCount; i++)
2132 d1.m_rgRealDataD[i] = m_rgRealDataD[i] / dfVal;
2135 else if (m_rgRealDataF !=
null)
2137 d1.m_rgRealDataF =
new float[nCount];
2138 d1.m_bIsRealData =
true;
2140 for (
int i = 0; i < nCount; i++)
2142 d1.m_rgRealDataF[i] = (float)(m_rgRealDataF[i] / dfVal);
2147 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2150 else if (m_bIsRealData && bConvertToByte)
2152 d1.m_rgByteData =
new byte[nCount];
2153 d1.m_bIsRealData =
false;
2155 if (m_rgRealDataD !=
null)
2157 for (
int i = 0; i < nCount; i++)
2159 double dfVal1 = m_rgRealDataD[i] / dfVal;
2160 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2163 else if (m_rgRealDataF !=
null)
2165 for (
int i = 0; i < nCount; i++)
2167 double dfVal1 = m_rgRealDataF[i] / dfVal;
2168 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2173 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2178 d1.m_rgByteData =
new byte[nCount];
2179 d1.m_bIsRealData =
false;
2181 for (
int i = 0; i < nCount; i++)
2183 double dfVal1 = (double)m_rgByteData[i] / dfVal;
2184 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2196 get {
return m_nSourceID; }
2204 get {
return m_nOriginalSourceID; }
2212 get {
return m_nImageID; }
2229 get {
return m_nVirtualID; }
2237 get {
return m_nGroupID; }
2238 set { m_nGroupID = value; }
2246 get {
return m_nIndex; }
2247 set { m_nIndex = value; }
2255 get {
return m_dt; }
2256 set { m_dt = value; }
2264 get {
return m_bAutoLabeled; }
2265 set { m_bAutoLabeled = value; }
2273 get {
return m_bIsRealData; }
2281 get {
return m_nHeight; }
2289 get {
return m_nWidth; }
2297 get {
return m_nChannels; }
2305 get {
return m_nLabel; }
2313 get {
return m_nOriginalLabel; }
2314 set { m_nOriginalLabel = value; }
2322 get {
return m_rgByteData; }
2330 get {
return m_rgRealDataD; }
2338 get {
return m_rgRealDataF; }
2346 get {
return m_nBoost; }
2347 set { m_nBoost = value; }
2355 m_nBoost = m_nOriginalBoost;
2363 get {
return m_dataCriteriaFormat; }
2364 set { m_dataCriteriaFormat = value; }
2372 get {
return m_rgDataCriteria; }
2373 set { m_rgDataCriteria = value; }
2381 get {
return m_debugDataFormat; }
2382 set { m_debugDataFormat = value; }
2390 get {
return m_rgDebugData; }
2391 set { m_rgDebugData = value; }
2399 get {
return m_strDesc; }
2400 set { m_strDesc = value; }
2409 get {
return m_nAnnotationType; }
2410 set { m_nAnnotationType = value; }
2418 get {
return m_rgAnnotationGroup; }
2419 set { m_rgAnnotationGroup = value; }
2446 string strOut =
"Idx = " + m_nIndex.ToString(
"N0");
2448 strOut +=
"; Label = " + m_nLabel.ToString();
2449 strOut +=
"; Boost = " + m_nBoost.ToString();
2451 if (m_dt != DateTime.MinValue)
2452 strOut +=
"; Time = " + m_dt.ToString();
2454 if (!
string.IsNullOrEmpty(m_strDesc))
2455 strOut +=
"; Desc = " + m_strDesc;
2471 if (m_rgRealDataD !=
null)
2473 for (
int i = 0; i < m_rgRealDataD.Length && i < nMaxItems; i++)
2475 str += m_rgRealDataD[i].ToString() +
",";
2478 else if (m_rgRealDataF !=
null)
2480 for (
int i = 0; i < m_rgRealDataF.Length && i < nMaxItems; i++)
2482 str += m_rgRealDataF[i].ToString() +
",";
2487 str =
"No Real Data Found!";
2492 for (
int i = 0; i < m_rgByteData.Length && i < nMaxItems; i++)
2494 str += m_rgByteData[i].ToString() +
",";
2498 return str.TrimEnd(
',');
2511 if (m_rgByteData ==
null)
2512 throw new Exception(
"Bytemaps are only supported with byte based data.");
2514 return new Bytemap(m_nChannels, m_nHeight, m_nWidth, m_rgByteData);
2526 if (rgdfMean ==
null)
2535 rgdfMean[i] += sd.
RealDataD[i] / nTotal;
2542 rgdfMean[i] += sd.
RealDataF[i] / nTotal;
2547 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2554 rgdfMean[i] += (double)sd.
ByteData[i] / (
double)nTotal;
2570 if (rgImg.Length < 2)
2571 throw new Exception(
"There must be at least 2 images in the simple datum array.");
2576 rgSums =
new float[rgImg[0].
ByteData.Length];
2578 rgSums =
new float[rgImg[0].
RealDataD.Length];
2580 rgSums =
new float[rgImg[0].
RealDataF.Length];
2582 throw new Exception(
"No data in rgImg[0]!");
2584 Stopwatch sw =
new Stopwatch();
2593 for (
int i = 0; i < rgImg.Length && i < 100; i++)
2595 nHeight = Math.Max(nHeight, rgImg[i].
Height);
2596 nWidth = Math.Max(nWidth, rgImg[i].
Width);
2599 for (
int i = 0; i < rgImg.Length; i++)
2601 if (rgImg[i] !=
null)
2603 if (rgImg[i].
Height != nHeight || rgImg[i].
Width != nWidth)
2608 for (
int n = 0; n < rgSums.Length; n++)
2615 for (
int n = 0; n < rgSums.Length; n++)
2617 rgSums[n] += (float)rgImg[i].
RealDataD[n];
2622 for (
int n = 0; n < rgSums.Length; n++)
2624 rgSums[n] += (float)rgImg[i].
RealDataF[n];
2629 throw new Exception(
"No data in rgImg[" + i.ToString() +
"]!");
2634 if (sw.Elapsed.TotalMilliseconds > 2000)
2636 double dfPct = (double)i / (
double)rgImg.Length;
2637 log.
WriteLine(
"processing mean (" + dfPct.ToString(
"P") +
")");
2640 if (rgAbort !=
null)
2642 if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
2651 byte[] rgbMean =
new byte[rgSums.Length];
2653 for (
int n = 0; n < rgSums.Length; n++)
2655 rgbMean[n] = (byte)(rgSums[n] / (
float)nCount);
2659 d.
SetData(
new List<byte>(rgbMean), -1,
true);
2664 double[] rgdfMean =
new double[rgSums.Length];
2666 for (
int n = 0; n < rgSums.Length; n++)
2668 rgdfMean[n] = (double)rgSums[n] / nCount;
2672 d.
SetData(
new List<double>(rgdfMean), -1,
true);
2677 float[] rgfMean =
new float[rgSums.Length];
2679 for (
int n = 0; n < rgSums.Length; n++)
2681 rgfMean[n] = (float)rgSums[n] / nCount;
2685 d.
SetData(
new List<float>(rgfMean), -1,
true);
2690 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2706 using (MemoryStream ms =
new MemoryStream())
2707 using (BinaryWriter bw =
new BinaryWriter(ms))
2709 bw.Write((
int)type);
2712 if (annotations !=
null)
2713 nCount = annotations.
Count;
2717 if (annotations !=
null)
2719 for (
int i = 0; i < annotations.
Count; i++)
2721 annotations[i].Save(bw);
2726 return ms.ToArray();
2750 if (rg ==
null || fmt !=
DATA_FORMAT.ANNOTATION_DATA)
2753 using (MemoryStream ms =
new MemoryStream(rg))
2754 using (BinaryReader br =
new BinaryReader(ms))
2759 int nCount = br.ReadInt32();
2762 for (
int i = 0; i < nCount; i++)
2780 if (m_rgAnnotationGroup ==
null)
2795 using (StreamWriter sw =
new StreamWriter(strFile +
".txt"))
2797 sw.WriteLine(
"Index = " +
Index.ToString());
2798 sw.WriteLine(
"ImageID = " +
ImageID.ToString());
2799 sw.WriteLine(
"VirtualID = " +
VirtualID.ToString());
2800 sw.WriteLine(
"Label = " +
Label.ToString());
2801 sw.WriteLine(
"AutoLabeled = " +
AutoLabeled.ToString());
2802 sw.WriteLine(
"Boost = " +
Boost.ToString());
2803 sw.WriteLine(
"SourceID = " +
SourceID.ToString());
2806 sw.WriteLine(
"Time = " +
TimeStamp.ToString());
2807 sw.WriteLine(
"Size = {1," +
Channels.ToString() +
"," +
Height.ToString() +
"," +
Width.ToString() +
"}");
2821 using (StreamReader sr =
new StreamReader(strFile))
2823 string strVal = parseValue(sr.ReadLine(),
'=');
2824 int nIndex =
int.Parse(strVal);
2826 strVal = parseValue(sr.ReadLine(),
'=');
2827 int nImageID =
int.Parse(strVal);
2829 strVal = parseValue(sr.ReadLine(),
'=');
2830 int nVirtualID =
int.Parse(strVal);
2832 strVal = parseValue(sr.ReadLine(),
'=');
2833 int nLabel =
int.Parse(strVal);
2835 strVal = parseValue(sr.ReadLine(),
'=');
2836 bool bAutoLabeled =
bool.Parse(strVal);
2838 strVal = parseValue(sr.ReadLine(),
'=');
2839 int nBoost =
int.Parse(strVal);
2841 strVal = parseValue(sr.ReadLine(),
'=');
2842 int nSrcId =
int.Parse(strVal);
2844 strVal = parseValue(sr.ReadLine(),
'=');
2845 int nOriginalSrcId =
int.Parse(strVal);
2847 strVal = parseValue(sr.ReadLine(),
'=');
2848 string strDesc = strVal;
2850 strVal = parseValue(sr.ReadLine(),
'=');
2851 DateTime dt = DateTime.Parse(strVal);
2853 strVal = parseValue(sr.ReadLine(),
'=');
2854 strVal = strVal.Trim(
'{',
'}');
2855 string[] rgstr = strVal.Split(
',');
2857 int nChannels =
int.Parse(rgstr[1]);
2858 int nHeight =
int.Parse(rgstr[2]);
2859 int nWidth =
int.Parse(rgstr[3]);
2861 return new SimpleDatum(
false, nChannels, nWidth, nHeight, nLabel, dt, nBoost, bAutoLabeled, nIndex, nVirtualID, nImageID, nSrcId, nOriginalSrcId);
2865 private static string parseValue(
string str,
char chDelim)
2867 int nPos = str.LastIndexOf(chDelim);
2871 return str.Substring(nPos + 1).Trim();
2881 string[] rgstrFiles = Directory.GetFiles(strPath,
"*.txt");
2882 List<SimpleDatum> rgData =
new List<SimpleDatum>();
2884 foreach (
string strFile
in rgstrFiles)
2900 public static float[]
Transpose(
float[] rg,
int nH,
int nW,
int nDim = 1)
2902 float[] rgT =
new float[rg.Length];
2904 for (
int i = 0; i < nH; i++)
2906 for (
int j = 0; j < nW; j++)
2908 int nSrcIdx = (i * nW + j) * nDim;
2909 int nDstIdx = (j * nH + i) * nDim;
2912 rgT[nDstIdx] = rg[nSrcIdx];
2914 Array.Copy(rg, nSrcIdx, rgT, nDstIdx, nDim);
2929 public static double[]
Transpose(
double[] rg,
int nH,
int nW,
int nDim = 1)
2931 double[] rgT =
new double[rg.Length];
2933 for (
int i = 0; i < nH; i++)
2935 for (
int j = 0; j < nW; j++)
2937 int nSrcIdx = (i * nW + j) * nDim;
2938 int nDstIdx = (j * nH + i) * nDim;
2941 rgT[nDstIdx] = rg[nSrcIdx];
2943 Array.Copy(rg, nSrcIdx, rgT, nDstIdx, nDim);
2959 List<int> m_rgShape;
2961 object m_tag =
null;
2971 m_strName = strName;
2974 m_rgShape =
new List<int>() { nCount };
2976 if (rgShape !=
null)
2977 m_rgShape.AddRange(rgShape);
2985 get {
return m_tag; }
2986 set { m_tag = value; }
2994 get {
return m_rgShape; }
3002 get {
return m_strName; }
3003 set { m_strName = value; }
3011 get {
return m_rgItems.Count(); }
3021 get {
return m_rgItems[nIdx]; }
3022 set { m_rgItems[nIdx] = value; }
3031 return (IEnumerator<SimpleDatum>)m_rgItems.GetEnumerator();
3034 IEnumerator IEnumerable.GetEnumerator()
3036 return m_rgItems.GetEnumerator();
Defines a collection of AnnotationGroups.
void Add(AnnotationGroupCollection col)
Add another AnnotationGroupCollection to this one.
int Count
Specifies the number of items in the collection.
The AnnoationGroup class manages a group of annotations.
AnnotationGroup Clone()
Create a copy of the annotation group.
static AnnotationGroup Load(BinaryReader br)
Load an annotation group using the binary reader.
The Bytemap operates similar to a bitmap but is actually just an array of bytes.
int Channels
Specifies the channels of the data.
int Height
Specifies the height of the data.
byte[] Bytes
Specifies the data itself.
int Width
Specifies the width of the data.
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
The ImageData class is a helper class used to convert between Datum, other raw data,...
static Datum GetImageData(Bitmap bmp, SimpleDatum sd, bool? bIsDataRealOverride=null, int[] rgFocusMap=null)
The GetImageData function converts a Bitmap into a Datum.
static Bitmap GetImage(SimpleDatum d, ColorMapper clrMap=null, List< int > rgClrOrder=null)
Converts a SimplDatum (or Datum) into an image, optionally using a ColorMapper.
The Log class provides general output in text form.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
The SimpleDatumCollection holds a named array of SimpleDatums
object Tag
Get/set a user defined value.
IEnumerator< SimpleDatum > GetEnumerator()
Get the enumerator for the collection.
SimpleDatumCollection(int nCount, string strName="", List< int > rgShape=null)
The constructor.
string Name
Get/set the name of the array.
List< int > Shape
Returns the shape of the items within the array (including the array count as the first element).
int Count
Get the number of items in the array.
The SimpleDatum class holds a data input within host memory.
string TagName
Returns a user-defined name of the tag associated with the data.
static Tuple< double[], float[]> GetRealData(byte[] rgData)
Decodes an array of byte values into a array of either double or float values depending on how the or...
void CopyData(SimpleDatum d)
Copy just the data from another SimpleDatum, making sure to update the C x H x W dimensions and IsRea...
byte[] GetByteData(out bool bEncoded)
Returns the data as a byte array regardless of how it is stored.
void SetImageID(int nID)
Set the image ID.
int OriginalLabel
Get/set the original known label of the data.
static byte[] GetByteData(List< float > rgData)
Encodes a list of float values to an encoded byte array.
void Copy(SimpleDatum d, bool bCopyData, int? nHeight=null, int? nWidth=null)
Copy another SimpleDatum into this one.
float GetDataAtF(int nIdx)
Returns the item at a specified index in the float type.
static T[] PadData< T >(List< T > rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Padd the data.
bool Sub(SimpleDatum sd, bool bSetNegativeToZero=false)
Subtract the data of another SimpleDatum from this one, so this = this - sd.
static byte[] SaveAnnotationDataToDataCriteriaByteArray(ANNOTATION_TYPE type, AnnotationGroupCollection annotations)
Save the annotation data to a byte array.
static double[] Transpose(double[] rg, int nH, int nW, int nDim=1)
Transpose the data within a double array.
static SimpleDatum CalculateMean(Log log, SimpleDatum[] rgImg, WaitHandle[] rgAbort)
Calculate the mean of an array of SimpleDatum and return the mean as a new SimpleDatum.
void Zero()
Zero out all data in the datum but keep the size and other settings.
ANNOTATION_TYPE
Specifies the annotation type when using annotations.
byte[] DebugData
Get/set debug data associated with the data.
void ResetBoost()
Reset the boost to the original boost.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, List< float > rgfData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
SimpleDatum Div(double dfVal, bool bConvertToByte)
Divides all elements of the SimpleDatum by a value and returns the result as a new SimpleDatum.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, int nBoost=0, bool bAutoLabeled=false, int nIdx=-1, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
SimpleDatum(SimpleDatum d, int nHeight, int nWidth)
The SimpleDatum constructor.
List< int > GetNonZeroIndexes()
Returns all indexes with non-zero data.
void MaskOutAllButLastColumnsX(int nLastColumsToRetain, int nMaskingValue)
DEPRECIATED: Masks out all data except for the last columns of data.
static byte[] GetByteData(List< double > rgData)
Encodes a list of double values to an encoded byte array.
string ToArrayAsString(int nMaxItems)
Returns a string containing the items of the SimpleDatum.
bool HasRealData
Returns true if either the RealDataD or RealDataF are non null and have length > 0.
bool LoadAnnotationDataFromDataCriteria()
Load the annotation data and type from the data criteria.
void SetLabel(int nLabel)
Sets the label.
int ItemCount
Returns the number of data items.
bool GetDataValid(bool bByType=true)
Returns true if the ByteData or RealDataD or RealDataF are not null, false otherwise.
List< T > ClipToLastColumnsX< T >(int nLastColumns=10)
DEPRECIATED: Clips the SimpleDatum to the last nLastColumns and returns the data.
SimpleDatum(Valuemap data)
The SimpleDatum constructor.
T[] GetData< T >(int nImagePadX=0, int nImagePadY=0)
Returns the data as a generic array and optionally pads the data.
int VirtualID
Returns the virtual ID of the SimpleDatum.
SimpleDatum()
The SimpleDatum constructor.
void SaveAnnotationDataToDataCriteria()
Save the annotation data and type to the data criteria.
DateTime TimeStamp
Get/set the Timestamp.
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel=-1, DateTime? dtTime=null, int nBoost=0, bool bAutoLabeled=false, int nIdx=-1, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, double[] rgdfData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
SimpleDatum(Bytemap data)
The SimpleDatum constructor.
object Tag
Specifies user data associated with the SimpleDatum.
string m_strTagName
Specifies the name of the user value.
SimpleDatum(SimpleDatum d, bool bCopyData=false)
The SimpleDatum constructor.
void SetData(SimpleDatum d)
Set the data of the current SimpleDatum by copying the data of another.
string Description
Get/set a description of the data.
static byte[] GetByteData(byte[] rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Return the non-real data as a byte array after padding the data.
SimpleDatum Resize(int nH, int nW)
Resize the data and return it as a new SimpleDatum.
SimpleDatum(int nChannels, int nWidth, int nHeight)
The SimpleDatum constructor.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, float[] rgfData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
void ScalePow(double dfScalePow, double dfMin=-double.MaxValue, double dfMax=double.MaxValue)
Scale the values by the scaling factor that raises each value by the specified power.
override string ToString()
Return a string representation of the SimpleDatum.
Bytemap ToBytemap()
Return the SimpleData data as a Bytemap.
static AnnotationGroupCollection LoadAnnotationDataFromDataCriteria(byte[] rg, DATA_FORMAT fmt, out ANNOTATION_TYPE type)
Load the AnnotationGroups from the byte array.
T GetDataAt< T >(int nIdx)
Returns the item at a specified index in the type specified.
int Channels
Return the number of channels of the data.
int OriginalSourceID
Returns the original source ID which is set when using a virtual ID.
static double[] getRealDataD(byte[] rgData, int nIdx)
Decodes an array of byte values into a array of double values.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, List< byte > rgData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
bool IsRealData
Returns whether or not the data contains real numbers or byte data.
AnnotationGroupCollection annotation_group
When using annoations, each annotation group contains an annotation for a particular class used with ...
float[] RealDataF
Return the float data. This field is valid when IsRealData = true.
byte[] DataCriteria
Get/set data criteria associated with the data.
ANNOTATION_TYPE annotation_type
When using annotations, the annotation type specifies the type of annotation. Currently,...
void SetData(List< byte > rgByteData, int nLabel, bool bAllowVirtualOverride=false)
Sets the byte data of the SimpleDatum and its Label.
static bool AccumulateMean(ref double[] rgdfMean, SimpleDatum sd, int nTotal)
Accumulate a portion of a SimpleDatum to calculate the mean value.
DATA_FORMAT
Defines the data format of the DebugData and DataCriteria when specified.
double Max
Returns the maximum value in the data or double.NaN if there is no data.
int GroupID
Get/set the group ID of the SimpleDatum.
int Boost
Get/set the boost for this data.
object m_tag
Specifies a user value.
void Clip(int nDataLen, int? nNewChannel, int? nNewHeight, int? nNewWidth)
Clip the data length down to a smaller size and copies the clipped data.
int Width
Return the width of the data.
int HitCount
Get/set the hit count for the SimpleDatum.
static List< SimpleDatum > LoadFromPath(string strPath)
Load all SimpleDatums from a directory of files previously stored with SaveInfo.
double GetDataAtD(int nIdx)
Returns the item at a specified index in the double type.
bool AutoLabeled
Get/set whether or not the label was auto generated.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, List< double > rgfData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
void SetData(List< double > rgRealData, int nLabel, bool bAllowVirtualOverride=false)
Sets the double data of the SimpleDatum and its Label.
byte[] ByteData
Return the byte data. This field is valid when IsRealData = false.
int SourceID
Returns the ID of the data source that owns this image.
static float[] getRealDataF(byte[] rgData, int nIdx)
Decodes an array of byte values into a array of float values.
bool SubAbs(SimpleDatum sd)
Subtract the data of another SimpleDatum from this one, and take the absolute value,...
static SimpleDatum LoadInfo(string strFile)
Load a SimpleData from text file information previously saved with SaveInfo.
int Index
Returns the index of the SimpleDatum.
DATA_FORMAT DebugDataFormat
Get/set the data format of the debug data.
void ResetLabel()
Resets the label to the original label used when creating the SimpleDatum.
byte GetDataAtByte(int nIdx)
Returns the item at a specified index in the byte type.
int ImageID
Returns the ID of the image in the database.
SimpleDatum(List< SimpleDatum > rg, bool bAlignChannels)
Constructor that copies an array into a single SimpleDatum by appending each to the other in order.
int Height
Return the height of the data.
void SetData(float[] rgf, int nLabel)
Set the data to the float array specified.
void SetData(List< float > rgRealData, int nLabel, bool bAllowVirtualOverride=false)
Sets the float data of the SimpleDatum and its Label.
DATA_FORMAT DataCriteriaFormat
Get/set the data format of the data criteria.
void SetData(byte[] rgb, int nLabel)
Set the data to the byte array specified.
double[] RealDataD
Return the double data. This field is valid when IsRealData = true.
void SetData(double[] rgdf, int nLabel)
Set the data to the double array specified.
void Scale(double dfScale, double dfMin=-double.MaxValue, double dfMax=double.MaxValue)
Scale the values by the scaling factor.
static float[] Transpose(float[] rg, int nH, int nW, int nDim=1)
Transpose the data within a float array.
double Min
Returns the minimum value in the data or double.NaN if there is no data.
static Tuple< double[], float[]> GetRealData(byte[] rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Return the real data as a double or float array (depending on the original encoding data type) after ...
int Label
Return the known label of the data.
SimpleDatum(int nChannels, int nWidth, int nHeight, float[] rgf, int nOffset, int nCount, bool bDataIsReal=true)
The SimpleDatum constructor.
void SaveInfo(string strFile)
Save the SimpleDatum information to a text file.
SimpleDatum(bool bIsReal, int nChannels, int nWidth, int nHeight, int nLabel, DateTime dtTime, byte[] rgData, int nBoost, bool bAutoLabeled, int nIdx, int nVirtualID=0, int nImageID=0, int nSourceID=0, int nOriginalSourceID=0)
The SimpleDatum constructor.
The SimpleTemporalDatumCollection manages a collection of SimpleTemporalDatum objects.
SimpleTemporalDatumCollection(int nCapacity)
The constructor.
int Count
Returns the number of items in the collection.
void Add(SimpleDatum sd)
Add a new datum to the collection (must support the RealDataF data);
void Clear()
Clear all items from the list.
The SimpleTemporalDatum is used to return temporal data
float[] Data
Get/set the data which is of length (Channels * Width * Height).
int Height
Get the data height.
SimpleTemporalDatum(int nChannels, int nWidth, int nHeight, float[] rgData)
The constructor.
int ItemCount
Returns the number of items in the data.
int Channels
Get the data channels.
int Width
Get the data width.
The Utility class provides general utility funtions.
The Realmap operates similar to a bitmap but is actually just an array of doubles.
double[] Values
Specifies the data itself.
int Channels
Specifies the channels of the data.
int Height
Specifies the height of the data.
int Width
Specifies the width of the data.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
@ CUSTOM
Defines a purely custom training method.
@ NONE
No training category specified.