forked from TensorStack-AI/TensorStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageInput.cs
More file actions
95 lines (79 loc) · 2.66 KB
/
ImageInput.cs
File metadata and controls
95 lines (79 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) TensorStack. All rights reserved.
// Licensed under the Apache 2.0 License.
using System.Drawing;
using TensorStack.Common;
using TensorStack.Common.Image;
using TensorStack.Common.Tensor;
namespace TensorStack.Image
{
/// <summary>
/// ImageInput implementation with System.Drawing.Bitmap.
/// </summary>
public class ImageInput : ImageInput<Bitmap>
{
private Bitmap _image;
/// <summary>
/// Initializes a new instance of the <see cref="ImageInput"/> class.
/// </summary>
/// <param name="tensor">The tensor.</param>
public ImageInput(ImageTensor tensor) : base(tensor)
{
_image = tensor.ToBitmapImage();
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageInput"/> class.
/// </summary>
/// <param name="image">The image.</param>
public ImageInput(Bitmap image)
: base(image.ToTensor())
{
_image = image;
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageInput"/> class.
/// </summary>
/// <param name="filename">The filename.</param>
public ImageInput(string filename)
: this(new Bitmap(filename)) { }
/// <summary>
/// Initializes a new instance of the <see cref="ImageInput"/> class.
/// </summary>
/// <param name="filename">The filename.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="resizeMode">The resize mode.</param>
public ImageInput(string filename, int width, int height, ResizeMode resizeMode = ResizeMode.Stretch) : this(new Bitmap(filename))
{
Resize(width, height, resizeMode);
}
/// <summary>
/// Gets the image.
/// </summary>
public override Bitmap Image => _image;
/// <summary>
/// Saves the image.
/// </summary>
/// <param name="filename">The filename.</param>
public override void Save(string filename)
{
_image.Save(filename);
}
/// <summary>
/// Called when Tensor data has changed
/// </summary>
protected override void OnTensorDataChanged()
{
base.OnTensorDataChanged();
_image = this.ToBitmapImage();
}
/// <summary>
/// Releases resources.
/// </summary>
protected override void Dispose(bool disposing)
{
_image?.Dispose();
_image = null;
base.Dispose(disposing);
}
}
}