MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Valuemap.cs
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace MyCaffe.basecode
9{
13 [Serializable]
14 public class Valuemap
15 {
16 int m_nChannels;
17 int m_nHeight;
18 int m_nWidth;
19 int m_nChannelOffset;
20 double[] m_rgData;
21
29 public Valuemap(int nChannels, int nHeight, int nWidth, double[] rgData = null)
30 {
31 int nSize = nChannels * nHeight * nWidth;
32 m_rgData = (rgData != null) ? rgData : new double[nSize];
33 m_nChannels = nChannels;
34 m_nHeight = nHeight;
35 m_nWidth = nWidth;
36 m_nChannelOffset = nHeight * nWidth;
37 }
38
43 public Valuemap(Valuemap data)
44 {
45 int nChannels = data.Channels;
46 int nHeight = data.Height;
47 int nWidth = data.Width;
48
49 int nSize = nChannels * nHeight * nWidth;
50 m_rgData = new double[nSize];
51 m_nChannels = nChannels;
52 m_nHeight = nHeight;
53 m_nWidth = nWidth;
54 m_nChannelOffset = nHeight * nWidth;
55
56 Array.Copy(data.Values, m_rgData, nSize);
57 }
58
65 public void SetPixel(int nX, int nY, double clr)
66 {
67 int nIdx = nY * m_nWidth + nX;
68 m_rgData[nIdx] = clr;
69
70 if (m_nChannels == 3)
71 {
72 m_rgData[nIdx + m_nChannelOffset] = clr;
73 m_rgData[nIdx + m_nChannelOffset * 2] = clr;
74 }
75 }
76
83 public double GetPixel(int nX, int nY)
84 {
85 int nIdx = nY * m_nWidth + nX;
86 return m_rgData[nIdx];
87 }
88
96 public void SetPixel(int nChannel, int nX, int nY, double clr)
97 {
98 int nIdx = (nChannel * m_nChannelOffset) + nY * m_nWidth + nX;
99 m_rgData[nIdx] = clr;
100 }
101
109 public double GetPixel(int nChannel, int nX, int nY)
110 {
111 int nIdx = (nChannel * m_nChannelOffset) + nY * m_nWidth + nX;
112 return m_rgData[nIdx];
113 }
114
119 public void SetAll(double dfVal)
120 {
121 for (int i = 0; i < m_rgData.Length; i++)
122 {
123 m_rgData[i] = dfVal;
124 }
125 }
126
132 public void SetAll(int nChannel, double dfVal)
133 {
134 int nIdxStart = m_nChannelOffset * nChannel;
135 int nCount = m_nChannelOffset;
136
137 for (int i = nIdxStart; i < nIdxStart + nCount; i++)
138 {
139 m_rgData[i] = dfVal;
140 }
141 }
142
146 public void Clear()
147 {
148 Array.Clear(m_rgData, 0, m_rgData.Length);
149 }
150
154 public double[] Values
155 {
156 get { return m_rgData; }
157 }
158
162 public int Channels
163 {
164 get { return m_nChannels; }
165 }
166
170 public int Height
171 {
172 get { return m_nHeight; }
173 }
174
178 public int Width
179 {
180 get { return m_nWidth; }
181 }
182 }
183}
The Realmap operates similar to a bitmap but is actually just an array of doubles.
Definition: Valuemap.cs:15
double[] Values
Specifies the data itself.
Definition: Valuemap.cs:155
Valuemap(int nChannels, int nHeight, int nWidth, double[] rgData=null)
The constructor.
Definition: Valuemap.cs:29
double GetPixel(int nX, int nY)
Get the value of a pixel in the map.
Definition: Valuemap.cs:83
Valuemap(Valuemap data)
The constructorl
Definition: Valuemap.cs:43
void SetPixel(int nChannel, int nX, int nY, double clr)
Set a given pixel to a given color.
Definition: Valuemap.cs:96
void SetAll(double dfVal)
Set all values to the specified value.
Definition: Valuemap.cs:119
void SetAll(int nChannel, double dfVal)
Set all values of a given channel to a specified value.
Definition: Valuemap.cs:132
int Channels
Specifies the channels of the data.
Definition: Valuemap.cs:163
void Clear()
Reset all values to zero.
Definition: Valuemap.cs:146
double GetPixel(int nChannel, int nX, int nY)
Get the value of a pixel in the map.
Definition: Valuemap.cs:109
void SetPixel(int nX, int nY, double clr)
Set a given pixel to a given color.
Definition: Valuemap.cs:65
int Height
Specifies the height of the data.
Definition: Valuemap.cs:171
int Width
Specifies the width of the data.
Definition: Valuemap.cs:179
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12