-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bn fusion, started work on integration
- Loading branch information
Tuomas Frondelius
committed
Sep 5, 2018
1 parent
96cf1da
commit 2dbb59a
Showing
19 changed files
with
1,702 additions
and
307 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
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,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Kitware.VTK; | ||
|
||
namespace HistoGrading.Components | ||
{ | ||
class Interaction | ||
{ | ||
//Declarations | ||
static vtkRenderWindow renWin; | ||
|
||
//Public methods | ||
public void set_renderer(vtkRenderWindow input_renwin) | ||
{ | ||
renWin = input_renwin; | ||
} | ||
public vtkRenderWindowInteractor coordinate_interactor() | ||
{ | ||
//Declare new interactor style | ||
vtkInteractorStyle interactorSyle = vtkInteractorStyle.New(); | ||
|
||
//Set new mouse events | ||
interactorSyle.LeftButtonPressEvt += null; | ||
interactorSyle.LeftButtonReleaseEvt += new vtkObject.vtkObjectEventHandler(get_coordinates); | ||
|
||
//Create new interactor | ||
vtkRenderWindowInteractor interactor = vtkRenderWindowInteractor.New(); | ||
interactor.SetInteractorStyle(interactorSyle); | ||
|
||
return interactor; | ||
} | ||
|
||
//Interactors | ||
private static void get_coordinates(vtkObject sender, vtkObjectEventArgs e) | ||
{ | ||
int[] cur = renWin.GetPosition(); | ||
string txt = ""; | ||
foreach(int num in cur) | ||
{ | ||
txt += System.String.Format("{0}",num); | ||
txt += "|"; | ||
} | ||
StreamWriter file = new StreamWriter(@"C:\\users\\jfrondel\\desktop\\GITS\\VTKOUTPUT.txt"); | ||
file.WriteLine(txt); | ||
} | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27428.2015 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CNTKIntegration", "CNTKIntegration\CNTKIntegration.csproj", "{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Debug|x64.ActiveCfg = Debug|x64 | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Debug|x64.Build.0 = Debug|x64 | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Release|x64.ActiveCfg = Release|x64 | ||
{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}.Release|x64.Build.0 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7361E0DF-AC8E-4D38-9310-21114107E1CE} | ||
EndGlobalSection | ||
EndGlobal |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
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,113 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\build\OpenCvSharp3-AnyCPU.props" Condition="Exists('..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\build\OpenCvSharp3-AnyCPU.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{DF287675-FBD0-4E44-AC82-7A5B3DC9F5B5}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>CNTKIntegration</RootNamespace> | ||
<AssemblyName>CNTKIntegration</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\x64\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
<OutputPath>bin\x64\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Cntk.Core.Managed-2.5.1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21fff2ec8197defe, processorArchitecture=AMD64"> | ||
<HintPath>..\packages\CNTK.CPUOnly.2.5.1\lib\net45\x64\Cntk.Core.Managed-2.5.1.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Kitware.mummy.Runtime, Version=1.0.2.599, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44, processorArchitecture=AMD64"> | ||
<HintPath>..\packages\Activiz.NET.x64.5.8.0\lib\net20\Kitware.mummy.Runtime.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44, processorArchitecture=AMD64"> | ||
<HintPath>..\packages\Activiz.NET.x64.5.8.0\lib\net20\Kitware.VTK.dll</HintPath> | ||
</Reference> | ||
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\lib\net46\OpenCvSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\lib\net46\OpenCvSharp.Blob.dll</HintPath> | ||
</Reference> | ||
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\lib\net46\OpenCvSharp.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="OpenCvSharp.UserInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\lib\net46\OpenCvSharp.UserInterface.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Components\DataTypes.cs" /> | ||
<Compile Include="Components\Functions.cs" /> | ||
<Compile Include="Models\UNet.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="..\packages\CNTK.Deps.MKL.2.5.1\build\net45\CNTK.Deps.MKL.targets" Condition="Exists('..\packages\CNTK.Deps.MKL.2.5.1\build\net45\CNTK.Deps.MKL.targets')" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\CNTK.Deps.MKL.2.5.1\build\net45\CNTK.Deps.MKL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.MKL.2.5.1\build\net45\CNTK.Deps.MKL.targets'))" /> | ||
<Error Condition="!Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.5.1\build\net45\CNTK.Deps.OpenCV.Zip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.OpenCV.Zip.2.5.1\build\net45\CNTK.Deps.OpenCV.Zip.targets'))" /> | ||
<Error Condition="!Exists('..\packages\CNTK.CPUOnly.2.5.1\build\net45\CNTK.CPUOnly.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.CPUOnly.2.5.1\build\net45\CNTK.CPUOnly.targets'))" /> | ||
<Error Condition="!Exists('..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\build\OpenCvSharp3-AnyCPU.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp3-AnyCPU.3.4.1.20180830\build\OpenCvSharp3-AnyCPU.props'))" /> | ||
</Target> | ||
<Import Project="..\packages\CNTK.Deps.OpenCV.Zip.2.5.1\build\net45\CNTK.Deps.OpenCV.Zip.targets" Condition="Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.5.1\build\net45\CNTK.Deps.OpenCV.Zip.targets')" /> | ||
<Import Project="..\packages\CNTK.CPUOnly.2.5.1\build\net45\CNTK.CPUOnly.targets" Condition="Exists('..\packages\CNTK.CPUOnly.2.5.1\build\net45\CNTK.CPUOnly.targets')" /> | ||
</Project> |
100 changes: 100 additions & 0 deletions
100
CNTKIntegration/CNTKIntegration/Components/DataTypes.cs
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,100 @@ | ||
using System; | ||
using System.IO; | ||
using System.Drawing; | ||
using System.Runtime.InteropServices; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Kitware.VTK; | ||
using OpenCvSharp; | ||
using OpenCvSharp.Extensions; | ||
|
||
namespace CNTKIntegration.Components | ||
{ | ||
class DataTypes | ||
{ | ||
//3D byte array to vtkimagedata | ||
public static vtkImageData byteToVTK(byte[,,] data) | ||
{ | ||
//Get input dimensions | ||
int[] dims = new int[] { data.GetLength(0), data.GetLength(1), data.GetLength(2) }; | ||
//Create VTK data for putput | ||
vtkImageData vtkdata = vtkImageData.New(); | ||
//Character array for conversion | ||
vtkUnsignedCharArray charArray = vtkUnsignedCharArray.New(); | ||
//Pin byte array | ||
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned); | ||
//Set character array input | ||
charArray.SetArray(pinnedArray.AddrOfPinnedObject(), dims[0] * dims[1] * dims[2], 1); | ||
//Set vtkdata properties and connect array | ||
//Data from char array | ||
vtkdata.GetPointData().SetScalars(charArray); | ||
//Number of scalars/pixel | ||
vtkdata.SetNumberOfScalarComponents(1); | ||
//Data extent, 1st and last axis are swapped from the char array | ||
//Data is converted back to original orientation | ||
vtkdata.SetExtent(0, dims[0] - 1, 0, dims[1] - 1, 0, dims[2] - 1); | ||
//Scalar type | ||
vtkdata.SetScalarTypeToUnsignedChar(); | ||
vtkdata.Update(); | ||
|
||
//Return vtk data | ||
return vtkdata; | ||
} | ||
|
||
//vtkimagedata to 1d byte array | ||
public static byte[] vtkToByte(vtkImageData vtkdata) | ||
{ | ||
//Get vtk data dimensions | ||
int[] extent = vtkdata.GetExtent(); | ||
int[] dims = new int[] { extent[1] - extent[0], extent[3] - extent[2], extent[5] - extent[4] }; | ||
//New byte array for conversions | ||
byte[] bytedata = new byte[dims[0] * dims[1] * dims[2]]; | ||
//pin bytedata to memory | ||
GCHandle pinnedArray = GCHandle.Alloc(bytedata, GCHandleType.Pinned); | ||
//Get pointer to pinned array | ||
IntPtr ptr = pinnedArray.AddrOfPinnedObject(); | ||
//VTK exporter | ||
vtkImageExport exporter = vtkImageExport.New(); | ||
//Connect input data to exporter | ||
exporter.SetInput(vtkdata); | ||
exporter.Update(); | ||
//Export data to byte array | ||
exporter.Export(ptr); | ||
//Free pinned array | ||
pinnedArray.Free(); | ||
//Return byte array | ||
return bytedata; | ||
} | ||
|
||
//byte array to float | ||
public static float[] byteToFloat(byte[] bytedata, float mu = (float)0, float sd = (float)0) | ||
{ | ||
//Empty array for putput | ||
float[] floatdata = new float[bytedata.Length]; | ||
|
||
//Iterate over bytedata | ||
Parallel.For(0,bytedata.Length, k => | ||
{ | ||
//If normalization parameters are not give, return bytedata cast as float data | ||
if (mu == 0) | ||
{ | ||
floatdata[k] = (float)bytedata[k]; | ||
} | ||
//Otherwise normalize data | ||
else | ||
{ | ||
floatdata[k] = (float)bytedata[k]-mu; | ||
if (sd != 0) | ||
{ | ||
floatdata[k] /= sd; | ||
} | ||
} | ||
}); | ||
|
||
//return float data | ||
return floatdata; | ||
} | ||
} | ||
} |
Oops, something went wrong.