-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProcessing.cs
884 lines (637 loc) · 28.6 KB
/
ImageProcessing.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO.Compression;
using System.Linq;
using System.Text;
using DIP_START;
namespace DIP_Project
{
public class ThresholdEventArgs : EventArgs
{
public int Max { get; set; }
public ThresholdEventArgs(int newMax)
{
Max = newMax;
}
}
public class ImageProcessing
{
public event EventHandler MaxValueChanged;
public void OnMaxChanged(ThresholdEventArgs e)
{
if (MaxValueChanged != null)
MaxValueChanged(this, e);
}
private int _maxValue = 255; // going to be 255 at very least
//public Bitmap original_image, proc_image;
private readonly int[] _sobelGx = { -1, -2, -1, 0, 0, 0, 1, 2, 1 };
private readonly int[] _sobelGy = { -1, 0, 1, -2, 0, 2, -1, 0, 1 };
private readonly int[] _laplacian = { 0, 1, 0, 1, -4, 1, 0, 1, 0 }; // lect 3 slide 17
private readonly int[] _pointDet = { -1, -1, -1, -1, 8, -1, -1, -1, -1 };
private readonly int[] _horizontal = { -1, -1, -1, 2, 2, 2, -1, -1, -1 };
private readonly int[] _vertical = { -1, 2, -1, -1, 2, -1, -1, 2, -1 };
private readonly int[] _pos45 = { -1, -1, 2, -1, 2, -1, 2, -1, -1 };
private readonly int[] _neg45 = { 2, -1, -1, -1, 2, -1, -1, -1, 2 };
public ImageProcessing()
{
}
// -----------------------------------------
// -------------- Inverse ------------------
// -----------------------------------------
private Bitmap InverseVideo(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
int width = original.Width;
int height = original.Height;
Rectangle r = new Rectangle(535, 50, width, height);
Rectangle r2 = new Rectangle(0, 0, width, height);
var proc_image = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData bmData = proc_image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
p[0] = (byte)(255 - p[0]);
++p;
}
}
}
proc_image.UnlockBits(bmData);
return proc_image;
}
// -----------------------------------------
// -------------- Darken- ------------------
// -----------------------------------------
private Bitmap Darken(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
int width = original.Width;
int height = original.Height;
Rectangle r = new Rectangle(535, 50, width, height);
Rectangle r2 = new Rectangle(0, 0, width, height);
var proc_image = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData bmData = proc_image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if (p[0] > 120)
{
if (p[0] < 195)
p[0] = 0;
}
++p;
}
}
}
proc_image.UnlockBits(bmData);
return proc_image;
}
// -----------------------------------------
// -------------- Brighten------------------
// -----------------------------------------
private Bitmap Brighten(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
int width = original.Width;
int height = original.Height;
Rectangle r2 = new Rectangle(0, 0, width, height);
var procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData bmData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if (p[0] > 10 && p[0] < 100)
{
p[0] = 255;
}
++p;
}
}
}
procImage.UnlockBits(bmData);
return procImage;
}
// -----------------------------------------
// -------------- Binarize------------------
// -----------------------------------------
public Bitmap Binarize(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
int width = original.Width;
int height = original.Height;
Rectangle r2 = new Rectangle(0, 0, width, height);
Bitmap procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData bmData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite,
PixelFormat.Format8bppIndexed);
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
if (*p >= threshold)
{
*p = 255;
if (threshold == 255 && *p == 255)
*p = 0;
}
else
{
*p = 0;
}
p++;
}
}
}
procImage.UnlockBits(bmData);
return procImage;
}
// -----------------------------------------
// ------- Neighbourhood Averaging----------
// -----------------------------------------
public Bitmap NeighbourhoodAveraging(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
// One method will serve Averaging with and Without thresholding
int width = original.Width - 2;
int height = original.Height - 2;
Rectangle r2 = new Rectangle(0, 0, original.Width, original.Height);
Bitmap procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData procData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
IntPtr origScan0 = origData.Scan0;
var procScan0 = procData.Scan0;
unsafe
{
byte* o = (byte*)(void*)origScan0;
byte* p = (byte*)(void*)procScan0;
for (int y = 0; y < height; ++y)
{
// Ensure on correct row
p = (byte*)(void*)procScan0 + (y * strideOrig);
o = (byte*)(void*)origScan0 + (y * strideOrig);
for (int x = 0; x < width; ++x)
{
var p1 = *o;
var p2 = *(o + 1);
var p3 = *(o + 2);
var p4 = *(o + strideOrig);
//var p5 = (o + strideOrig + 1)[0];
var p6 = *(o + strideOrig + 2);
var p7 = *(o + strideOrig * 2);
var p8 = *(o + strideOrig * 2 + 1);
var p9 = *(o + strideOrig * 2 + 2);
var avg = (byte)((p1 + p2 + p3 + p4 + p6 + p7 + p8 + p9) / 8);
// if below threshold change else leave alone
if (*(p + strideOrig + 1) <= threshold)
*(p + strideOrig + 1) = avg;
++p;
++o;
}
}
}
original.UnlockBits(origData);
procImage.UnlockBits(procData);
return procImage;
}
// -----------------------------------------
// --------- Median Filtering---------------
// -----------------------------------------
public Bitmap Median(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
int width = original.Width - 2;
int height = original.Height - 2;
Rectangle r2 = new Rectangle(0, 0, width, height);
Bitmap procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData procData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
IntPtr origScan0 = origData.Scan0;
var procScan0 = procData.Scan0;
List<Byte> byteMe = new List<byte>();
unsafe
{
byte* o = (byte*)(void*)origScan0;
byte* p = (byte*)(void*)procScan0;
for (int y = 0; y < height; ++y)
{
// Ensure on correct row
p = (byte*)(void*)procScan0 + (y * strideOrig);
o = (byte*)(void*)origScan0 + (y * strideOrig);
for (int x = 0; x < width; ++x)
{
var p1 = *o;
var p2 = *(o + 1);
var p3 = *(o + 2);
var p4 = *(o + strideOrig);
var p5 = *(o + strideOrig + 1);
var p6 = *(o + strideOrig + 2);
var p7 = *(o + strideOrig * 2);
var p8 = *(o + strideOrig * 2 + 1);
var p9 = *(o + strideOrig * 2 + 2);
byteMe = new List<byte>() { p1, p2, p3, p4, p5, p6, p7, p8, p9 };
byteMe.Sort();
*(p + strideOrig + 1) = byteMe[4];
++p;
++o;
}
}
}
original.UnlockBits(origData);
procImage.UnlockBits(procData);
return procImage;
}
// -----------------------------------------
// --------- Roberts Gradient --------------
// ----------With and Without --------------
// ----------Thresholding-------------------
// -----------------------------------------
public Bitmap RobertsGradient(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
const int borderAllowance = 1;
int width = original.Width - borderAllowance;
int height = original.Height - borderAllowance;
Rectangle r2 = new Rectangle(0, 0, width, height);
Bitmap procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData procData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
IntPtr origScan0 = origData.Scan0;
var procScan0 = procData.Scan0;
List<Byte> byteMe = new List<byte>();
unsafe
{
byte* o = (byte*)(void*)origScan0;
byte* p = (byte*)(void*)procScan0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
var a = o[y * strideOrig + x];
var b = o[(y + 1) * strideOrig + x + 1];
var c = o[(y + 1) * strideOrig + x];
var d = o[y * strideOrig + x + 1];
var result = Math.Abs(a - b) + Math.Abs(c - d);
if (result >= threshold && threshold != 255)
p[y * strideOrig + x] = 0;
else
p[y * strideOrig + x] = 255;
}
}
}
original.UnlockBits(origData);
procImage.UnlockBits(procData);
return procImage;
}
// ------------------------------------------------------
// -------Roberts Gradient With Pseudo ------------------
// ------------------------------------------------------
public Bitmap RobertsGradientWithPseudo(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(255));
const int borderAllowance = 1;
int width = original.Width - borderAllowance;
int height = original.Height - borderAllowance;
Rectangle r2 = new Rectangle(0, 0, width, height);
Bitmap procImage = new Bitmap(width, height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(procImage))
{
g.PageUnit = GraphicsUnit.Pixel;
g.DrawImage(original, r2);
}
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
IntPtr origScan0 = origData.Scan0;
List<Byte> byteMe = new List<byte>();
unsafe
{
byte* o = (byte*)(void*)origScan0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
var a = o[y * strideOrig + x];
var b = o[(y + 1) * strideOrig + x + 1];
var c = o[(y + 1) * strideOrig + x];
var d = o[y * strideOrig + x + 1];
var result = Math.Abs(a - b) + Math.Abs(c - d);
if (result >= threshold && threshold != 255)
{
procImage.SetPixel(x, y, Color.Red);
}
}
}
}
original.UnlockBits(origData);
return procImage;
}
// ----------------------------------------------------
// ------ Sobel/Laplacian/Point/Line Filters ----------
// ----------------------------------------------------
public Bitmap Execute_Filter(Bitmap original, int[] filter, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(_maxValue));
const int borderAllowance = 2;
int width = original.Width - borderAllowance;
int height = original.Height - borderAllowance;
var _3X3Selection = new int[9];
Rectangle r2 = new Rectangle(0, 0, original.Width, original.Height);
Bitmap procImage = original.Clone(r2, PixelFormat.Format8bppIndexed);
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData procData = procImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
System.IntPtr origScan0 = origData.Scan0;
System.IntPtr procScan0 = procData.Scan0;
unsafe
{
byte* o = (byte*)(void*)origScan0;
byte* p = (byte*)(void*)procScan0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
_3X3Selection[0] = o[y * strideOrig + x];
_3X3Selection[1] = o[y * strideOrig + x + 1];
_3X3Selection[2] = o[y * strideOrig + x + 2];
_3X3Selection[3] = o[(y + 1) * strideOrig + x];
_3X3Selection[4] = o[(y + 1) * strideOrig + x + 1];
_3X3Selection[5] = o[(y + 1) * strideOrig + x + 2];
_3X3Selection[6] = o[(y + 2) * strideOrig + x];
_3X3Selection[7] = o[(y + 2) * strideOrig + x + 1];
_3X3Selection[8] = o[(y + 2) * strideOrig + x + 2];
int gx = 0;
for (int i = 0; i < _3X3Selection.Length; i++)
{
gx += filter[i] * _3X3Selection[i];
}
if (Math.Abs(gx) >= threshold)
{
p[(y + 1) * strideOrig + x + 1] = 255;
}
else
{
p[(y + 1) * strideOrig + x + 1] = 0;
}
if (gx > _maxValue)
{
double m = Math.Ceiling(gx / 100f) * 100;
_maxValue = (int)m;
}
}
}
}
original.UnlockBits(origData);
procImage.UnlockBits(procData);
return procImage;
}
private Bitmap Calculate_GxGy(Bitmap original, int threshold)
{
MaxValueChanged(this, new ThresholdEventArgs(_maxValue));
// compare gx and gy and if either is greater than the threshold then 255
// else 0
const int BorderAllowance = 2;
var width = original.Width - BorderAllowance;
var height = original.Height - BorderAllowance;
Bitmap newBitmap = new Bitmap(
width, height, PixelFormat.Format8bppIndexed);
int[] _3X3Selection = new int[9];
BitmapData origData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData procData = newBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int strideOrig = origData.Stride;
System.IntPtr origScan0 = origData.Scan0;
System.IntPtr newScan0 = procData.Scan0;
unsafe
{
byte* o = (byte*)(void*)origScan0;
byte* c = (byte*)(void*)newScan0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
_3X3Selection[0] = o[y * strideOrig + x];
_3X3Selection[1] = o[y * strideOrig + x + 1];
_3X3Selection[2] = o[y * strideOrig + x + 2];
_3X3Selection[3] = o[(y + 1) * strideOrig + x];
_3X3Selection[4] = o[(y + 1) * strideOrig + x + 1];
_3X3Selection[5] = o[(y + 1) * strideOrig + x + 2];
_3X3Selection[6] = o[(y + 2) * strideOrig + x];
_3X3Selection[7] = o[(y + 2) * strideOrig + x + 1];
_3X3Selection[8] = o[(y + 2) * strideOrig + x + 2];
int gx = 0;
int gy = 0;
for (int i = 0; i < _3X3Selection.Length; i++)
{
gx += _sobelGx[i] * _3X3Selection[i];
}
for (int i = 0; i < _3X3Selection.Length; i++)
{
gy += _sobelGy[i] * _3X3Selection[i];
}
if (Math.Abs(gx) + Math.Abs(gy) >= threshold)
{
c[(y + 1) * strideOrig + x + 1] = 255;
}
else
{
c[(y + 1) * strideOrig + x + 1] = 0;
}
if ((Math.Abs(gx) + Math.Abs(gy)) > _maxValue)
{
double m = Math.Ceiling((Math.Abs(gx) + Math.Abs(gy)) / 100f) * 100;
_maxValue = (int)m;
}
}
}
}
original.UnlockBits(origData);
newBitmap.UnlockBits(procData);
return newBitmap;
}
//------------------------------------------------
//-----------Calculate Histogram Bins-------------
//------------------------------------------------
public int[] CalculateHistogramBins(Bitmap _orig)
{
int[] Bins = new int[256];
int width = _orig.Width;
int height = _orig.Height;
BitmapData bmData = _orig.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite,
PixelFormat.Format8bppIndexed);
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
Bins[*p]++;
p++;
}
}
}
_orig.UnlockBits(bmData);
return Bins;
}
// -------------------------------------------------------------------
// ------------------ Histogram Equalisation -------------------------
// -------------------------------------------------------------------
public Bitmap HistogramEqualisation(Bitmap _orig)
{
int[] Bins = CalculateHistogramBins(_orig);
int n = _orig.Width * _orig.Height;
double[] nkn = new double[256];
double[] cdf = new double[256];
double runningTotal = 0;
for (int i = 0; i < Bins.Length; i++)
{
var nV = Bins[i] / (double)n;
nkn[i] = nV;
runningTotal += nV;
cdf[i] = runningTotal;
}
int width = _orig.Width;
int height = _orig.Height;
Bitmap newBitmap = _orig.Clone(new Rectangle(0, 0, width, height), PixelFormat.Format8bppIndexed);
BitmapData newData = newBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite,
PixelFormat.Format8bppIndexed);
BitmapData bmData = _orig.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly,
PixelFormat.Format8bppIndexed);
IntPtr nScan0 = newData.Scan0;
IntPtr oScan0 = bmData.Scan0;
unsafe
{
byte* o = (byte*)(void*)oScan0;
byte* p = (byte*)(void*)nScan0;
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
double b = Math.Round(cdf[*o] * 255);
*p = (byte)b;
//Console.WriteLine(b);
o++;
p++;
}
}
}
newBitmap.UnlockBits(newData);
_orig.UnlockBits(bmData);
return newBitmap;
}
public Bitmap Execute(Process process, Bitmap original, int threshold)
{
switch (process)
{
case Process.Inverse:
return InverseVideo(original, threshold);
case Process.Darken:
return Darken(original, threshold);
case Process.Brighten:
return Brighten(original, threshold);
case Process.Binarize:
return Binarize(original, threshold);
case Process.NeighbourhoodAveraging:
return NeighbourhoodAveraging(original, threshold);
case Process.Median:
return Median(original, threshold);
case Process.RobertsGradientDirect:
case Process.RobertsGradientWithThresholding:
return RobertsGradient(original, threshold);
case Process.RobertsGradientWithPseudoColor:
return RobertsGradientWithPseudo(original, threshold);
case Process.SobelGx:
return Execute_Filter(original, _sobelGx, threshold);
case Process.SobelGy:
return Execute_Filter(original, _sobelGy, threshold);
case Process.SobelGxGy:
return Calculate_GxGy(original, threshold);
case Process.Laplacian:
return Execute_Filter(original, _laplacian, threshold);
case Process.PointDetection:
return Execute_Filter(original, _pointDet, threshold);
case Process.HorizontalLine:
return Execute_Filter(original, _horizontal, threshold);
case Process.VerticalLine:
return Execute_Filter(original, _vertical, threshold);
case Process.Pos45DegreeLine:
return Execute_Filter(original, _pos45, threshold);
case Process.Negative45DegreeLine:
return Execute_Filter(original, _neg45, threshold);
case Process.HistogramEqualisation:
return HistogramEqualisation(original);
case Process.GrayPalette:
return GrayPalette();
default:
return null;
}
}
private Bitmap GrayPalette()
{
int grey = 0;
var width = 512;
var height = 512;
Rectangle r2 = new Rectangle(0, 0, width, height);
Bitmap procImage = new Bitmap(width, height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(procImage))
{
g.PageUnit = GraphicsUnit.Pixel;
g.DrawImage(procImage, r2);
}
int x = 0;
int col_block = 32;
int row_block = 32;
int count = 0;
int nextrow = 0;
for (int i = 0; i < 16; i++)
{
for (int y = nextrow; y < row_block; y++)
{
while (col_block < width+1)
{
while (x < col_block)
{
procImage.SetPixel(x, y, Color.FromArgb(grey, grey, grey));
x++;
}
col_block += 32;
}
count++;
grey = count/2;
col_block = 32;
x = 0;
}
nextrow += 32;
row_block += 32;
}
Console.WriteLine(count);
return procImage;
}
}
}