6using System.Collections.Generic;
10using System.Threading.Tasks;
52 float fNewHeight = p.
height;
53 float fNewWidth = p.
width;
54 float fOrigAspect = (float)nOldWidth / (
float)nOldHeight;
55 float fNewAspect = fNewWidth / fNewHeight;
57 float fxmin = bbox.
xmin * nOldWidth;
58 float fymin = bbox.
ymin * nOldHeight;
59 float fxmax = bbox.
xmax * nOldWidth;
60 float fymax = bbox.
ymax * nOldHeight;
66 fxmin = (float)Math.Max(0.0, fxmin * fNewWidth / nOldWidth);
67 fxmax = (float)Math.Min(fNewWidth, fxmax * fNewWidth / nOldWidth);
68 fymin = (float)Math.Max(0.0, fymin * fNewHeight / nOldHeight);
69 fymax = (float)Math.Min(fNewHeight, fymax * fNewHeight / nOldHeight);
73 if (fOrigAspect > fNewAspect)
75 fPadding = (fNewHeight - fNewWidth / fOrigAspect) / 2;
76 fxmin = (float)Math.Max(0.0, fxmin * fNewWidth / nOldWidth);
77 fxmax = (float)Math.Min(fNewWidth, fxmax * fNewWidth / nOldWidth);
78 fymin = fymin * (fNewHeight - 2 * fPadding) / nOldHeight;
79 fymin = fPadding + Math.Max(0, fymin);
80 fymax = fymax * (fNewHeight - 2 * fPadding) / nOldHeight;
81 fymax = fPadding + Math.Min(fNewHeight, fymax);
85 fPadding = (fNewWidth - fOrigAspect * fNewHeight) / 2;
86 fxmin = fxmin * (fNewWidth - 2 * fPadding) / nOldWidth;
87 fxmin = fPadding + Math.Max(0, fxmin);
88 fxmax = fxmax * (fNewWidth - 2 * fPadding) / nOldWidth;
89 fxmax = fPadding + Math.Min(fNewWidth, fxmax);
90 fymin = (float)Math.Max(0.0, fymin * fNewHeight / nOldHeight);
91 fymax = (float)Math.Min(fNewHeight, fymax * fNewHeight / nOldHeight);
96 if (fOrigAspect < fNewAspect)
97 fNewHeight = fNewWidth / fOrigAspect;
99 fNewWidth = fOrigAspect * fNewHeight;
101 fxmin = (float)Math.Max(0.0, fxmin * fNewWidth / nOldWidth);
102 fxmax = (float)Math.Min(fNewWidth, fxmax * fNewWidth / nOldWidth);
103 fymin = (float)Math.Max(0.0, fymin * fNewHeight / nOldHeight);
104 fymax = (float)Math.Min(fNewHeight, fymax * fNewHeight / nOldHeight);
112 bbox.
xmin = fxmin / fNewWidth;
113 bbox.
ymin = fymin / fNewHeight;
114 bbox.
xmax = fxmax / fNewWidth;
115 bbox.
ymax = fymax / fNewHeight;
130 int height = (int)p.
height;
131 int width = (
int)p.
width;
132 float fOrigAspect = (float)nOldWidth / (
float)nOldHeight;
133 float fAspect = (float)width / (
float)height;
144 if (fOrigAspect < fAspect)
145 height = (int)(width / fOrigAspect);
147 width = (int)(fOrigAspect * height);
159 private float getRandom(
float fMin,
float fMax,
float fTotal = 256)
161 float fRange = fMax - fMin;
162 double dfVal = m_random.NextDouble();
163 double dfPct = ((fMin + (float)(fRange * dfVal)) / fTotal);
165 return 1.0f + (float)dfPct;
168 private Bitmap randomBrightness(Bitmap bmp,
float fProb,
float fDelta)
170 if (m_random.NextDouble() < fProb)
172 float fBrightness = getRandom(-fDelta, fDelta);
181 private Bitmap randomContrast(Bitmap bmp,
float fProb,
float fLower,
float fUpper)
183 if (m_random.NextDouble() < fProb)
185 float fContrast = getRandom(fLower, fUpper);
194 private Bitmap randomSaturation(Bitmap bmp,
float fProb,
float fLower,
float fUpper)
196 if (m_random.NextDouble() < fProb)
198 float fSaturation = getRandom(fLower, fUpper);
207 private Bitmap randomBrightnessContrastSaturation(Bitmap bmp,
float fProbBrightness,
float fBrightnessDelta,
float fProbContrast,
float fLowerContrast,
float fUpperContrast,
float fProbSaturation,
float fLowerSaturation,
float fUpperSaturation)
209 float fBrightness = 1;
211 float fSaturation = 1;
213 if (m_random.NextDouble() < fProbBrightness)
214 fBrightness = getRandom(-fBrightnessDelta, fBrightnessDelta);
216 if (m_random.NextDouble() < fProbContrast)
217 fContrast = getRandom(fLowerContrast, fUpperContrast);
219 if (m_random.NextDouble() < fProbSaturation)
220 fSaturation = getRandom(fLowerSaturation, fUpperSaturation);
222 if (fBrightness == 0 && fContrast == 1 && fSaturation == 1)
231 private Bitmap randomBrightnessSaturationContrast(Bitmap bmp,
float fProbBrightness,
float fBrightnessDelta,
float fProbContrast,
float fLowerContrast,
float fUpperContrast,
float fProbSaturation,
float fLowerSaturation,
float fUpperSaturation)
233 float fBrightness = 1;
235 float fSaturation = 1;
237 if (m_random.NextDouble() < fProbBrightness)
238 fBrightness = getRandom(-fBrightnessDelta, fBrightnessDelta);
240 if (m_random.NextDouble() < fProbContrast)
241 fContrast = getRandom(fLowerContrast, fUpperContrast);
243 if (m_random.NextDouble() < fProbSaturation)
244 fSaturation = getRandom(fLowerSaturation, fUpperSaturation);
246 if (fBrightness == 0 && fContrast == 1 && fSaturation == 1)
263 private void randomBrightnessContrastSaturation(
SimpleDatum sd,
float fProbBrightness,
float fBrightnessDelta,
float fProbContrast,
float fLowerContrast,
float fUpperContrast,
float fProbSaturation,
float fLowerSaturation,
float fUpperSaturation,
ImageTools.
ADJUSTCONTRAST_ORDERING ordering)
265 float fBrightness = 1;
267 float fSaturation = 1;
269 if (m_random.NextDouble() < fProbBrightness)
270 fBrightness = getRandom(-fBrightnessDelta, fBrightnessDelta);
272 if (m_random.NextDouble() < fProbContrast)
273 fContrast = getRandom(fLowerContrast, fUpperContrast);
275 if (m_random.NextDouble() < fProbSaturation)
276 fSaturation = getRandom(fLowerSaturation, fUpperSaturation);
278 if (fBrightness == 0 && fContrast == 1 && fSaturation == 1)
286 if (m_random.NextDouble() < fProb)
294 List<double[]> rgrgData =
new List<double[]>();
295 List<int> rgIdx =
new List<int>();
297 for (
int i = 0; i < sd.
Channels; i++)
299 double[] rgData =
new double[nCount];
300 Array.Copy(sd.
RealDataD, nOffset, rgData, 0, nCount);
301 rgrgData.Add(rgData);
306 List<int> rgOrder =
new List<int>();
309 int nIdx = m_random.Next(sd.
Channels);
310 if (!rgOrder.Contains(nIdx))
315 for (
int i = 0; i < sd.
Channels; i++)
317 int nIdx = rgOrder[i];
318 Array.Copy(rgrgData[nIdx], 0, sd.
RealDataD, nOffset, nCount);
326 List<float[]> rgrgData =
new List<float[]>();
327 List<int> rgIdx =
new List<int>();
329 for (
int i = 0; i < sd.
Channels; i++)
331 float[] rgData =
new float[nCount];
332 Array.Copy(sd.
RealDataF, nOffset, rgData, 0, nCount);
333 rgrgData.Add(rgData);
338 List<int> rgOrder =
new List<int>();
341 int nIdx = m_random.Next(sd.
Channels);
342 if (!rgOrder.Contains(nIdx))
347 for (
int i = 0; i < sd.
Channels; i++)
349 int nIdx = rgOrder[i];
350 Array.Copy(rgrgData[nIdx], 0, sd.
RealDataF, nOffset, nCount);
356 throw new Exception(
"SimpleDatum: Both the RealDataD and RealDataF are null!");
363 List<byte[]> rgrgData =
new List<byte[]>();
364 List<int> rgIdx =
new List<int>();
366 for (
int i = 0; i < sd.
Channels; i++)
368 byte[] rgData =
new byte[nCount];
369 Array.Copy(sd.
ByteData, nOffset, rgData, 0, nCount);
370 rgrgData.Add(rgData);
375 List<int> rgOrder =
new List<int>();
378 int nIdx = m_random.Next(sd.
Channels);
379 if (!rgOrder.Contains(nIdx))
384 for (
int i = 0; i < sd.
Channels; i++)
386 int nIdx = rgOrder[i];
387 Array.Copy(rgrgData[nIdx], 0, sd.
ByteData, nOffset, nCount);
404 double dfProb = m_random.NextDouble();
428 double dfProb = m_random.NextDouble();
448 m_log.
WriteLine(
"WARNING: noise application not yet implemented.");
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
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.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
The NormalizedBBox manages a bounding box used in SSD.
float ymax
Get/set the y maximum.
float xmax
Get/set the x maximum.
NormalizedBBox Clone()
Return a copy of the object.
float xmin
Get/set the x minimum.
float ymin
Get/set the y minimum.
The SimpleDatum class holds a data input within host memory.
void CopyData(SimpleDatum d)
Copy just the data from another SimpleDatum, making sure to update the C x H x W dimensions and IsRea...
int ItemCount
Returns the number of data items.
void SetData(SimpleDatum d)
Set the data of the current SimpleDatum by copying the data of another.
int Channels
Return the number of channels of the data.
bool IsRealData
Returns whether or not the data contains real numbers or byte data.
float[] RealDataF
Return the float data. This field is valid when IsRealData = true.
int Width
Return the width of the data.
byte[] ByteData
Return the byte data. This field is valid when IsRealData = false.
int Height
Return the height of the data.
double[] RealDataD
Return the double data. This field is valid when IsRealData = true.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Specifies the parameters for the DistortionParameter used with SSD.
float contrast_lower
Get/set lower bound for random contrast factor (default = 0.5).
float random_order_prob
Get/set the probability of randomly ordering the image channels (default = 0).
float brightness_delta
Get/set amount to add to the pixel values within [-delta,delta] (default = 0)
float saturation_prob
Get/set probability of adjusting the saturation (default = 0).
float saturation_lower
Get/set lower bound for random saturation factor (default = 0.5).
float saturation_upper
Get/set upper bound for random saturation factor (default = 1.5).
float brightness_prob
Get/set probability of adjusting the brightness (default = 0).
float contrast_prob
Get/set probability of adjusting the contrast (default = 0).
float contrast_upper
Get/set upper bound for random contrast factor (default = 1.5).
Specifies the parameters for the NoiseParameter used with SSD.
Specifies the parameters for the ResizeParameter for use with SSD.
uint height
Get/set the resizing height.
uint width
Get/set the resizing width.
ResizeMode
Defines the resizing mode.
ResizeMode resize_mode
Get/set the resizing mode.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.data namespace contains dataset creators used to create common testing datasets such as M...
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...