diff --git a/netstandard/ClothONNX.Gpu/ClothONNX.Gpu.csproj b/netstandard/ClothONNX.Gpu/ClothONNX.Gpu.csproj
index f0fe4a2..3e26f2e 100644
--- a/netstandard/ClothONNX.Gpu/ClothONNX.Gpu.csproj
+++ b/netstandard/ClothONNX.Gpu/ClothONNX.Gpu.csproj
@@ -4,8 +4,8 @@
netstandard2.0
ClothONNX.Gpu
8.0
- 1.0.2.1
- 1.0.2.1
+ 1.1.0.1
+ 1.1.0.1
Valery Asiryan
Valery Asiryan
Cloth segmentation library based on deep neural networks and ONNX runtime.
@@ -13,7 +13,7 @@
Open-source
ClothONNX.Gpu
ClothONNX.Gpu
- 1.0.2.1
+ 1.1.0.1
true
cloth detection segmentation recognition onnx neural-networks unet
https://github.com/FaceONNX/ClothONNX
diff --git a/netstandard/ClothONNX.Gpu/ClothSegmentator.cs b/netstandard/ClothONNX.Gpu/ClothSegmentator.cs
index 03cf387..c59f532 100644
--- a/netstandard/ClothONNX.Gpu/ClothSegmentator.cs
+++ b/netstandard/ClothONNX.Gpu/ClothSegmentator.cs
@@ -29,47 +29,61 @@ public class ClothSegmentator : IClothSegmentator
///
/// Initializes cloth segmentator.
+ /// Cloth segmentator quality
///
- public ClothSegmentator()
+ public ClothSegmentator(ClothSegmentatorQuality clothSegmentatorQuality = ClothSegmentatorQuality.Medium)
{
+ ClothSegmentatorQuality = clothSegmentatorQuality;
_session = new InferenceSession(Resources.cloth_segmentation_unet);
}
///
/// Initializes cloth segmentator.
///
+ /// Cloth segmentator quality
/// Session options
- public ClothSegmentator(SessionOptions options)
+ public ClothSegmentator(SessionOptions options, ClothSegmentatorQuality clothSegmentatorQuality = ClothSegmentatorQuality.Medium)
{
+ ClothSegmentatorQuality = clothSegmentatorQuality;
_session = new InferenceSession(Resources.cloth_segmentation_unet, options);
}
#endregion
+ #region Properties
+
+ ///
+ /// Gets or sets cloth segmentator quality.
+ ///
+ public ClothSegmentatorQuality ClothSegmentatorQuality { get; set; }
+
+ #endregion
+
#region Methods
///
- public float[,] Forward(Bitmap image)
+ public float[,] Forward(Bitmap image, InterpolationMode interpolationMode = InterpolationMode.Bilinear)
{
var rgb = image.ToRGB(false);
- return Forward(rgb);
+ return Forward(rgb, interpolationMode);
}
///
- public float[,] Forward(float[][,] image)
+ public float[,] Forward(float[][,] image, InterpolationMode interpolationMode = InterpolationMode.Bilinear)
{
if (image.Length != 3)
throw new ArgumentException("Image must be in BGR terms");
var width = image[0].GetLength(1);
var height = image[0].GetLength(0);
- var size = new Size(768, 768);
+ var length = (int)ClothSegmentatorQuality;
+ var size = new Size(length, length);
var resized = new float[3][,];
for (int i = 0; i < image.Length; i++)
{
- resized[i] = image[i].ResizePreserved(size.Height, size.Width, 0.0f, InterpolationMode.Bilinear);
+ resized[i] = image[i].ResizePreserved(size.Height, size.Width, 0.0f, interpolationMode);
}
var dimentions = new int[] { 1, 3, size.Width, size.Height };
@@ -113,7 +127,7 @@ public ClothSegmentator(SessionOptions options)
}
}
- return mask.ResizePreserved(height, width, InterpolationMode.Bilinear);
+ return mask.ResizePreserved(height, width, interpolationMode);
}
#endregion
diff --git a/netstandard/ClothONNX.Gpu/ClothSegmentatorQuality.cs b/netstandard/ClothONNX.Gpu/ClothSegmentatorQuality.cs
new file mode 100644
index 0000000..1d88de0
--- /dev/null
+++ b/netstandard/ClothONNX.Gpu/ClothSegmentatorQuality.cs
@@ -0,0 +1,21 @@
+namespace ClothONNX
+{
+ ///
+ /// Defines a cloth segmentator quality.
+ ///
+ public enum ClothSegmentatorQuality
+ {
+ ///
+ /// Log quality.
+ ///
+ Low = 512,
+ ///
+ /// Medium quality.
+ ///
+ Medium = 768,
+ ///
+ /// High quality.
+ ///
+ High = 1024
+ }
+}
diff --git a/netstandard/ClothONNX.Gpu/IClothSegmentator.cs b/netstandard/ClothONNX.Gpu/IClothSegmentator.cs
index 51e37e4..8eda656 100644
--- a/netstandard/ClothONNX.Gpu/IClothSegmentator.cs
+++ b/netstandard/ClothONNX.Gpu/IClothSegmentator.cs
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
+using UMapx.Core;
namespace ObjectONNX
{
@@ -14,15 +15,17 @@ public interface IClothSegmentator : IDisposable
/// Returns cloth segmentation results.
///
/// Bitmap
+ /// Interpolation mode
/// Result
- float[,] Forward(Bitmap image);
+ float[,] Forward(Bitmap image, InterpolationMode interpolationMode = InterpolationMode.Bilinear);
///
/// Returns cloth segmentation results.
///
/// Image in BGR terms
+ /// Interpolation mode
/// Result
- float[,] Forward(float[][,] image);
+ float[,] Forward(float[][,] image, InterpolationMode interpolationMode = InterpolationMode.Bilinear);
#endregion
}
diff --git a/netstandard/ClothONNX/ClothONNX.csproj b/netstandard/ClothONNX/ClothONNX.csproj
index a513902..528d72d 100644
--- a/netstandard/ClothONNX/ClothONNX.csproj
+++ b/netstandard/ClothONNX/ClothONNX.csproj
@@ -4,8 +4,8 @@
netstandard2.0
ClothONNX
8.0
- 1.0.2.1
- 1.0.2.1
+ 1.1.0.1
+ 1.1.0.1
Valery Asiryan
Valery Asiryan
Cloth segmentation library based on deep neural networks and ONNX runtime.
@@ -13,7 +13,7 @@
Open-source
ClothONNX
ClothONNX
- 1.0.2.1
+ 1.1.0.1
true
cloth detection segmentation recognition onnx neural-networks unet
https://github.com/FaceONNX/ClothONNX
diff --git a/netstandard/ClothONNX/ClothSegmentator.cs b/netstandard/ClothONNX/ClothSegmentator.cs
index 03cf387..c59f532 100644
--- a/netstandard/ClothONNX/ClothSegmentator.cs
+++ b/netstandard/ClothONNX/ClothSegmentator.cs
@@ -29,47 +29,61 @@ public class ClothSegmentator : IClothSegmentator
///
/// Initializes cloth segmentator.
+ /// Cloth segmentator quality
///
- public ClothSegmentator()
+ public ClothSegmentator(ClothSegmentatorQuality clothSegmentatorQuality = ClothSegmentatorQuality.Medium)
{
+ ClothSegmentatorQuality = clothSegmentatorQuality;
_session = new InferenceSession(Resources.cloth_segmentation_unet);
}
///
/// Initializes cloth segmentator.
///
+ /// Cloth segmentator quality
/// Session options
- public ClothSegmentator(SessionOptions options)
+ public ClothSegmentator(SessionOptions options, ClothSegmentatorQuality clothSegmentatorQuality = ClothSegmentatorQuality.Medium)
{
+ ClothSegmentatorQuality = clothSegmentatorQuality;
_session = new InferenceSession(Resources.cloth_segmentation_unet, options);
}
#endregion
+ #region Properties
+
+ ///
+ /// Gets or sets cloth segmentator quality.
+ ///
+ public ClothSegmentatorQuality ClothSegmentatorQuality { get; set; }
+
+ #endregion
+
#region Methods
///
- public float[,] Forward(Bitmap image)
+ public float[,] Forward(Bitmap image, InterpolationMode interpolationMode = InterpolationMode.Bilinear)
{
var rgb = image.ToRGB(false);
- return Forward(rgb);
+ return Forward(rgb, interpolationMode);
}
///
- public float[,] Forward(float[][,] image)
+ public float[,] Forward(float[][,] image, InterpolationMode interpolationMode = InterpolationMode.Bilinear)
{
if (image.Length != 3)
throw new ArgumentException("Image must be in BGR terms");
var width = image[0].GetLength(1);
var height = image[0].GetLength(0);
- var size = new Size(768, 768);
+ var length = (int)ClothSegmentatorQuality;
+ var size = new Size(length, length);
var resized = new float[3][,];
for (int i = 0; i < image.Length; i++)
{
- resized[i] = image[i].ResizePreserved(size.Height, size.Width, 0.0f, InterpolationMode.Bilinear);
+ resized[i] = image[i].ResizePreserved(size.Height, size.Width, 0.0f, interpolationMode);
}
var dimentions = new int[] { 1, 3, size.Width, size.Height };
@@ -113,7 +127,7 @@ public ClothSegmentator(SessionOptions options)
}
}
- return mask.ResizePreserved(height, width, InterpolationMode.Bilinear);
+ return mask.ResizePreserved(height, width, interpolationMode);
}
#endregion
diff --git a/netstandard/ClothONNX/ClothSegmentatorQuality.cs b/netstandard/ClothONNX/ClothSegmentatorQuality.cs
new file mode 100644
index 0000000..1d88de0
--- /dev/null
+++ b/netstandard/ClothONNX/ClothSegmentatorQuality.cs
@@ -0,0 +1,21 @@
+namespace ClothONNX
+{
+ ///
+ /// Defines a cloth segmentator quality.
+ ///
+ public enum ClothSegmentatorQuality
+ {
+ ///
+ /// Log quality.
+ ///
+ Low = 512,
+ ///
+ /// Medium quality.
+ ///
+ Medium = 768,
+ ///
+ /// High quality.
+ ///
+ High = 1024
+ }
+}
diff --git a/netstandard/ClothONNX/IClothSegmentator.cs b/netstandard/ClothONNX/IClothSegmentator.cs
index 51e37e4..8eda656 100644
--- a/netstandard/ClothONNX/IClothSegmentator.cs
+++ b/netstandard/ClothONNX/IClothSegmentator.cs
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
+using UMapx.Core;
namespace ObjectONNX
{
@@ -14,15 +15,17 @@ public interface IClothSegmentator : IDisposable
/// Returns cloth segmentation results.
///
/// Bitmap
+ /// Interpolation mode
/// Result
- float[,] Forward(Bitmap image);
+ float[,] Forward(Bitmap image, InterpolationMode interpolationMode = InterpolationMode.Bilinear);
///
/// Returns cloth segmentation results.
///
/// Image in BGR terms
+ /// Interpolation mode
/// Result
- float[,] Forward(float[][,] image);
+ float[,] Forward(float[][,] image, InterpolationMode interpolationMode = InterpolationMode.Bilinear);
#endregion
}
diff --git a/netstandard/Examples/ClothSegmentation/Form1.cs b/netstandard/Examples/ClothSegmentation/Form1.cs
index 08f60bf..d61948a 100644
--- a/netstandard/Examples/ClothSegmentation/Form1.cs
+++ b/netstandard/Examples/ClothSegmentation/Form1.cs
@@ -1,4 +1,5 @@
using ClothONNX;
+using UMapx.Core;
using UMapx.Imaging;
namespace ClothSegmentation
@@ -17,7 +18,7 @@ public Form1()
AllowDrop = true;
Text = "ClothONNX: Cloth Segmentation";
- _clothSegmentator = new ClothSegmentator();
+ _clothSegmentator = new ClothSegmentator(ClothSegmentatorQuality.High);
var image = new Bitmap("example.png");
Process(image);
}
@@ -38,9 +39,12 @@ private void Form1_DragDrop(object sender, DragEventArgs e)
private void Process(Bitmap image)
{
- var results = _clothSegmentator.Forward(image);
+ var results = _clothSegmentator.Forward(
+ image: image,
+ interpolationMode: InterpolationMode.Bicubic);
+
using var mask = results.FromGrayscale();
- var maskColorFilter = new MaskColorFilter(Color.Red);
+ var maskColorFilter = new MaskColorFilter(Color.Yellow);
maskColorFilter.Apply(image, mask);
BackgroundImage?.Dispose();