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
| #region Background Thread Worker
/// <summary>
/// When image processing is done
/// </summary>
void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressText.Text = "Processing complete! " + e.Error.Message;
}
public delegate void Run(out double result, BitmapImage img1, BitmapImage img2);
/// <summary>
/// Process images in background
/// </summary>
void DoWork(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(500);
double r;
Mark m;
//processing count
int n = 0;
foreach (PictureGroup pg in data.groups) n += pg.picturesWithDistorsion.Count; //image count
n *= 2;//2 processings: PSNR & SSIM
//process images
int i = 0;
foreach (PictureGroup pg in data.groups)
{
foreach (Picture p in pg.picturesWithDistorsion)
{
r = modules.metrics.RunnableMetric.PSNR(pg.original.pixels, p.pixels, pg.original.Width, pg.original.Height);
m = new Mark { filename = p.file.Name, mosp = r, metric = "PSNR" };
p.marks.Add(m);
bw.ReportProgress(100 * (++i / n));
r = modules.metrics.RunnableMetric.SSIM(pg.original.pixels, p.pixels, pg.original.Width, pg.original.Height);
m = new Mark { filename = p.file.Name, mosp = r, metric = "SSIM" };
p.marks.Add(m);
bw.ReportProgress(100 * (++i / n));
}
}
}
/// <summary>
/// Update display (progressbar & text)
/// </summary>
void ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressText.Text = "Processing images...";
progress.Value = e.ProgressPercentage;
if (OriginalList.Items.Count > 0 && OriginalList.SelectedIndex == -1) OriginalList.SelectedIndex = 0;
}
#endregion |
Partager