MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ImageData.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Drawing;
6using System.IO;
7
8namespace MyCaffe.basecode
9{
13 public class ImageData
14 {
23 public static Datum GetImageData(Bitmap bmp, SimpleDatum sd, bool? bIsDataRealOverride = null, int[] rgFocusMap = null)
24 {
25 if (!bIsDataRealOverride.HasValue)
26 bIsDataRealOverride = sd.IsRealData;
27
28 if (sd.RealDataD != null || sd.ByteData != null)
29 return GetImageDataD(bmp, sd.Channels, bIsDataRealOverride.Value, sd.Label, true, rgFocusMap);
30 else
31 return GetImageDataF(bmp, sd.Channels, bIsDataRealOverride.Value, sd.Label, true, rgFocusMap);
32 }
33
44 public static Datum GetImageDataD(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap = true, int[] rgFocusMap = null)
45 {
46 if (nChannels != 1 && nChannels != 3)
47 throw new Exception("Images only support either 1 or 3 channels.");
48
49 List<byte>[] rgrgByteData = new List<byte>[nChannels];
50 List<double>[] rgrgRealData = new List<double>[nChannels];
51
52 for (int i = 0; i < nChannels; i++)
53 {
54 rgrgByteData[i] = new List<byte>();
55 rgrgRealData[i] = new List<double>();
56 }
57
58 if (bmp.Width >= bmp.Height && bUseLockBitmap)
59 {
60 LockBitmap bmp1 = new LockBitmap(bmp);
61
62 try
63 {
64 bmp1.LockBits();
65 for (int y = 0; y < bmp1.Height; y++)
66 {
67 for (int x = 0; x < bmp1.Width; x++)
68 {
69 int nFocus = 1;
70
71 if (rgFocusMap != null)
72 {
73 int nIdx = y * bmp1.Width + x;
74 nFocus = rgFocusMap[nIdx];
75 }
76
77 Color clr = (nFocus == 1) ? bmp1.GetPixel(x, y) : Color.Black;
78
79 if (nChannels == 1)
80 {
81 if (bDataIsReal)
82 rgrgRealData[0].Add(clr.ToArgb());
83 else
84 rgrgByteData[0].Add((byte)((clr.R * 0.3) + (clr.G * 0.59) + (clr.B * 0.11)));
85 }
86 else
87 {
88 if (bDataIsReal)
89 {
90 rgrgRealData[0].Add(clr.R);
91 rgrgRealData[1].Add(clr.G);
92 rgrgRealData[2].Add(clr.B);
93 }
94 else
95 {
96 rgrgByteData[0].Add(clr.R);
97 rgrgByteData[1].Add(clr.G);
98 rgrgByteData[2].Add(clr.B);
99 }
100 }
101 }
102 }
103 }
104 catch (Exception excpt)
105 {
106 throw excpt;
107 }
108 finally
109 {
110 bmp1.UnlockBits();
111 }
112 }
113 // LockBitmap currently has a bug with images were bmp.Width < bmp.Height so in this case we use the slower Bitmap.GetPixel.
114 else
115 {
116 for (int y = 0; y < bmp.Height; y++)
117 {
118 for (int x = 0; x < bmp.Width; x++)
119 {
120 int nFocus = 1;
121
122 if (rgFocusMap != null)
123 {
124 int nIdx = y * bmp.Width + x;
125 nFocus = rgFocusMap[nIdx];
126 }
127
128 Color clr = (nFocus == 1) ? bmp.GetPixel(x, y) : Color.Black;
129
130 if (nChannels == 1)
131 {
132 if (bDataIsReal)
133 rgrgRealData[0].Add(clr.ToArgb());
134 else
135 rgrgByteData[0].Add((byte)((clr.R * 0.3) + (clr.G * 0.59) + (clr.B * 0.11)));
136 }
137 else
138 {
139 if (bDataIsReal)
140 {
141 rgrgRealData[0].Add(clr.R);
142 rgrgRealData[1].Add(clr.G);
143 rgrgRealData[2].Add(clr.B);
144 }
145 else
146 {
147 rgrgByteData[0].Add(clr.R);
148 rgrgByteData[1].Add(clr.G);
149 rgrgByteData[2].Add(clr.B);
150 }
151 }
152 }
153 }
154 }
155
156 List<byte> rgByteData = new List<byte>();
157 List<double> rgRealData = new List<double>();
158
159 for (int i = 0; i < nChannels; i++)
160 {
161 rgByteData.AddRange(rgrgByteData[i]);
162 rgRealData.AddRange(rgrgRealData[i]);
163 }
164
165 if (bDataIsReal)
166 return new Datum(true, nChannels, bmp.Width, bmp.Height, nLabel, DateTime.MinValue, new List<double>(rgRealData), 0, false, -1);
167 else
168 return new Datum(false, nChannels, bmp.Width, bmp.Height, nLabel, DateTime.MinValue, new List<byte>(rgByteData), 0, false, -1);
169 }
170
181 public static Datum GetImageDataF(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap = true, int[] rgFocusMap = null)
182 {
183 if (nChannels != 1 && nChannels != 3)
184 throw new Exception("Images only support either 1 or 3 channels.");
185
186 List<byte>[] rgrgByteData = new List<byte>[nChannels];
187 List<float>[] rgrgRealData = new List<float>[nChannels];
188
189 for (int i = 0; i < nChannels; i++)
190 {
191 rgrgByteData[i] = new List<byte>();
192 rgrgRealData[i] = new List<float>();
193 }
194
195 if (bmp.Width >= bmp.Height && bUseLockBitmap)
196 {
197 LockBitmap bmp1 = new LockBitmap(bmp);
198
199 try
200 {
201 bmp1.LockBits();
202 for (int y = 0; y < bmp1.Height; y++)
203 {
204 for (int x = 0; x < bmp1.Width; x++)
205 {
206 int nFocus = 1;
207
208 if (rgFocusMap != null)
209 {
210 int nIdx = y * bmp1.Width + x;
211 nFocus = rgFocusMap[nIdx];
212 }
213
214 Color clr = (nFocus == 1) ? bmp1.GetPixel(x, y) : Color.Black;
215
216 if (nChannels == 1)
217 {
218 if (bDataIsReal)
219 rgrgRealData[0].Add(clr.ToArgb());
220 else
221 rgrgByteData[0].Add((byte)((clr.R * 0.3) + (clr.G * 0.59) + (clr.B * 0.11)));
222 }
223 else
224 {
225 if (bDataIsReal)
226 {
227 rgrgRealData[0].Add(clr.R);
228 rgrgRealData[1].Add(clr.G);
229 rgrgRealData[2].Add(clr.B);
230 }
231 else
232 {
233 rgrgByteData[0].Add(clr.R);
234 rgrgByteData[1].Add(clr.G);
235 rgrgByteData[2].Add(clr.B);
236 }
237 }
238 }
239 }
240 }
241 catch (Exception excpt)
242 {
243 throw excpt;
244 }
245 finally
246 {
247 bmp1.UnlockBits();
248 }
249 }
250 // LockBitmap currently has a bug with images were bmp.Width < bmp.Height so in this case we use the slower Bitmap.GetPixel.
251 else
252 {
253 for (int y = 0; y < bmp.Height; y++)
254 {
255 for (int x = 0; x < bmp.Width; x++)
256 {
257 int nFocus = 1;
258
259 if (rgFocusMap != null)
260 {
261 int nIdx = y * bmp.Width + x;
262 nFocus = rgFocusMap[nIdx];
263 }
264
265 Color clr = (nFocus == 1) ? bmp.GetPixel(x, y) : Color.Black;
266
267 if (nChannels == 1)
268 {
269 if (bDataIsReal)
270 rgrgRealData[0].Add(clr.ToArgb());
271 else
272 rgrgByteData[0].Add((byte)((clr.R * 0.3) + (clr.G * 0.59) + (clr.B * 0.11)));
273 }
274 else
275 {
276 if (bDataIsReal)
277 {
278 rgrgRealData[0].Add(clr.R);
279 rgrgRealData[1].Add(clr.G);
280 rgrgRealData[2].Add(clr.B);
281 }
282 else
283 {
284 rgrgByteData[0].Add(clr.R);
285 rgrgByteData[1].Add(clr.G);
286 rgrgByteData[2].Add(clr.B);
287 }
288 }
289 }
290 }
291 }
292
293 List<byte> rgByteData = new List<byte>();
294 List<float> rgRealData = new List<float>();
295
296 for (int i = 0; i < nChannels; i++)
297 {
298 rgByteData.AddRange(rgrgByteData[i]);
299 rgRealData.AddRange(rgrgRealData[i]);
300 }
301
302 if (bDataIsReal)
303 return new Datum(true, nChannels, bmp.Width, bmp.Height, nLabel, DateTime.MinValue, new List<float>(rgRealData), 0, false, -1);
304 else
305 return new Datum(false, nChannels, bmp.Width, bmp.Height, nLabel, DateTime.MinValue, new List<byte>(rgByteData), 0, false, -1);
306 }
307
319 public static Datum GetImageData<T>(T[] rgData, int nChannels, int nHeight, int nWidth, bool bDataIsReal, int nStartIdx = 0, int nCount = -1)
320 {
321 if (nCount == -1)
322 nCount = rgData.Length;
323
324 if (nChannels != 1 && nChannels != 3)
325 throw new Exception("Images only support either 1 or 3 channels.");
326
327 if (bDataIsReal)
328 {
329 if (typeof(T) == typeof(double))
330 {
331 double[] rgRealData = (double[])Convert.ChangeType(rgData, typeof(double[]));
332 return new Datum(true, nChannels, nWidth, nHeight, 0, DateTime.MinValue, new List<double>(rgRealData), 0, false, -1);
333 }
334 else if (typeof(T) == typeof(float))
335 {
336 float[] rgRealData = (float[])Convert.ChangeType(rgData, typeof(float[]));
337 return new Datum(true, nChannels, nWidth, nHeight, 0, DateTime.MinValue, new List<float>(rgRealData), 0, false, -1);
338 }
339 else
340 {
341 throw new Exception("Unsupported type '" + typeof(T).ToString() + " - only 'double' and 'float' are supported.");
342 }
343 }
344 else
345 {
346 List<byte> rgByteData = new List<byte>();
347 float[] rgDataF = Utility.ConvertVecF<T>(rgData);
348
349 for (int i = nStartIdx; i < nStartIdx + nCount; i++)
350 {
351 float fVal = rgDataF[i];
352
353 if (float.IsInfinity(fVal) || float.IsNaN(fVal))
354 fVal = 0;
355
356 rgByteData.Add((byte)fVal);
357 }
358
359 return new Datum(false, nChannels, nWidth, nHeight, 0, DateTime.MinValue, new List<byte>(rgByteData), 0, false, -1);
360 }
361 }
362
371 public static Bitmap GetImageAtChannel(SimpleDatum d, int nChannel, ColorMapper clrMap = null, List<int> rgClrOrder = null)
372 {
373 if (d.Channels != 1 && d.Channels != 3)
374 throw new Exception("Standard images only support either 1 or 3 channels.");
375
376 Bitmap bmp = new Bitmap(d.Width, d.Height);
377 List<byte>[] rgrgByteData = new List<byte>[d.Channels];
378 List<double>[] rgrgRealData = new List<double>[d.Channels];
379 int nOffset = 0;
380 int nCount = d.Height * d.Width;
381 bool bDataIsReal = d.HasRealData;
382 double dfMin = 1;
383 double dfMax = 0;
384
385
386 for (int i = 0; i < d.Channels; i++)
387 {
388 List<byte> rgByteData = new List<byte>();
389 List<double> rgRealData = new List<double>();
390 int nChIdx = i;
391
392 if (rgClrOrder != null)
393 nChIdx = rgClrOrder[i];
394
395 if (bDataIsReal)
396 {
397 for (int j = 0; j < nCount; j++)
398 {
399 double dfVal = d.GetDataAtD(nOffset + j);
400 dfMin = Math.Min(dfMin, dfVal);
401 dfMax = Math.Max(dfMax, dfVal);
402 rgRealData.Add(dfVal);
403 }
404
405 rgrgRealData[nChIdx] = rgRealData;
406 }
407 else
408 {
409 for (int j = 0; j < nCount; j++)
410 {
411 rgByteData.Add(d.ByteData[nOffset + j]);
412 }
413
414 rgrgByteData[nChIdx] = rgByteData;
415 }
416
417 nOffset += nCount;
418 }
419
420 LockBitmap bmp1 = new LockBitmap(bmp);
421
422 try
423 {
424 bmp1.LockBits();
425
426 for (int y = 0; y < bmp1.Height; y++)
427 {
428 for (int x = 0; x < bmp1.Width; x++)
429 {
430 Color clr;
431 int nIdx = (y * bmp1.Width) + x;
432
433 if (d.Channels == 1)
434 {
435 if (bDataIsReal)
436 {
437 if (dfMin >= 0 && dfMax <= 1.0)
438 {
439 int nG = (int)(rgrgRealData[0][nIdx] * 255.0);
440 if (nG < 0)
441 nG = 0;
442 if (nG > 255)
443 nG = 255;
444
445 clr = Color.FromArgb(nG, nG, nG);
446 }
447 else
448 {
449 clr = Color.FromArgb((int)rgrgRealData[0][nIdx]);
450 }
451
452 if (clrMap != null)
453 clr = clrMap.GetColor(clr.ToArgb());
454 }
455 else
456 {
457 clr = Color.FromArgb((int)rgrgByteData[0][nIdx], (int)rgrgByteData[0][nIdx], (int)rgrgByteData[0][nIdx]);
458 }
459 }
460 else
461 {
462 if (bDataIsReal)
463 {
464 int nR = (nChannel == 0) ? (int)rgrgRealData[0][nIdx] : 0;
465 int nG = (nChannel == 1) ? (int)rgrgRealData[1][nIdx] : 0;
466 int nB = (nChannel == 2) ? (int)rgrgRealData[2][nIdx] : 0;
467
468 clr = Color.FromArgb(nR, nG, nB);
469
470 if (clrMap != null)
471 clr = clrMap.GetColor(clr.ToArgb());
472 }
473 else
474 {
475 int nR = (nChannel == 0) ? (int)rgrgByteData[0][nIdx] : 0;
476 int nG = (nChannel == 1) ? (int)rgrgByteData[1][nIdx] : 0;
477 int nB = (nChannel == 2) ? (int)rgrgByteData[2][nIdx] : 0;
478
479 clr = Color.FromArgb(nR, nG, nB);
480 }
481 }
482
483 bmp1.SetPixel(x, y, clr);
484 }
485 }
486 }
487 catch (Exception excpt)
488 {
489 throw excpt;
490 }
491 finally
492 {
493 bmp1.UnlockBits();
494 }
495
496 return bmp;
497 }
498
506 public static Bitmap GetImage(SimpleDatum d, ColorMapper clrMap = null, List<int> rgClrOrder = null)
507 {
508 if (d.Channels != 1 && d.Channels != 3)
509 throw new Exception("Standard images only support either 1 or 3 channels.");
510
511 Bitmap bmp = new Bitmap(d.Width, d.Height);
512 List<byte>[] rgrgByteData = new List<byte>[d.Channels];
513 List<double>[] rgrgRealData = new List<double>[d.Channels];
514 int nOffset = 0;
515 int nCount = d.Height * d.Width;
516 bool bDataIsReal = d.HasRealData;
517 double dfMin = 1;
518 double dfMax = 0;
519
520
521 for (int i = 0; i < d.Channels; i++)
522 {
523 List<byte> rgByteData = new List<byte>();
524 List<double> rgRealData = new List<double>();
525 int nChIdx = i;
526
527 if (rgClrOrder != null)
528 nChIdx = rgClrOrder[i];
529
530 if (bDataIsReal)
531 {
532 for (int j = 0; j < nCount; j++)
533 {
534 double dfVal = d.GetDataAtD(nOffset + j);
535 dfMin = Math.Min(dfMin, dfVal);
536 dfMax = Math.Max(dfMax, dfVal);
537 rgRealData.Add(dfVal);
538 }
539
540 rgrgRealData[nChIdx] = rgRealData;
541 }
542 else
543 {
544 for (int j = 0; j < nCount; j++)
545 {
546 rgByteData.Add(d.ByteData[nOffset + j]);
547 }
548
549 rgrgByteData[nChIdx] = rgByteData;
550 }
551
552 nOffset += nCount;
553 }
554
555 LockBitmap bmp1 = new LockBitmap(bmp);
556
557 try
558 {
559 bmp1.LockBits();
560
561 for (int y = 0; y < bmp1.Height; y++)
562 {
563 for (int x = 0; x < bmp1.Width; x++)
564 {
565 Color clr;
566 int nIdx = (y * bmp1.Width) + x;
567
568 if (d.Channels == 1)
569 {
570 if (bDataIsReal)
571 {
572 if (dfMin >= 0 && dfMax <= 1.0)
573 {
574 int nG = clip((int)(rgrgRealData[0][nIdx] * 255.0), 0, 255);
575 clr = Color.FromArgb(nG, nG, nG);
576 }
577 else
578 {
579 clr = Color.FromArgb((int)rgrgRealData[0][nIdx]);
580 }
581
582 if (clrMap != null)
583 clr = clrMap.GetColor(clr.ToArgb());
584 }
585 else
586 {
587 int nR = clip((int)rgrgByteData[0][nIdx], 0, 255);
588 int nG = clip((int)rgrgByteData[0][nIdx], 0, 255);
589 int nB = clip((int)rgrgByteData[0][nIdx], 0, 255);
590
591 clr = Color.FromArgb(nR, nG, nB);
592 }
593 }
594 else
595 {
596 if (bDataIsReal)
597 {
598 int nR = clip((int)rgrgRealData[0][nIdx], 0, 255);
599 int nG = clip((int)rgrgRealData[1][nIdx], 0, 255);
600 int nB = clip((int)rgrgRealData[2][nIdx], 0, 255);
601
602 clr = Color.FromArgb(nR, nG, nB);
603
604 if (clrMap != null)
605 clr = clrMap.GetColor(clr.ToArgb());
606 }
607 else
608 {
609 int nR = clip((int)rgrgByteData[0][nIdx], 0, 255);
610 int nG = clip((int)rgrgByteData[1][nIdx], 0, 255);
611 int nB = clip((int)rgrgByteData[2][nIdx], 0, 255);
612
613 clr = Color.FromArgb(nR, nG, nB);
614 }
615 }
616
617 bmp1.SetPixel(x, y, clr);
618 }
619 }
620 }
621 catch (Exception excpt)
622 {
623 throw excpt;
624 }
625 finally
626 {
627 bmp1.UnlockBits();
628 }
629
630 return bmp;
631 }
632
633 private static int clip(int n, int nMin, int nMax)
634 {
635 if (n < nMin)
636 return nMin;
637
638 if (n > nMax)
639 return nMax;
640
641 return n;
642 }
643
651 public static Bitmap GetImage(List<Result> rg, Size sz, ColorMapper clrMap)
652 {
653 Bitmap bmp = new Bitmap(sz.Width, sz.Height);
654 int nSize = (int)Math.Ceiling(Math.Sqrt(rg.Count));
655 float fX = 0;
656 float fY = 0;
657 float fIncX = (float)sz.Width / (float)nSize;
658 float fIncY = (float)sz.Height / (float)nSize;
659
660 using (Graphics g = Graphics.FromImage(bmp))
661 {
662 g.FillRectangle(Brushes.Black, new RectangleF(0, 0, bmp.Width, bmp.Height));
663
664 for (int i=0; i<rg.Count; i++)
665 {
666 Brush br = new SolidBrush(clrMap.GetColor(rg[i].Score));
667 g.FillRectangle(br, fX, fY, fIncX, fIncY);
668 br.Dispose();
669
670 fX += fIncX;
671
672 if (fX >= bmp.Width)
673 {
674 fX = 0;
675 fY += fIncY;
676 }
677 }
678 }
679
680 return bmp;
681 }
682
683 private static double getColorAverage(Bitmap bmp, int nRow)
684 {
685 double dfColorTotal = 0;
686
687 for (int x = 0; x < bmp.Width; x++)
688 {
689 Color clr = bmp.GetPixel(x, nRow);
690
691 dfColorTotal += clr.R;
692 dfColorTotal += clr.B;
693 dfColorTotal += clr.G;
694 }
695
696 return dfColorTotal / bmp.Width;
697 }
698
699 private static void offsetInward(Bitmap bmp, ref int nYBottom, ref int nYTop, int nSegmentHeight)
700 {
701 double dfAve1;
702 double dfAve2;
703
704 while (nYBottom - nYTop > nSegmentHeight)
705 {
706 dfAve1 = getColorAverage(bmp, nYBottom - 1);
707
708 if (dfAve1 == 0)
709 nYBottom--;
710
711 if (nYBottom - nYTop > nSegmentHeight)
712 {
713 dfAve2 = getColorAverage(bmp, nYTop);
714
715 if (dfAve2 == 0 || dfAve2 < dfAve1)
716 nYTop++;
717 else
718 nYBottom--;
719
720 if (dfAve1 > 0 && dfAve2 > 0)
721 break;
722 }
723 }
724 }
725
726 private static double[] getImageData(Bitmap bmp, int nYBottom, int nYTop, int nSegmentHeight)
727 {
728 double[] rgrgData = new double[nSegmentHeight * bmp.Width];
729
730 offsetInward(bmp, ref nYBottom, ref nYTop, nSegmentHeight);
731
732 for (int y = 0; y < nSegmentHeight; y++)
733 {
734 for (int x = 0; x < bmp.Width; x++)
735 {
736 Color clr = bmp.GetPixel(x, y + nYTop);
737
738 int nDataIdx = (y * bmp.Width) + x;
739 int nR = clr.R;
740 int nG = clr.G;
741 int nB = clr.B;
742 int nColor = (nR << 16) + (nG << 8) + nB;
743 double dfClr = (double)nColor / (double)0xFFFFFF;
744
745 rgrgData[nDataIdx] = dfClr;
746 }
747 }
748
749 return rgrgData;
750 }
751
758 public static int[] LoadFocusMap(string strImgFile)
759 {
760 if (string.IsNullOrEmpty(strImgFile) || !File.Exists(strImgFile))
761 return null;
762
763 Bitmap bmpFocus = null;
764
765 bmpFocus = new Bitmap(strImgFile);
766 int[] rgnFocusMap = new int[bmpFocus.Width * bmpFocus.Height];
767
768 for (int y = 0; y < bmpFocus.Height; y++)
769 {
770 for (int x = 0; x < bmpFocus.Width; x++)
771 {
772 Color clr = bmpFocus.GetPixel(x, y);
773 if (clr.R != 0 || clr.G != 0 || clr.R != 0)
774 rgnFocusMap[y * bmpFocus.Width + x] = 1;
775 }
776 }
777
778 bmpFocus.Dispose();
779
780 return rgnFocusMap;
781 }
782 }
783}
The ColorMapper maps a value within a number range, to a Color within a color scheme.
Definition: ColorMapper.cs:14
Color GetColor(double dfVal)
Find the color using a binary search algorithm.
Definition: ColorMapper.cs:350
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
Definition: Datum.cs:12
The ImageData class is a helper class used to convert between Datum, other raw data,...
Definition: ImageData.cs:14
static int[] LoadFocusMap(string strImgFile)
Load a black/white image as a focus map where any area not colored black is attributed focus....
Definition: ImageData.cs:758
static Datum GetImageData< T >(T[] rgData, int nChannels, int nHeight, int nWidth, bool bDataIsReal, int nStartIdx=0, int nCount=-1)
The GetImageData function converts an array of type 'T' into a Datum.
Definition: ImageData.cs:319
static Datum GetImageData(Bitmap bmp, SimpleDatum sd, bool? bIsDataRealOverride=null, int[] rgFocusMap=null)
The GetImageData function converts a Bitmap into a Datum.
Definition: ImageData.cs:23
static Bitmap GetImage(SimpleDatum d, ColorMapper clrMap=null, List< int > rgClrOrder=null)
Converts a SimplDatum (or Datum) into an image, optionally using a ColorMapper.
Definition: ImageData.cs:506
static Bitmap GetImageAtChannel(SimpleDatum d, int nChannel, ColorMapper clrMap=null, List< int > rgClrOrder=null)
Converts a SimplDatum (or Datum) into an image, optionally using a ColorMapper.
Definition: ImageData.cs:371
static Datum GetImageDataF(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap=true, int[] rgFocusMap=null)
The GetImageDataF function converts a Bitmap into a Datum using the float type for real data.
Definition: ImageData.cs:181
static Bitmap GetImage(List< Result > rg, Size sz, ColorMapper clrMap)
Converts a list of KeyValuePairs into an image using a ColorMapper.
Definition: ImageData.cs:651
static Datum GetImageDataD(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap=true, int[] rgFocusMap=null)
The GetImageDataD function converts a Bitmap into a Datum using the double type for real data.
Definition: ImageData.cs:44
The LockBitmap class provides very efficient SetPixel and GetPixel functionality of a bitmap by using...
Definition: LockBitmap.cs:21
Color GetPixel(int x, int y)
Get the color of the specified pixel
Definition: LockBitmap.cs:121
void SetPixel(int x, int y, Color color)
Set the color of the specified pixel
Definition: LockBitmap.cs:164
void UnlockBits()
Unlock bitmap data, releasing its underlying data.
Definition: LockBitmap.cs:99
int Width
Returns the width of the bitmap.
Definition: LockBitmap.cs:37
int Height
Returns the height of the bitmap.
Definition: LockBitmap.cs:41
void LockBits()
Lock bitmap data to access its underlying raw data.
Definition: LockBitmap.cs:55
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
bool HasRealData
Returns true if either the RealDataD or RealDataF are non null and have length > 0.
int Channels
Return the number of channels of the data.
bool IsRealData
Returns whether or not the data contains real numbers or byte data.
int Width
Return the width of the data.
double GetDataAtD(int nIdx)
Returns the item at a specified index in the double type.
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.
int Label
Return the known label of the data.
The Utility class provides general utility funtions.
Definition: Utility.cs:35
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12