-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/SMRUCC/R-sharp
- Loading branch information
Showing
6 changed files
with
150 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
#Region "Microsoft.VisualBasic::e82346187276f99f773149fe7e549efe, studio\Rsharp_kit\MLkit\dataset\bitmap.vb" | ||
|
||
' Author: | ||
' | ||
' asuka ([email protected]) | ||
' xie ([email protected]) | ||
' xieguigang ([email protected]) | ||
' | ||
' Copyright (c) 2018 GPL3 Licensed | ||
' | ||
' | ||
' GNU GENERAL PUBLIC LICENSE (GPL3) | ||
' | ||
' | ||
' This program is free software: you can redistribute it and/or modify | ||
' it under the terms of the GNU General Public License as published by | ||
' the Free Software Foundation, either version 3 of the License, or | ||
' (at your option) any later version. | ||
' | ||
' This program is distributed in the hope that it will be useful, | ||
' but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
' GNU General Public License for more details. | ||
' | ||
' You should have received a copy of the GNU General Public License | ||
' along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
|
||
' /********************************************************************************/ | ||
|
||
' Summaries: | ||
|
||
|
||
' Code Statistics: | ||
|
||
' Total Lines: 224 | ||
' Code Lines: 162 (72.32%) | ||
' Comment Lines: 30 (13.39%) | ||
' - Xml Docs: 96.67% | ||
' | ||
' Blank Lines: 32 (14.29%) | ||
' File Size: 8.83 KB | ||
|
||
|
||
' Module bitmap_func | ||
' | ||
' Function: corp_rectangle, intensity_vec, open, scan_rowpeaks, summary_region | ||
' | ||
' Sub: Main | ||
' | ||
' /********************************************************************************/ | ||
' Author: | ||
' | ||
' asuka ([email protected]) | ||
' xie ([email protected]) | ||
' xieguigang ([email protected]) | ||
' | ||
' Copyright (c) 2018 GPL3 Licensed | ||
' | ||
' | ||
' GNU GENERAL PUBLIC LICENSE (GPL3) | ||
' | ||
' | ||
' This program is free software: you can redistribute it and/or modify | ||
' it under the terms of the GNU General Public License as published by | ||
' the Free Software Foundation, either version 3 of the License, or | ||
' (at your option) any later version. | ||
' | ||
' This program is distributed in the hope that it will be useful, | ||
' but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
' GNU General Public License for more details. | ||
' | ||
' You should have received a copy of the GNU General Public License | ||
' along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
|
||
' /********************************************************************************/ | ||
|
||
' Summaries: | ||
|
||
|
||
' Code Statistics: | ||
|
||
' Total Lines: 224 | ||
' Code Lines: 162 (72.32%) | ||
' Comment Lines: 30 (13.39%) | ||
' - Xml Docs: 96.67% | ||
' | ||
' Blank Lines: 32 (14.29%) | ||
' File Size: 8.83 KB | ||
|
||
|
||
' Module bitmap_func | ||
' | ||
' Function: corp_rectangle, intensity_vec, open, scan_rowpeaks, summary_region | ||
' | ||
' Sub: Main | ||
' | ||
' /********************************************************************************/ | ||
|
||
#End Region | ||
|
||
|
@@ -58,6 +58,8 @@ Imports System.IO | |
Imports System.Runtime.CompilerServices | ||
Imports Microsoft.VisualBasic.ApplicationServices.Terminal.ProgressBar | ||
Imports Microsoft.VisualBasic.CommandLine.Reflection | ||
Imports Microsoft.VisualBasic.DataMining.DensityQuery | ||
Imports Microsoft.VisualBasic.Imaging | ||
Imports Microsoft.VisualBasic.Imaging.BitmapImage | ||
Imports Microsoft.VisualBasic.Math.Distributions | ||
Imports Microsoft.VisualBasic.Math.SignalProcessing | ||
|
@@ -82,8 +84,30 @@ Module bitmap_func | |
|
||
Sub Main() | ||
Call RInternal.generic.add("summary", GetType(BitmapReader), AddressOf summary_region) | ||
Call RInternal.Object.Converts.addHandler(GetType(SLICPixel()), AddressOf createPixelClusterTable) | ||
End Sub | ||
|
||
<RGenericOverloads("as.data.frame")> | ||
Private Function createPixelClusterTable(pixels As SLICPixel(), args As list, env As Environment) As Object | ||
Dim df As New dataframe With { | ||
.columns = New Dictionary(Of String, Array) | ||
} | ||
Dim offset As Integer | ||
|
||
Call df.add("x", From pixel As SLICPixel In pixels Select pixel.x) | ||
Call df.add("y", From pixel As SLICPixel In pixels Select pixel.y) | ||
Call df.add("cluster", From pixel As SLICPixel In pixels Select pixel.cluster) | ||
|
||
For i As Integer = 0 To pixels(0).color.Length - 1 | ||
offset = i | ||
df.add($"v{i + 1}", From pixel As SLICPixel | ||
In pixels | ||
Select pixel.color(offset)) | ||
Next | ||
|
||
Return df | ||
End Function | ||
|
||
<RGenericOverloads("summary")> | ||
Private Function summary_region(bmp As BitmapReader, args As list, env As Environment) As Object | ||
Dim offset_x As Integer = args.getValue("x", env, [default]:=1) | ||
|
@@ -202,6 +226,45 @@ Module bitmap_func | |
Return copy | ||
End Function | ||
|
||
''' <summary> | ||
''' | ||
''' </summary> | ||
''' <param name="bmp"></param> | ||
''' <returns></returns> | ||
<ExportAPI("slic")> | ||
<RApiReturn(GetType(SLICPixel))> | ||
Public Function slic(bmp As Object, | ||
Optional region_size As Double = 0.05, | ||
Optional iterations As Integer = 1000, | ||
Optional env As Environment = Nothing) As Object | ||
|
||
Dim buf As BitmapBuffer | ||
|
||
If bmp Is Nothing Then | ||
Return RInternal.debug.stop("the given bitmap data object should not be nothing!", env) | ||
End If | ||
|
||
If TypeOf bmp Is Bitmap Then | ||
buf = BitmapBuffer.FromBitmap(DirectCast(bmp, Bitmap)) | ||
ElseIf TypeOf bmp Is Image Then | ||
buf = BitmapBuffer.FromImage(DirectCast(bmp, Image)) | ||
ElseIf TypeOf bmp Is BitmapBuffer Then | ||
buf = bmp | ||
Else | ||
Return Message.InCompatibleType(GetType(BitmapBuffer), bmp.GetType, env) | ||
End If | ||
|
||
If region_size < 1 Then | ||
' convert ration to pixel size | ||
region_size = {buf.Width * region_size, buf.Height * region_size}.Average | ||
End If | ||
|
||
Dim method As New SLIC(buf) | ||
Dim pixels = method.MeasureSegments(region_size, iterations) | ||
|
||
Return pixels | ||
End Function | ||
|
||
''' <summary> | ||
''' scan the peak signal inside the bitmap image data | ||
''' </summary> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
imports "bitmap" from "MLkit"; | ||
|
||
let data = readImage(file.path(@dir, "lena.jpg" )); | ||
let regions = bitmap::slic(data,region_size = 0.3, | ||
iterations = 10); | ||
|
||
regions = as.data.frame(regions); | ||
|
||
setwd(@dir); | ||
|
||
bitmap(file = "./lena.png") { | ||
plot(regions$x, regions$y, | ||
class = regions$cluster, | ||
colors = "paper", | ||
point.size = 5, | ||
reverse=TRUE ); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
imports "bitmap" from "MLkit"; | ||
|
||
let data = readImage(file.path(@dir, "/../1537192287563.jpg" )); | ||
let regions = bitmap::slic(data,region_size = 0.3, | ||
iterations = 10); | ||
|
||
regions = as.data.frame(regions); | ||
|
||
setwd(@dir); | ||
|
||
bitmap(file = "./demo2.png") { | ||
plot(regions$x, regions$y, | ||
class = regions$cluster, | ||
colors = "paper", | ||
point.size = 5, | ||
reverse=TRUE ); | ||
}; | ||
|