.:: Sharpness Analyzer ::.
Image Sharpness Analyzer
A program written in C# that tells you which image is sharper.
SOFTWARE WRITTEN IN C#
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5: using System.Drawing;
6:
7: namespace EdgeDetection
8: {
9:
10: public enum SharpnessEquality
11: {
12: Equal,
13: LeftIsSharper,
14: RightIsSharper
15: }
16:
17: class Sharpness
18: {
19:
20: public static SharpnessEquality CompareSharpness(Bitmap bmp1, Bitmap bmp2, int Thresh)
21: {
22:
23: if (Thresh > 255 || Thresh < 0)
24: {
25: throw new System.ArgumentException("Threshold out of bounds", "Out of bounds exception");
26: }
27:
28: if ((bmp1.Width != bmp2.Width) || (bmp1.Height != bmp2.Height))
29: {
30: throw new System.ArgumentException("Images are not of equal size", "Image dimensions inequality exception");
31: }
32:
33: long Counter1 = 0;
34: for (int y = 0; y < bmp1.Height; y++)
35: {
36: for (int x = 0; x < bmp1.Width-1; x++)
37: {
38: Color c1 = bmp1.GetPixel(x, y);
39: int R1 = c1.R;
40: int G1 = c1.G;
41: int B1 = c1.B;
42: int Grey1 = (R1 + G1 + B1) / 3;
43:
44: Color c2 = bmp1.GetPixel(x+1, y);
45: int R2 = c2.R;
46: int G2 = c2.G;
47: int B2 = c2.B;
48: int Grey2 = (R2 + G2 + B2) / 3;
49:
50: if (Math.Abs(Grey1 - Grey2) > Thresh )
51: {
52: Counter1++;
53: }
54:
55: }
56: }
57:
58:
59:
60: long Counter2 = 0;
61: for (int y = 0; y < bmp2.Height; y++)
62: {
63: for (int x = 0; x < bmp2.Width - 1; x++)
64: {
65: Color c1 = bmp2.GetPixel(x, y);
66: int R1 = c1.R;
67: int G1 = c1.G;
68: int B1 = c1.B;
69: int Grey1 = (R1 + G1 + B1) / 3;
70:
71: Color c2 = bmp2.GetPixel(x + 1, y);
72: int R2 = c2.R;
73: int G2 = c2.G;
74: int B2 = c2.B;
75: int Grey2 = (R2 + G2 + B2) / 3;
76:
77: if (Math.Abs(Grey1 - Grey2) > Thresh)
78: {
79: Counter2++;
80: }
81:
82: }
83: }
84:
85:
86: SharpnessEquality ret;
87: if (Counter1 == Counter2)
88: {
89: ret = SharpnessEquality.Equal;
90: }
91: else
92: {
93: if (Counter1 > Counter2)
94: {
95: ret = SharpnessEquality.LeftIsSharper;
96: }
97: else
98: {
99: ret = SharpnessEquality.RightIsSharper;
100: }
101: }
102:
103: return ret;
104: }
105:
106: }
107: }