Skip to content

Commit

Permalink
Added median filter
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Oct 2, 2020
1 parent 4afe06c commit f362121
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 40 deletions.
Binary file modified .vs/MagickUtils/v16/.suo
Binary file not shown.
20 changes: 20 additions & 0 deletions FormsHelpers/EffectsTabHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class EffectsTabHelper
public static int blurRadiusMin;
public static int blurRadiusMax;

public static int medianRadiusMin;
public static int medianRadiusMax;

public static void NoisePreview ()
{
Program.mainForm.SetNoiseVars();
Expand Down Expand Up @@ -65,5 +68,22 @@ public static void BlurApply ()
Program.mainForm.SetBlurVars();
EffectsUtils.BlurDir(blurRadiusMin, blurRadiusMax);
}

public static void MedianPreview()
{
Program.mainForm.SetMedianVars();
FileInfo firstImg = IOUtils.GetFiles()[0];
string tempImgPath = Path.Combine(IOUtils.GetAppDataDir(), "medianpreview" + firstImg.Extension);
if (File.Exists(tempImgPath)) File.Delete(tempImgPath);
File.Copy(firstImg.FullName, tempImgPath);
EffectsUtils.Median(tempImgPath, medianRadiusMin, medianRadiusMax);
Program.mainForm.PreviewImage(tempImgPath);
}

public static void MedianApply()
{
Program.mainForm.SetMedianVars();
EffectsUtils.MedianDir(medianRadiusMin, medianRadiusMax);
}
}
}
32 changes: 30 additions & 2 deletions MagickUtils/EffectsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void Blur (string path, int radiusMin, int radiusMax)
var blur = new SuperfastBlur.GaussianBlur(image as Bitmap);
Random rand = new Random();
int blurRad = rand.Next(radiusMin, radiusMax + 1);
Program.Print("-> Using radius " + blurRad);
Program.Print("-> Using blur radius " + blurRad);
var result = blur.Process(blurRad);
string tempPath = Path.Combine(IOUtils.GetAppDataDir(), "blur-out.png");
result.Save(tempPath, ImageFormat.Png);
Expand Down Expand Up @@ -122,6 +122,34 @@ public static void EdgeDetect (string path)
PostProcessing(null, path, path);
}

public async static void MedianDir(int radiusMin, int radiusMax)
{
int counter = 1;
FileInfo[] files = IOUtils.GetFiles();

Program.PreProcessing();
foreach (FileInfo file in files)
{
Program.ShowProgress("Running Median Filter on Image ", counter, files.Length);
Median(file.FullName, radiusMin, radiusMax);
counter++;
if (counter % 2 == 0) await Program.PutTaskDelay();
}
Program.PostProcessing(true);
}

public static void Median(string path, int radiusMin, int radiusMax)
{
PreProcessing(path);
MagickImage img = new MagickImage(path);
Random rand = new Random();
int radius = rand.Next(radiusMin, radiusMax + 1);
Program.Print("-> Using median radius " + radius);
img.MedianFilter(radius);
img.Write(path);
PostProcessing(null, path, path);
}

static void PreProcessing (string path, string infoSuffix = null)
{
Program.Print("-> Processing " + Path.GetFileName(path) + " " + infoSuffix);
Expand All @@ -135,7 +163,7 @@ static void PostProcessing (MagickImage img, string sourcePath, string outPath,
img.Dispose();
long bytesPost = new FileInfo(outPath).Length;
//Program.Print("-> Done. Size pre: " + Format.Filesize(bytesPre) + " - Size post: " + Format.Filesize(bytesPost) + " - Ratio: " + Format.Ratio(bytesPre, bytesPost));
Program.Print("-> Done.");
Program.Print("Done.");
if(delSource)
DelSource(sourcePath);
}
Expand Down
188 changes: 152 additions & 36 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f362121

Please sign in to comment.