Skip to content
Snippets Groups Projects
Commit 387c74a3 authored by kunzst72230's avatar kunzst72230
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
File added
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
\ No newline at end of file
Batman.png

284 KiB

Batman16.png

34.6 KiB

Batman2.png

7.03 KiB

Batman32.png

43.3 KiB

Batman4.png

14.3 KiB

Batman8.png

20.8 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
namespace k_means_Algorithmus
{
class Program
{
static int AnzahlCluster = 256;
static string DataName = "color";
static Random random = new Random();
static void Main(string[] args)
{
Bitmap originalImage = new Bitmap("D:/Desktop/Medieninformatik/6. Semester/Medienverarbeitung/k-means-Algorithmus/" + DataName + ".png");
int height = originalImage.Height;
int width = originalImage.Width;
List<PointData> PointDataList = new List<PointData>();
Color pixel;
for (int i = 0; i < width; i++) // Fügt alle Pixel in PointDataList ein
{
for (int j = 0; j < height; j++)
{
if (/*((i + j)) % 100 == 0*/ true) {
pixel = originalImage.GetPixel(i, j);
PointData point = new PointData(i, j, pixel.R, pixel.G, pixel.B);
PointDataList.Add(point);
}
}
}
Console.WriteLine(PointDataList.Count());
//foreach (PointData Point in PointDataList)
//{
// if((Point.x +Point.y) % 100 == 0)
// {
// Console.WriteLine(Point.red + ", " + Point.green + ", " + Point.blue + ": "+ Point.groupnumber);
// }
//}
Console.WriteLine("-------------------");
List<ClusterPoint> ClusterPointList = new List<ClusterPoint>();
for (int i = 0; i < AnzahlCluster; i++)
{
pixel = originalImage.GetPixel(random.Next(0, width), random.Next(0, height));
ClusterPoint temp = new ClusterPoint(0, 0, pixel.R, pixel.G, pixel.B, i);
ClusterPointList.Add(temp);
Console.WriteLine("c"+ i +" Punkt: " + temp.red + ", " + temp.green + ", " + temp.blue + ", " + temp.clustergroup);
}
int iteration = 0;
while(iteration < 10)
{
//Euklidische Distanz berechnen
foreach (PointData Point in PointDataList)
{
int counter = 0;
double[] distance = new double[ClusterPointList.Count];
double lastdistance = distance[0];
foreach (ClusterPoint cluster in ClusterPointList)
{
double dx = cluster.red - Point.red;
double dy = cluster.green - Point.green;
double dz = cluster.blue - Point.blue;
distance[counter] = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2) + Math.Pow(dz, 2));
if ((distance[counter] <= lastdistance) || counter == 0)
{
Point.groupnumber = cluster.clustergroup;
//Console.WriteLine(Point.groupnumber);
lastdistance = distance[counter];
}
counter++;
}
}
//foreach (PointData Point in PointDataList)
//{
// Console.WriteLine(Point.red + ", " + Point.green + ", " + Point.blue + ", " + Point.groupnumber);
//}
//Console.WriteLine("-------------------------");
foreach (ClusterPoint cluster in ClusterPointList)
{
//Console.WriteLine(cluster.groupnumber);
double summx = 0, summy = 0, summz = 0;
int counter = 0;
foreach (PointData Point in PointDataList)
{
if (Point.groupnumber == cluster.clustergroup)
{
summx += Point.red;
summy += Point.green;
summz += Point.blue;
counter++;
}
}
if (counter != 0)
{
cluster.red = (int)(summx / counter);
cluster.green = (int)(summy / counter);
cluster.blue = (int)(summz / counter);
}
//Console.WriteLine("||c" + cluster.clustergroup + ": " + counter + "||");
}
foreach(ClusterPoint cluster in ClusterPointList)
{
//Console.WriteLine("c" + cluster.clustergroup +" Punkt: " + cluster.red + ", " + cluster.green + ", " + cluster.blue + ", " + cluster.clustergroup);
}
iteration++;
}
Bitmap image4 = new Bitmap(width, height);
foreach (ClusterPoint cluster in ClusterPointList)
{
foreach(PointData Point in PointDataList)
{
if(Point.groupnumber == cluster.clustergroup)
{
pixel = Color.FromArgb(255, cluster.red, cluster.green, cluster.blue);
image4.SetPixel((int)Point.x, (int)Point.y, pixel);
}
}
}
image4.Save("D:/Desktop/Medieninformatik/6. Semester/Medienverarbeitung/k-means-Algorithmus/" + DataName + AnzahlCluster + ".png");
}
}
public class PointData
{
public double x, y;
public int groupnumber;
public int red, green, blue;
public PointData(double x, double y, int red, int green, int blue, int groupnumber = 0)
{
this.x = x;
this.y = y;
this.groupnumber = groupnumber;
this.red = red;
this.green = green;
this.blue = blue;
}
}
public class ClusterPoint : PointData
{
public int clustergroup;
public ClusterPoint(double x, double y, int red, int green, int blue, int clustergroup) : base(x, y, red, green, blue)
{
this.clustergroup = clustergroup;
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("k-means-Algorithmus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("k-means-Algorithmus")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("c6962534-25b8-40e7-ae18-7d03e9b6fe59")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
File added
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
\ No newline at end of file
File added
color.png 0 → 100644
color.png

6.11 KiB

color16.png

5.16 KiB

color256.png

13.7 KiB

color4.png

2.95 KiB

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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>{C6962534-25B8-40E7-AE18-7D03E9B6FE59}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>k_means_Algorithmus</RootNamespace>
<AssemblyName>k-means-Algorithmus</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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>
<ItemGroup>
<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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30711.63
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "k-means-Algorithmus", "k-means-Algorithmus.csproj", "{C6962534-25B8-40E7-AE18-7D03E9B6FE59}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C6962534-25B8-40E7-AE18-7D03E9B6FE59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6962534-25B8-40E7-AE18-7D03E9B6FE59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6962534-25B8-40E7-AE18-7D03E9B6FE59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6962534-25B8-40E7-AE18-7D03E9B6FE59}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D64E9562-6811-4469-9EBA-A8F14D2000EB}
EndGlobalSection
EndGlobal
lama.png 0 → 100644
lama.png

213 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment