Skip to content

Commit

Permalink
fix of the namespace reference error
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Oct 11, 2024
1 parent f026fad commit 8f6e4fb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.MachineLearning.Convolutional.ImageProcessor
Imports System.Drawing
Imports Microsoft.VisualBasic.Imaging.BitmapImage


#If NET48 Then
Imports Pen = System.Drawing.Pen
Expand Down Expand Up @@ -142,7 +144,7 @@ Namespace Convolutional
''' <returns></returns>
Public Overrides Function feedNext() As Layer
Dim fullImage As New Rectangle(0, 0, inputSize(1), inputSize(0))
Dim bmpData As BitmapData = _resizedInputBmp.LockBits(fullImage, ImageLockMode.ReadOnly, _resizedInputBmp.PixelFormat)
Dim bmpData As BitmapBuffer = BitmapBuffer.FromBitmap(_resizedInputBmp)
Dim stride As Integer = bmpData.Stride
Dim emptyBytesCount As Integer = stride - bmpData.Width * 3
Dim rowLengthWithoutEB As Integer = stride - emptyBytesCount
Expand Down Expand Up @@ -178,7 +180,6 @@ Namespace Convolutional
End If
End While

Call _resizedInputBmp.UnlockBits(bmpData)
Call _resizedInputBmp.Dispose()

Return Me
Expand Down
7 changes: 4 additions & 3 deletions Data_science/MachineLearning/MLDataStorage/MNIST.vb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports std = System.Math
Imports Microsoft.VisualBasic.Imaging.BitmapImage


#If NET48 Then
Imports Pen = System.Drawing.Pen
Expand Down Expand Up @@ -168,7 +170,7 @@ Public Class MNIST : Implements IDisposable

Public Function ConvertImage(raw As NamedCollection(Of Byte)) As NamedValue(Of Image)
Dim image As Bitmap = New Bitmap(columns, rows)
Dim data = image.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim data As BitmapBuffer = BitmapBuffer.FromBitmap(image)
Dim ptr As IntPtr = data.Scan0
Dim bytes = std.Abs(data.Stride) * image.Height
Dim rgbValues = New Byte(bytes - 1) {}
Expand All @@ -184,8 +186,7 @@ Public Class MNIST : Implements IDisposable
Next

Marshal.Copy(rgbValues, 0, ptr, bytes)

image.UnlockBits(data)
data.Dispose()

Return New NamedValue(Of Image) With {
.Name = raw.Last,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ Imports System.Drawing
Imports Microsoft.VisualBasic.Data.ChartPlots.Graphic
Imports Microsoft.VisualBasic.Data.ChartPlots.Graphic.Canvas
Imports Microsoft.VisualBasic.DataMining.ComponentModel
Imports Microsoft.VisualBasic.DataMining.UMAP
Imports Microsoft.VisualBasic.Imaging.Drawing2D.Colors
Imports Microsoft.VisualBasic.Linq

#If NET48 Then
Imports SolidBrush = System.Drawing.SolidBrush
Imports Brushes = System.Drawing.Brushes
#Else
Imports SolidBrush = Microsoft.VisualBasic.Imaging.SolidBrush
Imports Brushes = Microsoft.VisualBasic.Imaging.Brushes
#End If

Public MustInherit Class EmbeddingRender : Inherits Plot

Protected ReadOnly labels As String()
Expand Down
31 changes: 31 additions & 0 deletions Microsoft.VisualBasic.Core/src/Drawing/GDI+/GraphicsExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.CommandLine.Reflection
Imports Microsoft.VisualBasic.ComponentModel.Algorithm.base
Imports Microsoft.VisualBasic.Imaging.BitmapImage
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Linq
Imports Microsoft.VisualBasic.Net.Http
Expand Down Expand Up @@ -407,6 +408,36 @@ Namespace Imaging
End With
End Function

''' <summary>
''' Color replace using memory pointer
''' </summary>
''' <param name="image"></param>
''' <param name="subject"></param>
''' <param name="replaceAs"></param>
''' <returns></returns>
<Extension>
Public Function ColorReplace(image As Bitmap, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
Using bitmap As BitmapBuffer = BitmapBuffer.FromBitmap(image)
Dim byts As BitmapBuffer = bitmap

For x As Integer = 0 To byts.Width - 1
For y As Integer = 0 To byts.Height - 1
If GDIColors.Equals(byts.GetPixel(x, y), subject, tolerance) Then
Call byts.SetPixel(x, y, replaceAs)
End If
Next
Next
End Using

Return image
End Function

<MethodImpl(MethodImplOptions.AggressiveInlining)>
<Extension>
Public Function ColorReplace(image As Image, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
Return New Bitmap(image).ColorReplace(subject, replaceAs, tolerance)
End Function

''' <summary>
''' Adding a frame box to the target image source.(为图像添加边框)
''' </summary>
Expand Down
30 changes: 0 additions & 30 deletions gr/Drawing-net4.8/Utils.vb
Original file line number Diff line number Diff line change
Expand Up @@ -275,35 +275,5 @@ Namespace Imaging.BitmapImage
Return res
End If
End Function

''' <summary>
''' Color replace using memory pointer
''' </summary>
''' <param name="image"></param>
''' <param name="subject"></param>
''' <param name="replaceAs"></param>
''' <returns></returns>
<Extension>
Public Function ColorReplace(image As Bitmap, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
Using bitmap As BitmapBuffer = BitmapBuffer.FromBitmap(image)
Dim byts As BitmapBuffer = bitmap

For x As Integer = 0 To byts.Width - 1
For y As Integer = 0 To byts.Height - 1
If GDIColors.Equals(byts.GetPixel(x, y), subject, tolerance) Then
Call byts.SetPixel(x, y, replaceAs)
End If
Next
Next
End Using

Return image
End Function

<MethodImpl(MethodImplOptions.AggressiveInlining)>
<Extension>
Public Function ColorReplace(image As Image, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
Return New Bitmap(image).ColorReplace(subject, replaceAs, tolerance)
End Function
End Module
End Namespace

0 comments on commit 8f6e4fb

Please sign in to comment.