Skip to content

Commit

Permalink
Merge pull request #1 from Nhowka/master
Browse files Browse the repository at this point in the history
Single use of GetPixel per actual pixel
  • Loading branch information
juangallostra authored Jan 20, 2017
2 parents 6d1fe79 + a008b55 commit 40202d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions HelperMethods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -47,9 +47,10 @@ public static Image Convert2ASCII(Image BW_Image, List<WeightedChar> characters,
List<string> RowText = new List<string> { };
for (int i=0; i <BW_Image.Width;i++) // COLUMN
{
double targetvalue = (BlackAndWhite.GetPixel(i, j).R
+ BlackAndWhite.GetPixel(i, j).G
+ BlackAndWhite.GetPixel(i, j).B)/3;
Color pixel = BlackAndWhite.GetPixel(i, j);
double targetvalue = (pixel.R
+ pixel.G
+ pixel.B)/3;

WeightedChar closestchar = characters.Where(t=>Math.Abs(t.Weight-targetvalue)==characters.Min(e => Math.Abs(e.Weight - targetvalue))).FirstOrDefault();
RowText.Add(closestchar.Character);
Expand Down Expand Up @@ -138,8 +139,8 @@ public static Bitmap Grayscale(Image image)
for (int j = 0; j < btm.Height; j++)
{
// Visit https://en.wikipedia.org/wiki/Grayscale for 0.3, 0.59 & 0.11 values

int ser = (int)(btm.GetPixel(i, j).R*0.3 + btm.GetPixel(i, j).G*0.59 + btm.GetPixel(i, j).B*0.11);
Color pixel = btm.GetPixel(i, j);
int ser = (int)(pixel.R*0.3 + pixel.G*0.59 + pixel.B*0.11);
btm.SetPixel(i, j, Color.FromArgb(ser, ser, ser));
}
}
Expand Down
9 changes: 5 additions & 4 deletions Initialize.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -101,9 +101,10 @@ private static double GetWeight(char c, SizeF size)
{
for (int j = 0; j < btm.Height; j++)
{
totalsum = totalsum + (btm.GetPixel(i, j).R
+ btm.GetPixel(i, j).G
+ btm.GetPixel(i, j).B)/3;
Color pixel = btm.GetPixel(i, j);
totalsum = totalsum + (pixel.R
+ pixel.G
+ pixel.B)/3;
}
}
// Weight = (sum of (R+G+B)/3 for all pixels in image) / Area. (Where Area = Width*Height )
Expand Down

0 comments on commit 40202d1

Please sign in to comment.