47 if (this.dataSize !=
Data.Length)
48 throw new ArgumentOutOfRangeException(nameof(
Data));
74 this.dataSize =
Data.Length;
100 rowSize = this.rowSize,
101 dataSize = this.dataSize,
124 if (value <= 0 || value >= this.rowSize - this.left)
125 throw new ArgumentOutOfRangeException(nameof(this.
Width));
128 this.skip = this.rowSize - this.width;
140 if (value <= 0 || (this.top + value) * this.width >= this.dataSize)
141 throw new ArgumentOutOfRangeException(nameof(this.
Height));
155 if (value < 0 || value >= this.rowSize - this.width)
156 throw new ArgumentOutOfRangeException(nameof(this.
Left));
159 this.start = this.left + this.top * this.rowSize;
171 if (value < 0 || (value + this.height) * this.width >= this.dataSize)
172 throw new ArgumentOutOfRangeException(nameof(this.
Top));
175 this.start = this.left + this.top * this.rowSize;
186 if (Left < 0 || Left + Width > this.rowSize)
187 throw new ArgumentOutOfRangeException(nameof(
Left));
190 throw new ArgumentOutOfRangeException(nameof(
Width));
193 this.start = this.left + this.top * this.rowSize;
195 this.skip = this.rowSize - this.width;
205 if (
Top < 0 || (
Top +
Height) * this.width > this.dataSize)
206 throw new ArgumentOutOfRangeException(nameof(
Top));
209 throw new ArgumentOutOfRangeException(nameof(
Height));
213 this.start = this.left + this.top * this.rowSize;
241 public T
this[
int X,
int Y]
243 get => this.data[(X + this.left) + (Y + this.top) * this.rowSize];
244 set => this.data[(X + this.left) + (Y + this.top) * this.rowSize] = value;
255 return (X + this.left) + (Y + this.top) * this.rowSize;
265 if (RowIndex < 0 || RowIndex >= this.height)
266 throw new ArgumentOutOfRangeException(nameof(RowIndex));
274 top = this.top + RowIndex,
275 rowSize = this.rowSize,
276 dataSize = this.dataSize,
277 start = this.start + (RowIndex * this.rowSize),
289 if (ColumnIndex < 0 || ColumnIndex >= this.width)
290 throw new ArgumentOutOfRangeException(nameof(ColumnIndex));
296 height = this.height,
297 left = this.left + ColumnIndex,
299 rowSize = this.rowSize,
300 dataSize = this.dataSize,
301 start = this.start + ColumnIndex,
302 skip = this.rowSize - 1
316 if (Left < 0 || Left >= this.width)
317 throw new ArgumentOutOfRangeException(nameof(
Left));
319 if (Top < 0 || Top >= this.height)
320 throw new ArgumentOutOfRangeException(nameof(
Top));
322 if (Width <= 0 || Width > this.width - this.left -
Left)
323 throw new ArgumentOutOfRangeException(nameof(
Width));
325 if (Height <= 0 || Height > this.height - this.top -
Top)
326 throw new ArgumentOutOfRangeException(nameof(
Height));
333 left = this.left +
Left,
334 top = this.top +
Top,
335 rowSize = this.rowSize,
336 dataSize = this.dataSize,
337 start = this.start +
Left + (
Top * this.rowSize),
338 skip = this.rowSize -
Width
349 using SKBitmap Bmp = SKBitmap.Decode(FileName);
350 byte[]
Data = Bmp.Bytes;
352 switch (Bmp.BytesPerPixel)
358 int i, j, c =
Data.Length;
359 ushort[] Bin16 =
new ushort[c / 2];
375 uint[] Bin32 =
new uint[c / 3];
393 Bin32 =
new uint[c / 4];
411 throw new ArgumentException(
"Color type not supported.", nameof(FileName));
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
void SetYSpan(int Top, int Height)
Sets Top and Height simultaneously.
virtual Matrix< T > ShallowCopy()
Creates a shallow copy of the matrix. The shallow copy points to the same underlying pixel data.
int Height
Height of matrix (number of rows)
T[] Data
Underlying data on which the matrix is defined.
static IMatrix LoadFromFile(string FileName)
Loads an image into a matrix.
int Width
Width of matrix (number of columns)
Matrix(int Width, int Height)
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Matrix(int Width, int Height, T[] Data, int Left, int Top, int RowSize, int Start, int Skip)
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Matrix< T > Row(int RowIndex)
Returns a row vector as a matrix.
Matrix< T > Region(int Left, int Top, int Width, int Height)
Returns a region of the matrix, as a new matrix.
int Left
Left offset of matrix in underlying data array.
int DataSize
Total number of elements in underlying data array.
Matrix(int Width, int Height, T[] Data)
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Type ElementType
Type of elements in matrix.
int RowSize
Number of elements per row in underlying data array.
int Skip
Number of elements to skip from the right edge in the underlying data to the left edge of the new row...
int StartIndex(int X, int Y)
Gets the start index of a point in the image.
Matrix< T > Column(int ColumnIndex)
Returns a column vector as a matrix.
void SetXSpan(int Left, int Width)
Sets Left and Width simultaneously.
int Top
Top offset of matrix in underlying data array.
int Start
Start offset of matrix in underlying data.