This repository was archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogramDrawer.cs
More file actions
55 lines (49 loc) · 1.65 KB
/
HistogramDrawer.cs
File metadata and controls
55 lines (49 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using ComputerGraphics0.Filters;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Linq;
using SixLabors.ImageSharp.Processing;
namespace ComputerGraphics0;
public class HistogramDrawer : IImageFilter
{
public string Name => "histogram";
public Image<Argb32> Process(Image<Argb32> source)
{
int[] histR = new int[256];
int[] histG = new int[256];
int[] histB = new int[256];
for (int i = 0; i < source.Width; i++)
{
for (int j = 0; j < source.Height; j++)
{
histR[source[i, j].R]++;
histG[source[i, j].G]++;
histB[source[i, j].B]++;
}
}
int maxR = histR.Max();
int maxG= histG.Max();
int maxB = histB.Max();
Image<Argb32> result = new Image<Argb32>(2560, maxR + maxG + maxB);
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < histR[i]; j++)
{
for (int k = 0; k < 10; k++)
result[i*10+k, result.Height - j - 1] = new Argb32(255, 0, 0);
}
for (int j = 0; j < histG[i]; j++)
{
for (int k = 0; k < 10; k++)
result[i*10+k, result.Height - j - maxR - 1] = new Argb32(0, 255, 0);
}
for (int j = 0; j < histB[i]; j++)
{
for (int k = 0; k < 10; k++)
result[i*10+k, result.Height - j - maxR - maxG - 1] = new Argb32(0, 0, 255);
}
}
result.Mutate(x=>x.Resize(result.Width, 2560));
return result;
}
}