3using System.Collections.Generic;
8using System.Runtime.InteropServices;
21 int m_nOriginalLabel = 0;
26 byte[] m_rgByteData =
null;
27 float[] m_rgRealDataF =
null;
28 double[] m_rgRealDataD =
null;
29 bool m_bIsRealData =
false;
30 DateTime m_dt = DateTime.MinValue;
31 int m_nOriginalBoost = 0;
33 bool m_bAutoLabeled =
false;
37 byte[] m_rgDataCriteria =
null;
39 byte[] m_rgDebugData =
null;
41 string m_strDesc =
null;
43 int m_nOriginalSourceID = 0;
143 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)
145 m_nChannels = nChannels;
148 m_nOriginalLabel = nLabel;
150 m_dt = dtTime.GetValueOrDefault(DateTime.MinValue);
151 m_nOriginalBoost = nBoost;
153 m_bAutoLabeled = bAutoLabeled;
154 m_nVirtualID = nVirtualID;
155 m_bIsRealData = bIsReal;
157 m_nImageID = nImageID;
158 m_nSourceID = nSourceID;
159 m_nOriginalSourceID = nOriginalSourceID;
179 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)
181 m_nChannels = nChannels;
184 m_nOriginalLabel = nLabel;
187 m_nOriginalBoost = nBoost;
189 m_bAutoLabeled = bAutoLabeled;
190 m_nVirtualID = nVirtualID;
191 m_bIsRealData = bIsReal;
193 m_nImageID = nImageID;
194 m_nSourceID = nSourceID;
195 m_nOriginalSourceID = nOriginalSourceID;
198 throw new ArgumentException(
"The data sent is not real, but the bIsReal is set to true!");
200 m_rgByteData = rgData.ToArray();
220 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)
222 m_nChannels = nChannels;
225 m_nOriginalLabel = nLabel;
228 m_nOriginalBoost = nBoost;
230 m_bAutoLabeled = bAutoLabeled;
231 m_nVirtualID = nVirtualID;
232 m_bIsRealData = bIsReal;
234 m_nImageID = nImageID;
235 m_nSourceID = nSourceID;
236 m_nOriginalSourceID = nOriginalSourceID;
239 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
241 m_rgRealDataD = rgfData.ToArray();
261 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)
263 m_nChannels = nChannels;
266 m_nOriginalLabel = nLabel;
269 m_nOriginalBoost = nBoost;
271 m_bAutoLabeled = bAutoLabeled;
272 m_nVirtualID = nVirtualID;
273 m_bIsRealData = bIsReal;
275 m_nImageID = nImageID;
276 m_nSourceID = nSourceID;
277 m_nOriginalSourceID = nOriginalSourceID;
280 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
282 m_rgRealDataF = rgfData.ToArray();
302 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)
304 m_nChannels = nChannels;
307 m_nOriginalLabel = nLabel;
310 m_nOriginalBoost = nBoost;
312 m_bAutoLabeled = bAutoLabeled;
313 m_nVirtualID = nVirtualID;
314 m_bIsRealData = bIsReal;
316 m_nImageID = nImageID;
317 m_nSourceID = nSourceID;
318 m_nOriginalSourceID = nOriginalSourceID;
321 throw new ArgumentException(
"The data sent is not real, but the bIsReal is set to true!");
323 m_rgByteData = rgData;
343 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)
345 m_nChannels = nChannels;
348 m_nOriginalLabel = nLabel;
351 m_nOriginalBoost = nBoost;
353 m_bAutoLabeled = bAutoLabeled;
354 m_nVirtualID = nVirtualID;
355 m_bIsRealData = bIsReal;
357 m_nImageID = nImageID;
358 m_nSourceID = nSourceID;
359 m_nOriginalSourceID = nOriginalSourceID;
362 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
364 m_rgRealDataD = rgdfData;
384 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)
386 m_nChannels = nChannels;
389 m_nOriginalLabel = nLabel;
392 m_nOriginalBoost = nBoost;
394 m_bAutoLabeled = bAutoLabeled;
395 m_nVirtualID = nVirtualID;
396 m_bIsRealData = bIsReal;
398 m_nImageID = nImageID;
399 m_nSourceID = nSourceID;
400 m_nOriginalSourceID = nOriginalSourceID;
403 throw new ArgumentException(
"The data sent is real, but the bIsReal is set to false!");
405 m_rgRealDataF = rgfData;
424 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)
426 m_nChannels = nChannels;
429 m_nOriginalLabel = nLabel;
432 m_nOriginalBoost = nBoost;
434 m_bAutoLabeled = bAutoLabeled;
435 m_nVirtualID = nVirtualID;
436 m_bIsRealData = bIsReal;
438 m_nImageID = nImageID;
439 m_nSourceID = nSourceID;
440 m_nOriginalSourceID = nOriginalSourceID;
442 m_rgRealDataD =
null;
443 m_rgRealDataF =
null;
456 public SimpleDatum(
int nChannels,
int nWidth,
int nHeight,
float[] rgf,
int nOffset,
int nCount,
bool bDataIsReal =
true)
458 m_nChannels = nChannels;
461 m_nOriginalLabel = 0;
462 m_nOriginalBoost = 0;
463 m_dt = DateTime.MinValue;
464 m_bAutoLabeled =
false;
469 m_nOriginalSourceID = 0;
472 int nLen = nChannels * nWidth * nHeight;
474 throw new Exception(
"The channel x width x height should equal the count!");
478 m_bIsRealData =
true;
479 m_rgRealDataF =
new float[nCount];
482 Array.Copy(rgf, nOffset, m_rgRealDataF, 0, nCount);
486 m_bIsRealData =
false;
487 m_rgByteData =
new byte[nCount];
489 for (
int i = 0; i < nCount; i++)
491 m_rgByteData[i] = Math.Min(Math.Max((
byte)rgf[nOffset + i], (
byte)0), (
byte)255);
504 m_nChannels = nChannels;
507 m_nOriginalLabel = 0;
508 m_nOriginalBoost = 0;
509 m_dt = DateTime.MinValue;
510 m_bAutoLabeled =
false;
515 m_nOriginalSourceID = 0;
526 m_nWidth = data.
Width;
528 m_nOriginalLabel = -1;
530 m_bIsRealData =
false;
532 m_rgByteData = data.
Bytes;
542 m_nWidth = data.
Width;
544 m_nOriginalLabel = -1;
546 m_bIsRealData =
true;
548 m_rgRealDataD = data.
Values;
569 Copy(d,
false, nHeight, nWidth);
599 m_nChannels *= rg.Count;
603 if (m_nChannels != rg.Count)
604 throw new Exception(
"Currently channel alignment is only allowed on single channel data.");
612 double[] rgData =
new double[m_nChannels *
Height *
Width];
614 for (
int h = 0; h <
Height; h++)
616 for (
int w = 0; w <
Width; w++)
618 int nIdxSrc = (h *
Width) + w;
619 int nIdxDst = nIdxSrc * m_nChannels;
621 for (
int c = 0; c < m_nChannels; c++)
623 rgData[nIdxDst + c] = rg[c].RealDataD[nIdxSrc];
628 m_rgRealDataD = rgData;
632 float[] rgData =
new float[m_nChannels *
Height *
Width];
634 for (
int h = 0; h <
Height; h++)
636 for (
int w = 0; w <
Width; w++)
638 int nIdxSrc = (h *
Width) + w;
639 int nIdxDst = nIdxSrc * m_nChannels;
641 for (
int c = 0; c < m_nChannels; c++)
643 rgData[nIdxDst + c] = rg[c].RealDataF[nIdxSrc];
648 m_rgRealDataF = rgData;
652 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
658 byte[] rgData =
new byte[m_nChannels *
Height *
Width];
660 for (
int h = 0; h <
Height; h++)
662 for (
int w = 0; w <
Width; w++)
664 int nIdxSrc = (h *
Width) + w;
665 int nIdxDst = nIdxSrc * m_nChannels;
667 for (
int c = 0; c < m_nChannels; c++)
669 rgData[nIdxDst + c] = rg[c].ByteData[nIdxSrc];
674 m_rgByteData = rgData;
675 m_rgRealDataF =
null;
676 m_rgRealDataD =
null;
682 bool bReal = rg[0].IsRealData;
684 int nItemCount = m_nChannels / rg.Count;
690 m_rgRealDataD =
new double[m_nChannels *
Height *
Width];
693 for (
int i = 0; i < rg.Count; i++)
695 Array.Copy(rg[i].
RealDataD, 0, m_rgRealDataD, nDstIdx, nItemCount);
696 nDstIdx += nItemCount;
701 m_rgRealDataF =
new float[m_nChannels *
Height *
Width];
704 for (
int i = 0; i < rg.Count; i++)
706 Array.Copy(rg[i].
RealDataF, 0, m_rgRealDataF, nDstIdx, nItemCount);
707 nDstIdx += nItemCount;
712 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
717 m_rgByteData =
new byte[m_nChannels *
Height *
Width];
718 m_rgRealDataD =
null;
719 m_rgRealDataF =
null;
721 for (
int i = 0; i < rg.Count; i++)
723 Array.Copy(rg[i].
ByteData, 0, m_rgByteData, nDstIdx, nItemCount);
724 nDstIdx += nItemCount;
735 get {
return m_nHitCount; }
736 set { m_nHitCount = value; }
744 get {
return m_tag; }
745 set {
m_tag = value; }
766 if (m_rgRealDataD !=
null)
767 return m_rgRealDataD.Min(p => p);
768 else if (m_rgRealDataF !=
null)
769 return m_rgRealDataF.Min(p => p);
771 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
775 if (m_rgByteData !=
null)
776 return (
double)m_rgByteData.Min(p => p);
792 if (m_rgRealDataD !=
null)
793 return m_rgRealDataD.Max(p => p);
794 else if (m_rgRealDataF !=
null)
795 return m_rgRealDataF.Max(p => p);
797 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
801 if (m_rgByteData !=
null)
802 return (
double)m_rgByteData.Max(p => p);
816 public void Clip(
int nDataLen,
int? nNewChannel,
int? nNewHeight,
int? nNewWidth)
818 if (m_rgByteData !=
null && m_rgByteData.Length > nDataLen)
820 byte[] rgData =
new byte[nDataLen];
821 Array.Copy(m_rgByteData, rgData, nDataLen);
822 m_rgByteData = rgData;
824 if (m_rgRealDataD !=
null && m_rgRealDataD.Length > nDataLen)
826 double[] rgData =
new double[nDataLen];
827 Array.Copy(m_rgRealDataD, rgData, nDataLen);
828 m_rgRealDataD = rgData;
830 if (m_rgRealDataF !=
null && m_rgRealDataF.Length > nDataLen)
832 float[] rgData =
new float[nDataLen];
833 Array.Copy(m_rgRealDataF, rgData, nDataLen);
834 m_rgRealDataF = rgData;
837 m_nChannels = nNewChannel.GetValueOrDefault(m_nChannels);
838 m_nHeight = nNewHeight.GetValueOrDefault(m_nHeight);
839 m_nWidth = nNewWidth.GetValueOrDefault(m_nWidth);
848 List<int> rgIdx =
new List<int>();
852 if (m_rgRealDataD !=
null)
854 for (
int i = 0; i < m_rgRealDataD.Length; i++)
856 if (m_rgRealDataD[i] != 0)
860 else if (m_rgRealDataF !=
null)
862 for (
int i = 0; i < m_rgRealDataF.Length; i++)
864 if (m_rgRealDataF[i] != 0)
870 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
875 for (
int i = 0; i < m_rgByteData.Length; i++)
877 if (m_rgByteData[i] != 0)
890 if (m_rgByteData !=
null)
891 Array.Clear(m_rgByteData, 0, m_rgByteData.Length);
893 if (m_rgRealDataD !=
null)
894 Array.Clear(m_rgRealDataD, 0, m_rgRealDataD.Length);
896 if (m_rgRealDataF !=
null)
897 Array.Clear(m_rgRealDataF, 0, m_rgRealDataF.Length);
908 bool bDifferent =
false;
911 throw new Exception(
"Both simple datums must have the same number of elements!");
913 if (m_rgByteData !=
null)
915 for (
int i = 0; i < m_rgByteData.Length; i++)
919 if (sd.m_rgByteData !=
null)
920 nVal = m_rgByteData[i] - sd.m_rgByteData[i];
921 else if (sd.m_rgRealDataD !=
null)
922 nVal = (int)m_rgByteData[i] - (
int)sd.m_rgRealDataD[i];
923 else if (sd.m_rgRealDataF !=
null)
924 nVal = (int)m_rgByteData[i] - (
int)sd.m_rgRealDataF[i];
930 if (bSetNegativeToZero && nVal < 0)
934 m_rgByteData[i] = (byte)nVal;
938 if (m_rgRealDataD !=
null)
940 for (
int i = 0; i < m_rgRealDataD.Length; i++)
942 if (sd.m_rgRealDataD !=
null)
943 m_rgRealDataD[i] -= sd.m_rgRealDataD[i];
944 else if (sd.m_rgRealDataF !=
null)
945 m_rgRealDataD[i] -= sd.m_rgRealDataF[i];
946 else if (sd.m_rgByteData !=
null)
947 m_rgRealDataD[i] -= sd.m_rgByteData[i];
949 if (m_rgRealDataD[i] != 0)
953 if (bSetNegativeToZero && m_rgRealDataD[i] < 0)
954 m_rgRealDataD[i] = 0;
959 if (m_rgRealDataF !=
null)
961 for (
int i = 0; i < m_rgRealDataF.Length; i++)
963 if (sd.m_rgRealDataD !=
null)
964 m_rgRealDataF[i] -= (float)sd.m_rgRealDataD[i];
965 else if (sd.m_rgRealDataF !=
null)
966 m_rgRealDataF[i] -= sd.m_rgRealDataF[i];
967 else if (sd.m_rgByteData !=
null)
968 m_rgRealDataF[i] -= sd.m_rgByteData[i];
970 if (m_rgRealDataF[i] != 0)
974 if (bSetNegativeToZero && m_rgRealDataF[i] < 0)
975 m_rgRealDataF[i] = 0;
990 bool bDifferent =
false;
993 throw new Exception(
"Both simple datums must have the same number of elements!");
995 if (m_rgByteData !=
null)
997 if (sd.m_rgByteData ==
null)
998 throw new Exception(
"Both simple datums must have the same type of data!");
1000 for (
int i = 0; i < m_rgByteData.Length; i++)
1002 m_rgByteData[i] = (byte)Math.Abs(m_rgByteData[i] - sd.m_rgByteData[i]);
1003 if (m_rgByteData[i] != 0)
1008 if (m_rgRealDataD !=
null)
1010 if (sd.m_rgRealDataD ==
null)
1011 throw new Exception(
"Both simple datums must have the same type of data!");
1013 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1015 m_rgRealDataD[i] = Math.Abs(m_rgRealDataD[i] - sd.m_rgRealDataD[i]);
1016 if (m_rgRealDataD[i] != 0)
1021 if (m_rgRealDataF !=
null)
1023 if (sd.m_rgRealDataF ==
null)
1024 throw new Exception(
"Both simple datums must have the same type of data!");
1026 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1028 m_rgRealDataF[i] = Math.Abs(m_rgRealDataF[i] - sd.m_rgRealDataF[i]);
1029 if (m_rgRealDataF[i] != 0)
1043 public void Scale(
double dfScale,
double dfMin = -
double.MaxValue,
double dfMax =
double.MaxValue)
1045 if (m_rgByteData !=
null)
1047 for (
int i = 0; i < m_rgByteData.Length; i++)
1049 int nVal = (int)(m_rgByteData[i] * dfScale);
1050 if (nVal < (
int)dfMin)
1052 else if (nVal > (
int)dfMax)
1054 m_rgByteData[i] = (byte)nVal;
1058 if (m_rgRealDataD !=
null)
1060 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1062 m_rgRealDataD[i] *= dfScale;
1063 if (m_rgRealDataD[i] < dfMin)
1064 m_rgRealDataD[i] = dfMin;
1065 else if (m_rgRealDataD[i] > dfMax)
1066 m_rgRealDataD[i] = dfMax;
1070 if (m_rgRealDataF !=
null)
1072 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1074 m_rgRealDataF[i] *= (float)dfScale;
1075 if (m_rgRealDataF[i] < dfMin)
1076 m_rgRealDataF[i] = (float)dfMin;
1077 else if (m_rgRealDataF[i] > dfMax)
1078 m_rgRealDataF[i] = (float)dfMax;
1089 public void ScalePow(
double dfScalePow,
double dfMin = -
double.MaxValue,
double dfMax =
double.MaxValue)
1091 if (m_rgByteData !=
null)
1093 for (
int i = 0; i < m_rgByteData.Length; i++)
1095 int nVal = (int)((
double)Math.Pow(m_rgByteData[i], dfScalePow));
1096 if (nVal < (
int)dfMin)
1098 else if (nVal > (
int)dfMax)
1100 m_rgByteData[i] = (byte)nVal;
1104 if (m_rgRealDataD !=
null)
1106 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1108 m_rgRealDataD[i] = Math.Pow(m_rgRealDataD[i], dfScalePow);
1109 if (m_rgRealDataD[i] < dfMin)
1110 m_rgRealDataD[i] = dfMin;
1111 else if (m_rgRealDataD[i] > dfMax)
1112 m_rgRealDataD[i] = dfMax;
1116 if (m_rgRealDataF !=
null)
1118 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1120 m_rgRealDataF[i] = (float)(Math.Pow(m_rgRealDataF[i], dfScalePow));
1121 if (m_rgRealDataF[i] < dfMin)
1122 m_rgRealDataF[i] = (float)dfMin;
1123 else if (m_rgRealDataF[i] > dfMax)
1124 m_rgRealDataF[i] = (float)dfMax;
1138 m_bIsRealData = d.m_bIsRealData;
1139 m_nLabel = d.m_nLabel;
1140 m_nOriginalLabel = d.m_nOriginalLabel;
1141 m_nChannels = d.m_nChannels;
1142 m_nHeight = nHeight.GetValueOrDefault(d.m_nHeight);
1143 m_nWidth = nWidth.GetValueOrDefault(d.m_nWidth);
1147 m_rgRealDataD =
Utility.Clone<
double>(d.m_rgRealDataD);
1148 m_rgRealDataF =
Utility.Clone<
float>(d.m_rgRealDataF);
1149 m_rgByteData =
Utility.Clone<
byte>(d.m_rgByteData);
1153 m_rgRealDataD = d.m_rgRealDataD;
1154 m_rgRealDataF = d.m_rgRealDataF;
1155 m_rgByteData = d.m_rgByteData;
1159 m_nOriginalBoost = d.m_nOriginalBoost;
1160 m_nBoost = d.m_nBoost;
1161 m_bAutoLabeled = d.m_bAutoLabeled;
1162 m_nImageID = d.m_nImageID;
1163 m_nVirtualID = d.m_nVirtualID;
1164 m_nGroupID = d.m_nGroupID;
1165 m_nIndex = d.m_nIndex;
1166 m_strDesc = d.m_strDesc;
1167 m_rgDataCriteria = d.m_rgDataCriteria;
1168 m_dataCriteriaFormat = d.m_dataCriteriaFormat;
1169 m_rgDebugData = d.m_rgDebugData;
1170 m_debugDataFormat = d.m_debugDataFormat;
1171 m_nSourceID = d.m_nSourceID;
1172 m_nOriginalSourceID = d.m_nOriginalSourceID;
1176 m_nAnnotationType = d.m_nAnnotationType;
1177 m_rgAnnotationGroup =
null;
1179 if (d.m_rgAnnotationGroup !=
null)
1185 m_rgAnnotationGroup.
Add(g.
Clone());
1196 m_nHeight = d.m_nHeight;
1197 m_nWidth = d.m_nWidth;
1198 m_nChannels = d.m_nChannels;
1199 m_rgByteData = d.m_rgByteData;
1200 m_bIsRealData = d.m_bIsRealData;
1201 m_rgRealDataD = d.m_rgRealDataD;
1202 m_rgRealDataF = d.m_rgRealDataF;
1218 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1232 if (m_bIsRealData && m_rgRealDataD ==
null && m_rgRealDataF ==
null)
1234 else if (!m_bIsRealData && m_rgByteData ==
null)
1240 if (m_rgRealDataD ==
null && m_rgRealDataF ==
null && m_rgByteData ==
null)
1254 int nC = m_nChannels;
1257 int nXStart = nW - nLastColumns;
1258 List<T> rg =
new List<T>();
1263 for (
int c = 0; c < nC; c++)
1265 for (
int y = 0; y < nH; y++)
1267 for (
int x = nXStart; x < nW; x++)
1269 int nIdxImg = (c * (nH * nW)) + (y * nW) + x;
1270 rg.Add((T)Convert.ChangeType(
ByteData[nIdxImg], typeof(T)));
1285 if (nLastColumsToRetain <= 0 || nLastColumsToRetain >= m_nWidth)
1288 int nC = m_nChannels;
1291 int nMaskWid = nW - nLastColumsToRetain;
1293 for (
int c = 0; c < nC; c++)
1295 for (
int y = 0; y < nH; y++)
1297 for (
int x = 0; x < nMaskWid; x++)
1299 int nIdxImg = (c * (nH * nW)) + (y * nW) + x;
1300 ByteData[nIdxImg] = (byte)nMaskingValue;
1312 public void SetData(List<byte> rgByteData,
int nLabel,
bool bAllowVirtualOverride =
false)
1314 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1315 throw new Exception(
"Cannot set the data of a virtual item!");
1318 m_bIsRealData =
false;
1319 m_rgByteData = rgByteData.ToArray();
1320 m_rgRealDataD =
null;
1321 m_rgRealDataF =
null;
1331 public void SetData(List<double> rgRealData,
int nLabel,
bool bAllowVirtualOverride =
false)
1333 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1334 throw new Exception(
"Cannot set the data of a virtual item!");
1337 m_bIsRealData =
true;
1338 m_rgByteData =
null;
1339 m_rgRealDataF =
null;
1340 m_rgRealDataD = rgRealData.ToArray();
1350 public void SetData(List<float> rgRealData,
int nLabel,
bool bAllowVirtualOverride =
false)
1352 if (!bAllowVirtualOverride && m_nVirtualID != 0)
1353 throw new Exception(
"Cannot set the data of a virtual item!");
1356 m_bIsRealData =
true;
1357 m_rgByteData =
null;
1358 m_rgRealDataD =
null;
1359 m_rgRealDataF = rgRealData.ToArray();
1374 m_rgByteData =
new byte[rgb.Length];
1375 Array.Copy(rgb, m_rgByteData, rgb.Length);
1376 m_bIsRealData =
false;
1377 m_rgRealDataD =
null;
1378 m_rgRealDataF =
null;
1392 m_rgRealDataF =
null;
1393 m_rgRealDataD =
new double[rgdf.Length];
1394 Array.Copy(rgdf, m_rgRealDataD, rgdf.Length);
1395 m_rgByteData =
null;
1396 m_bIsRealData =
true;
1410 m_rgRealDataD =
null;
1411 m_rgRealDataF =
new float[rgf.Length];
1412 Array.Copy(rgf, m_rgRealDataF, rgf.Length);
1413 m_rgByteData =
null;
1414 m_bIsRealData =
true;
1431 m_nLabel = m_nOriginalLabel;
1443 if (m_rgRealDataD !=
null)
1444 return m_rgRealDataD.Length;
1445 else if (m_rgRealDataF !=
null)
1446 return m_rgRealDataF.Length;
1448 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1451 return m_rgByteData.Length;
1462 if (m_rgRealDataD !=
null && m_rgRealDataD.Length > 0)
1465 if (m_rgRealDataF !=
null && m_rgRealDataF.Length > 0)
1482 if (m_rgRealDataD !=
null)
1483 return (T)Convert.ChangeType(m_rgRealDataD[nIdx], typeof(T));
1484 else if (m_rgRealDataF !=
null)
1485 return (T)Convert.ChangeType(m_rgRealDataF[nIdx], typeof(T));
1487 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1491 return (T)Convert.ChangeType(m_rgByteData[nIdx], typeof(T));
1504 if (m_rgRealDataD !=
null)
1505 return m_rgRealDataD[nIdx];
1506 else if (m_rgRealDataF !=
null)
1507 return m_rgRealDataF[nIdx];
1509 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1513 return m_rgByteData[nIdx];
1526 if (m_rgRealDataD !=
null)
1527 return (
float)m_rgRealDataD[nIdx];
1528 else if (m_rgRealDataF !=
null)
1529 return m_rgRealDataF[nIdx];
1531 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1535 return m_rgByteData[nIdx];
1550 if (m_rgRealDataD !=
null)
1551 dfVal = m_rgRealDataD[nIdx];
1552 else if (m_rgRealDataF !=
null)
1553 dfVal = m_rgRealDataF[nIdx];
1555 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1557 return (
byte)Math.Min(Math.Max(0, dfVal), 255);
1561 return m_rgByteData[nIdx];
1576 if (m_rgRealDataD !=
null)
1578 if (m_rgRealDataD.Length == 0)
1581 if (typeof(T) == typeof(
double))
1582 return (T[])Convert.ChangeType(m_rgRealDataD.ToArray(), typeof(T[]));
1584 T[] rg =
new T[m_rgRealDataD.Length];
1585 for (
int i = 0; i < rg.Length; i++)
1587 rg[i] = (T)Convert.ChangeType(m_rgRealDataD[i], typeof(T));
1592 else if (m_rgRealDataF !=
null)
1594 if (m_rgRealDataF.Length == 0)
1597 if (typeof(T) == typeof(
float))
1598 return (T[])Convert.ChangeType(m_rgRealDataF.ToArray(), typeof(T[]));
1600 T[] rg =
new T[m_rgRealDataF.Length];
1601 for (
int i = 0; i < rg.Length; i++)
1603 rg[i] = (T)Convert.ChangeType(m_rgRealDataF[i], typeof(T));
1615 if (m_rgByteData ==
null || m_rgByteData.Length == 0)
1618 T[] rg =
new T[m_rgByteData.Length];
1620 for (
int i = 0; i < rg.Length; i++)
1622 rg[i] = (T)Convert.ChangeType(m_rgByteData[i], typeof(T));
1639 public static byte[]
GetByteData(
byte[] rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1641 if (nImagePadX == 0 && nImagePadY == 0)
1644 return PadData<byte>(
new List<byte>(rgData), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1657 public static Tuple<double[], float[]>
GetRealData(
byte[] rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1659 Tuple<double[], float[]> rgRealData =
GetRealData(rgData);
1661 double[] rgRealDataD = rgRealData.Item1;
1662 float[] rgRealDataF = rgRealData.Item2;
1664 if (rgRealDataD !=
null)
1665 rgRealDataD = PadData<double>(rgRealDataD.ToList(), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1667 rgRealDataF = PadData<float>(rgRealDataF.ToList(), nImagePadX, nImagePadY, nHeight, nWidth, nChannels);
1669 return new Tuple<double[], float[]>(rgRealDataD, rgRealDataF);
1683 public static T[]
PadData<T>(List<T> rgData,
int nImagePadX,
int nImagePadY,
int nHeight,
int nWidth,
int nChannels)
1686 int nCount = nChannels * (nHeight * (nImagePadX + nWidth) + (nImagePadY * nImagePadX));
1687 T[] rgDataNew =
new T[nCount];
1689 for (
int c = 0; c < nChannels; c++)
1691 for (
int y = 0; y < nHeight; y++)
1693 for (
int i = 0; i < nImagePadX; i++)
1695 rgDataNew[nDstIdx] = (T)Convert.ChangeType(0.0, typeof(T));
1699 for (
int x = 0; x < nWidth; x++)
1701 int nIdx = (c * nWidth * nHeight) + (y * nWidth) + x;
1703 rgDataNew[nDstIdx] = rgData[nIdx];
1708 for (
int i = 0; i < nImagePadY; i++)
1710 for (
int x = 0; x < nWidth + nImagePadX; x++)
1712 rgDataNew[nDstIdx] = (T)Convert.ChangeType(0.0, typeof(T));
1736 if (m_rgRealDataD !=
null)
1737 return GetByteData(
new List<double>(m_rgRealDataD));
1738 else if (m_rgRealDataF !=
null)
1739 return GetByteData(
new List<float>(m_rgRealDataF));
1741 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1754 int nCount = rgData.Count;
1755 int nSize =
sizeof(double);
1758 int nDataCount =
sizeof(int) +
sizeof(
int) + (nSize * rgData.Count);
1759 byte[] rgByte =
new byte[nDataCount];
1761 byte[] rg = BitConverter.GetBytes(nCount);
1762 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1763 nOffset += rg.Length;
1765 rg = BitConverter.GetBytes(nSize);
1766 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1767 nOffset += rg.Length;
1769 foreach (
double df
in rgData)
1771 rg = BitConverter.GetBytes(df);
1772 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1773 nOffset += rg.Length;
1789 int nCount = rgData.Count;
1790 int nSize =
sizeof(float);
1793 int nDataCount =
sizeof(int) +
sizeof(
int) + (nSize * rgData.Count);
1794 byte[] rgByte =
new byte[nDataCount];
1796 byte[] rg = BitConverter.GetBytes(nCount);
1797 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1798 nOffset += rg.Length;
1800 rg = BitConverter.GetBytes(nSize);
1801 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1802 nOffset += rg.Length;
1804 foreach (
float df
in rgData)
1806 rg = BitConverter.GetBytes(df);
1807 Array.Copy(rg, 0, rgByte, nOffset, rg.Length);
1808 nOffset += rg.Length;
1821 double[] rgDataD =
null;
1822 float[] rgDataF =
null;
1825 int nCount = BitConverter.ToInt32(rgData, nIdx);
1827 int nSize = BitConverter.ToInt32(rgData, nIdx);
1831 if (nSize !=
sizeof(
float) && nSize !=
sizeof(
double))
1834 nSize =
sizeof(double);
1837 if (nSize ==
sizeof(
double))
1842 return new Tuple<double[], float[]>(rgDataD, rgDataF);
1853 List<double> rgData0 =
new List<double>();
1855 while (nIdx < rgData.Length)
1857 rgData0.Add(BitConverter.ToDouble(rgData, nIdx));
1861 return rgData0.ToArray();
1872 List<float> rgData0 =
new List<float>();
1874 while (nIdx < rgData.Length)
1876 rgData0.Add(BitConverter.ToSingle(rgData, nIdx));
1880 return rgData0.ToArray();
1892 m_nWidth != d.
Width)
1893 throw new Exception(
"Datum dimmensions do not match!");
1896 throw new Exception(
"Datum counts do not match!");
1900 d1.m_rgRealDataD =
null;
1901 d1.m_rgRealDataF =
null;
1902 d1.m_rgByteData =
null;
1906 if (m_rgRealDataD !=
null)
1908 d1.m_rgRealDataD =
new double[m_rgRealDataD.Length];
1910 for (
int i = 0; i < m_rgRealDataD.Length; i++)
1912 d1.m_rgRealDataD[i] = m_rgRealDataD[i] + d.
GetDataAtD(i);
1915 else if (m_rgRealDataF !=
null)
1917 d1.m_rgRealDataF =
new float[m_rgRealDataF.Length];
1919 for (
int i = 0; i < m_rgRealDataF.Length; i++)
1921 d1.m_rgRealDataF[i] = m_rgRealDataF[i] + d.
GetDataAtF(i);
1926 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1929 d1.m_bIsRealData =
true;
1933 d1.m_rgByteData =
new byte[m_rgByteData.Length];
1934 d1.m_bIsRealData =
false;
1936 for (
int i = 0; i < m_rgByteData.Length; i++)
1939 d1.m_rgByteData[i] = (byte)Math.Min(Math.Max(0, nVal), 255);
1955 throw new ArgumentOutOfRangeException(
"dfVal", 0,
"Cannot divide the simple datums by zero!");
1959 d1.m_rgRealDataD =
null;
1960 d1.m_rgRealDataF =
null;
1961 d1.m_rgByteData =
null;
1965 if (m_bIsRealData && !bConvertToByte)
1967 if (m_rgRealDataD !=
null)
1969 d1.m_rgRealDataD =
new double[nCount];
1970 d1.m_bIsRealData =
true;
1972 for (
int i = 0; i < nCount; i++)
1974 d1.m_rgRealDataD[i] = m_rgRealDataD[i] / dfVal;
1977 else if (m_rgRealDataF !=
null)
1979 d1.m_rgRealDataF =
new float[nCount];
1980 d1.m_bIsRealData =
true;
1982 for (
int i = 0; i < nCount; i++)
1984 d1.m_rgRealDataF[i] = (float)(m_rgRealDataF[i] / dfVal);
1989 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
1992 else if (m_bIsRealData && bConvertToByte)
1994 d1.m_rgByteData =
new byte[nCount];
1995 d1.m_bIsRealData =
false;
1997 if (m_rgRealDataD !=
null)
1999 for (
int i = 0; i < nCount; i++)
2001 double dfVal1 = m_rgRealDataD[i] / dfVal;
2002 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2005 else if (m_rgRealDataF !=
null)
2007 for (
int i = 0; i < nCount; i++)
2009 double dfVal1 = m_rgRealDataF[i] / dfVal;
2010 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2015 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2020 d1.m_rgByteData =
new byte[nCount];
2021 d1.m_bIsRealData =
false;
2023 for (
int i = 0; i < nCount; i++)
2025 double dfVal1 = (double)m_rgByteData[i] / dfVal;
2026 m_rgByteData[i] = (byte)Math.Min(Math.Max(dfVal1, 0), 255);
2038 get {
return m_nSourceID; }
2046 get {
return m_nOriginalSourceID; }
2054 get {
return m_nImageID; }
2071 get {
return m_nVirtualID; }
2079 get {
return m_nGroupID; }
2080 set { m_nGroupID = value; }
2088 get {
return m_nIndex; }
2089 set { m_nIndex = value; }
2097 get {
return m_dt; }
2098 set { m_dt = value; }
2106 get {
return m_bAutoLabeled; }
2107 set { m_bAutoLabeled = value; }
2115 get {
return m_bIsRealData; }
2123 get {
return m_nHeight; }
2131 get {
return m_nWidth; }
2139 get {
return m_nChannels; }
2147 get {
return m_nLabel; }
2155 get {
return m_nOriginalLabel; }
2156 set { m_nOriginalLabel = value; }
2164 get {
return m_rgByteData; }
2172 get {
return m_rgRealDataD; }
2180 get {
return m_rgRealDataF; }
2188 get {
return m_nBoost; }
2189 set { m_nBoost = value; }
2197 m_nBoost = m_nOriginalBoost;
2205 get {
return m_dataCriteriaFormat; }
2206 set { m_dataCriteriaFormat = value; }
2214 get {
return m_rgDataCriteria; }
2215 set { m_rgDataCriteria = value; }
2223 get {
return m_debugDataFormat; }
2224 set { m_debugDataFormat = value; }
2232 get {
return m_rgDebugData; }
2233 set { m_rgDebugData = value; }
2241 get {
return m_strDesc; }
2242 set { m_strDesc = value; }
2251 get {
return m_nAnnotationType; }
2252 set { m_nAnnotationType = value; }
2260 get {
return m_rgAnnotationGroup; }
2261 set { m_rgAnnotationGroup = value; }
2288 string strOut =
"Idx = " + m_nIndex.ToString(
"N0");
2290 strOut +=
"; Label = " + m_nLabel.ToString();
2291 strOut +=
"; Boost = " + m_nBoost.ToString();
2293 if (m_dt != DateTime.MinValue)
2294 strOut +=
"; Time = " + m_dt.ToString();
2296 if (!
string.IsNullOrEmpty(m_strDesc))
2297 strOut +=
"; Desc = " + m_strDesc;
2313 if (m_rgRealDataD !=
null)
2315 for (
int i = 0; i < m_rgRealDataD.Length && i < nMaxItems; i++)
2317 str += m_rgRealDataD[i].ToString() +
",";
2320 else if (m_rgRealDataF !=
null)
2322 for (
int i = 0; i < m_rgRealDataF.Length && i < nMaxItems; i++)
2324 str += m_rgRealDataF[i].ToString() +
",";
2329 str =
"No Real Data Found!";
2334 for (
int i = 0; i < m_rgByteData.Length && i < nMaxItems; i++)
2336 str += m_rgByteData[i].ToString() +
",";
2340 return str.TrimEnd(
',');
2353 if (m_rgByteData ==
null)
2354 throw new Exception(
"Bytemaps are only supported with byte based data.");
2356 return new Bytemap(m_nChannels, m_nHeight, m_nWidth, m_rgByteData);
2368 if (rgdfMean ==
null)
2377 rgdfMean[i] += sd.
RealDataD[i] / nTotal;
2384 rgdfMean[i] += sd.
RealDataF[i] / nTotal;
2389 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2396 rgdfMean[i] += (double)sd.
ByteData[i] / (
double)nTotal;
2412 if (rgImg.Length < 2)
2413 throw new Exception(
"There must be at least 2 images in the simple datum array.");
2418 rgSums =
new float[rgImg[0].
ByteData.Length];
2420 rgSums =
new float[rgImg[0].
RealDataD.Length];
2422 rgSums =
new float[rgImg[0].
RealDataF.Length];
2424 throw new Exception(
"No data in rgImg[0]!");
2426 Stopwatch sw =
new Stopwatch();
2435 for (
int i = 0; i < rgImg.Length && i < 100; i++)
2437 nHeight = Math.Max(nHeight, rgImg[i].
Height);
2438 nWidth = Math.Max(nWidth, rgImg[i].
Width);
2441 for (
int i = 0; i < rgImg.Length; i++)
2443 if (rgImg[i] !=
null)
2445 if (rgImg[i].
Height != nHeight || rgImg[i].
Width != nWidth)
2450 for (
int n = 0; n < rgSums.Length; n++)
2457 for (
int n = 0; n < rgSums.Length; n++)
2459 rgSums[n] += (float)rgImg[i].
RealDataD[n];
2464 for (
int n = 0; n < rgSums.Length; n++)
2466 rgSums[n] += (float)rgImg[i].
RealDataF[n];
2471 throw new Exception(
"No data in rgImg[" + i.ToString() +
"]!");
2476 if (sw.Elapsed.TotalMilliseconds > 2000)
2478 double dfPct = (double)i / (
double)rgImg.Length;
2479 log.
WriteLine(
"processing mean (" + dfPct.ToString(
"P") +
")");
2482 if (rgAbort !=
null)
2484 if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
2493 byte[] rgbMean =
new byte[rgSums.Length];
2495 for (
int n = 0; n < rgSums.Length; n++)
2497 rgbMean[n] = (byte)(rgSums[n] / (
float)nCount);
2501 d.
SetData(
new List<byte>(rgbMean), -1,
true);
2506 double[] rgdfMean =
new double[rgSums.Length];
2508 for (
int n = 0; n < rgSums.Length; n++)
2510 rgdfMean[n] = (double)rgSums[n] / nCount;
2514 d.
SetData(
new List<double>(rgdfMean), -1,
true);
2519 float[] rgfMean =
new float[rgSums.Length];
2521 for (
int n = 0; n < rgSums.Length; n++)
2523 rgfMean[n] = (float)rgSums[n] / nCount;
2527 d.
SetData(
new List<float>(rgfMean), -1,
true);
2532 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
2548 using (MemoryStream ms =
new MemoryStream())
2549 using (BinaryWriter bw =
new BinaryWriter(ms))
2551 bw.Write((
int)type);
2554 if (annotations !=
null)
2555 nCount = annotations.
Count;
2559 if (annotations !=
null)
2561 for (
int i = 0; i < annotations.
Count; i++)
2563 annotations[i].Save(bw);
2568 return ms.ToArray();
2592 if (rg ==
null || fmt !=
DATA_FORMAT.ANNOTATION_DATA)
2595 using (MemoryStream ms =
new MemoryStream(rg))
2596 using (BinaryReader br =
new BinaryReader(ms))
2601 int nCount = br.ReadInt32();
2604 for (
int i = 0; i < nCount; i++)
2622 if (m_rgAnnotationGroup ==
null)
2637 using (StreamWriter sw =
new StreamWriter(strFile +
".txt"))
2639 sw.WriteLine(
"Index = " +
Index.ToString());
2640 sw.WriteLine(
"ImageID = " +
ImageID.ToString());
2641 sw.WriteLine(
"VirtualID = " +
VirtualID.ToString());
2642 sw.WriteLine(
"Label = " +
Label.ToString());
2643 sw.WriteLine(
"AutoLabeled = " +
AutoLabeled.ToString());
2644 sw.WriteLine(
"Boost = " +
Boost.ToString());
2645 sw.WriteLine(
"SourceID = " +
SourceID.ToString());
2648 sw.WriteLine(
"Time = " +
TimeStamp.ToString());
2649 sw.WriteLine(
"Size = {1," +
Channels.ToString() +
"," +
Height.ToString() +
"," +
Width.ToString() +
"}");
2663 using (StreamReader sr =
new StreamReader(strFile))
2665 string strVal = parseValue(sr.ReadLine(),
'=');
2666 int nIndex =
int.Parse(strVal);
2668 strVal = parseValue(sr.ReadLine(),
'=');
2669 int nImageID =
int.Parse(strVal);
2671 strVal = parseValue(sr.ReadLine(),
'=');
2672 int nVirtualID =
int.Parse(strVal);
2674 strVal = parseValue(sr.ReadLine(),
'=');
2675 int nLabel =
int.Parse(strVal);
2677 strVal = parseValue(sr.ReadLine(),
'=');
2678 bool bAutoLabeled =
bool.Parse(strVal);
2680 strVal = parseValue(sr.ReadLine(),
'=');
2681 int nBoost =
int.Parse(strVal);
2683 strVal = parseValue(sr.ReadLine(),
'=');
2684 int nSrcId =
int.Parse(strVal);
2686 strVal = parseValue(sr.ReadLine(),
'=');
2687 int nOriginalSrcId =
int.Parse(strVal);
2689 strVal = parseValue(sr.ReadLine(),
'=');
2690 string strDesc = strVal;
2692 strVal = parseValue(sr.ReadLine(),
'=');
2693 DateTime dt = DateTime.Parse(strVal);
2695 strVal = parseValue(sr.ReadLine(),
'=');
2696 strVal = strVal.Trim(
'{',
'}');
2697 string[] rgstr = strVal.Split(
',');
2699 int nChannels =
int.Parse(rgstr[1]);
2700 int nHeight =
int.Parse(rgstr[2]);
2701 int nWidth =
int.Parse(rgstr[3]);
2703 return new SimpleDatum(
false, nChannels, nWidth, nHeight, nLabel, dt, nBoost, bAutoLabeled, nIndex, nVirtualID, nImageID, nSrcId, nOriginalSrcId);
2707 private static string parseValue(
string str,
char chDelim)
2709 int nPos = str.LastIndexOf(chDelim);
2713 return str.Substring(nPos + 1).Trim();
2723 string[] rgstrFiles = Directory.GetFiles(strPath,
"*.txt");
2724 List<SimpleDatum> rgData =
new List<SimpleDatum>();
2726 foreach (
string strFile
in rgstrFiles)
2742 public static float[]
Transpose(
float[] rg,
int nH,
int nW,
int nDim = 1)
2744 float[] rgT =
new float[rg.Length];
2746 for (
int i = 0; i < nH; i++)
2748 for (
int j = 0; j < nW; j++)
2750 int nSrcIdx = (i * nW + j) * nDim;
2751 int nDstIdx = (j * nH + i) * nDim;
2754 rgT[nDstIdx] = rg[nSrcIdx];
2756 Array.Copy(rg, nSrcIdx, rgT, nDstIdx, nDim);
2771 public static double[]
Transpose(
double[] rg,
int nH,
int nW,
int nDim = 1)
2773 double[] rgT =
new double[rg.Length];
2775 for (
int i = 0; i < nH; i++)
2777 for (
int j = 0; j < nW; j++)
2779 int nSrcIdx = (i * nW + j) * nDim;
2780 int nDstIdx = (j * nH + i) * nDim;
2783 rgT[nDstIdx] = rg[nSrcIdx];
2785 Array.Copy(rg, nSrcIdx, rgT, nDstIdx, nDim);
2800 List<int> m_rgShape;
2801 object m_tag =
null;
2811 m_strName = strName;
2814 m_rgShape =
new List<int>() { nCount };
2816 if (rgShape !=
null)
2817 m_rgShape.AddRange(rgShape);
2825 get {
return m_tag; }
2826 set { m_tag = value; }
2834 get {
return m_rgShape; }
2842 get {
return m_strName; }
2843 set { m_strName = value; }
2851 get {
return m_rgItems.Count(); }
2861 get {
return m_rgItems[nIdx]; }
2862 set { m_rgItems[nIdx] = value; }
2871 return (IEnumerator<SimpleDatum>)m_rgItems.GetEnumerator();
2874 IEnumerator IEnumerable.GetEnumerator()
2876 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 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.