private void ApplyAlgorithmToGroup() { _groupReporting = true; string[] names = openFileDialog.FileNames; int processedCount = 0; double averageCompression = 0; double averageAccuracy = 0; double averageCompressingTime = 0; double averageDecompressingTime = 0; for (int i = 0; i < names.Length; i++) { try { _originalImage = new MemoryStream(File.ReadAllBytes(names[i])); Del del = tsmApplyAlgorithm_Click; this.Invoke(del, null, null); averageCompression += _compression; averageAccuracy += ImageComparator.CalculateImagesEquality(_originalImage, _resultImage); averageCompressingTime += _compressingTime; averageDecompressingTime += _decompressingTime; processedCount++; } catch { } this.rtbStatistic.BeginInvoke((MethodInvoker) (() => this.rtbStatistic.Text = $"Processed images: {processedCount}")); this.progressBarGroupProcessing.BeginInvoke((MethodInvoker) (() => this.progressBarGroupProcessing.Value = (int)(i * 1000.0 / names.Length))); } averageCompression /= processedCount; averageAccuracy /= processedCount; averageCompressingTime /= processedCount; averageDecompressingTime /= processedCount; string report = MakeGroupReport(processedCount, averageCompression, averageAccuracy, averageCompressingTime, averageDecompressingTime); this.rtbStatistic.BeginInvoke((MethodInvoker) (() => this.rtbStatistic.Text = report)); this.progressBarGroupProcessing.BeginInvoke((MethodInvoker) (() => this.progressBarGroupProcessing.Value = 0)); Thread.Sleep(300); _groupReporting = false; GC.Collect(); }
private string MakeReport(Stream parCompressedImage) { StringBuilder report = new StringBuilder(); report.AppendLine(String.Format("Original image size: {0} bytes", _originalImage.Length)); report.AppendLine(String.Format("Compressed image size: {0} bytes", parCompressedImage.Length)); report.AppendLine(String.Format("Decompressed image size: {0} bytes", _resultImage.Length)); report.AppendLine(String.Format("Total compression: {0}%", _compression)); report.AppendLine(String.Format("Algorithm: {0}", _algorithm)); report.AppendLine(String.Format("Parameters: {0}", _algorithmParameters)); double accuracy = ImageComparator.CalculateImagesEquality(_originalImage, _resultImage); report.AppendLine(String.Format("Accuracy: {0}%", accuracy * 100)); report.AppendLine(String.Format("Compressing time: {0} ms", _compressingTime)); report.Append(String.Format("Decompressing time: {0} ms", _decompressingTime)); return(report.ToString()); }