diff --git a/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs b/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs
index c651b1d..7329b0b 100644
--- a/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs
+++ b/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs
@@ -131,9 +131,26 @@ namespace MarketData.CNNProcessing
this.pointMapping=pointMapping;
bitmap=new SKBitmap(width,height,SKColorType.Rgba8888, SKAlphaType.Premul);
Validate();
- }
+ }
+
+ ///
+ /// Create a new 32 bit bitmap with 8 bits per channel which includes 8 bits for the alpha channel where 0 = fully transparent and 255 = fully opaque
+ ///
+ ///
+ ///
+ public void CreateImage(int width, int height)
+ {
+ DisposeAll();
+ this.pointMapping = new PointMapping(width, height, width, 0, height, 0, 0,0);
+ bitmap=new SKBitmap(width,height,SKColorType.Rgba8888, SKAlphaType.Premul);
+ Validate();
+ }
- // This is the method that is currently being used in the CNNClient.Predict to send the image stream to Flask
+ ///
+ /// Save the bitmap as black and white jpeg and return the stream
+ /// This is the method that is currently being used in the CNNClient.Predict to send the image stream to Flask
+ ///
+ ///
public Stream SaveBlackAndWhiteJPG()
{
Validate();
@@ -145,7 +162,11 @@ namespace MarketData.CNNProcessing
return memoryStream;
}
- // Convert bitmap to stream for use in CNNClient
+ ///
+ /// Convert bitmap to stream for use in CNNClient
+ ///
+ ///
+ ///
public Stream ToStream()
{
Validate();
@@ -155,6 +176,11 @@ namespace MarketData.CNNProcessing
return memoryStream;
}
+ ///
+ /// Save the bitmap as gray scale jpeg to the specified file
+ ///
+ ///
+ ///
public bool SaveGrayScaleJPG(String pathFileName)
{
Validate();
@@ -164,6 +190,11 @@ namespace MarketData.CNNProcessing
return true;
}
+ ///
+ /// Save the bitmap as black and white jpeg to the specified file
+ ///
+ ///
+ ///
public bool SaveBlackAndWhiteJPG(String pathFileName)
{
Validate();
@@ -173,6 +204,10 @@ namespace MarketData.CNNProcessing
return true;
}
+ ///
+ /// Save the bitmap to the specified file
+ ///
+ ///
public void Save(String pathFileName)
{
Save(pathFileName,null);
@@ -204,7 +239,11 @@ namespace MarketData.CNNProcessing
canvas.DrawBitmap(bitmap, new SKPoint(0,0), paint);
return dstBitmap;
}
-
+
+ ///
+ /// Rotates the bitmap right by 90 degrees
+ ///
+ ///
public bool RotateRight()
{
Validate();
@@ -215,6 +254,10 @@ namespace MarketData.CNNProcessing
return true;
}
+ ///
+ /// Rotates the bitmap left by 90 degrees
+ ///
+ ///
public bool RotateLeft()
{
Validate();
@@ -225,6 +268,12 @@ namespace MarketData.CNNProcessing
return true;
}
+ ///
+ /// Rotates the bitmap to the specified angle
+ ///
+ ///
+ ///
+ ///
private SKBitmap Rotate(SKBitmap bitmap, double angle)
{
double radians = Math.PI * angle / 180;
@@ -256,7 +305,7 @@ namespace MarketData.CNNProcessing
bitmap=grayScaleBitmap;
}
- // Convert to 8 bits per pixel black and white
+ // Convert to 8 bits per pixel black and white
private SKBitmap ToGrayScale(SKBitmap bitmap)
{
SKColorFilter grayScaleColorFilter = SKColorFilter.CreateColorMatrix(new float[]
@@ -275,6 +324,11 @@ namespace MarketData.CNNProcessing
return dstBitmap;
}
+ ///
+ /// Adds a blur effect to the bitmap
+ ///
+ ///
+ ///
public bool Blur(float sigmaX)
{
Validate();
@@ -283,7 +337,14 @@ namespace MarketData.CNNProcessing
bitmap = blurredBitmap;
return true;
}
-
+
+ ///
+ /// Applies a blur effect to the bitmap
+ ///
+ ///
+ ///
+ ///
+ ///
private SKBitmap Blur(SKBitmap image, float sigmaX=5.0f, float sigmaY=5.0f)
{
SKImageFilter imageFilter = SKImageFilter.CreateBlur(sigmaX, sigmaY);
@@ -405,19 +466,51 @@ namespace MarketData.CNNProcessing
}
}
- public void DrawLine(SKColor color, float strokeWidth, SKPoint srcPoint,SKPoint dstPoint)
+ ///
+ /// Draw a line on the bitmap
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void DrawLine(SKColor color, float strokeWidth, SKPoint srcPoint, SKPoint dstPoint)
{
Validate();
- SKPoint txSrcPoint=pointMapping.MapPoint(srcPoint);
- SKPoint txDstPoint=pointMapping.MapPoint(dstPoint);
+ SKPoint txSrcPoint = pointMapping.MapPoint(srcPoint);
+ SKPoint txDstPoint = pointMapping.MapPoint(dstPoint);
using SKCanvas canvas = new SKCanvas(bitmap);
using SKPaint paint = new SKPaint();
paint.Style = SKPaintStyle.Stroke;
paint.StrokeWidth = strokeWidth; // Set the desired stroke width
- paint.Color = SKColors.Black;
+ paint.Color = color;
canvas.DrawLine(txSrcPoint, txDstPoint, paint);
}
+ ///
+ /// Draw text on the bitmap
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void DrawText(String text, SKPoint srcPoint,SKColor color,SKTextAlign align,SKFont font, float strokeWidth=1)
+ {
+ Validate();
+ SKPoint txSrcPoint = pointMapping.MapPoint(srcPoint);
+ using SKCanvas canvas = new SKCanvas(bitmap);
+ using SKPaint paint = new SKPaint();
+ paint.Style = SKPaintStyle.Stroke;
+ paint.StrokeWidth = strokeWidth; // Set the desired stroke width
+ paint.Color = color;
+ canvas.DrawText(text,srcPoint, align, font, paint);
+ }
+
+ ///
+ /// Draws the path along the line segments
+ ///
+ ///
+ ///
+ ///
public void DrawPath(SKColor color, float strokeWidth, LineSegments lineSegments)
{
Validate();
@@ -434,11 +527,18 @@ namespace MarketData.CNNProcessing
canvas.DrawLine(txSrcPoint, txDstPoint, paint);
}
}
-
- public bool DrawCircle(SKColor color, SKPoint center, float radius=1.00f)
+
+ ///
+ /// Draws a circle on the bitmap
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool DrawCircle(SKColor color, SKPoint center, float radius = 1.00f)
{
Validate();
- SKPoint txPointCenter=pointMapping.MapPoint(center);
+ SKPoint txPointCenter = pointMapping.MapPoint(center);
using SKPaint paint = new SKPaint();
paint.Color = color;
paint.Style = SKPaintStyle.Fill;