├── LICENSE ├── README.md ├── bjontegaard_etro.vba ├── bjontegaard_etro.xla ├── bjontegaard_etro_standalone_example.xlsm └── reference └── VCEG-M33.doc /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013 Tim Bruylants, ETRO, Vrije Universiteit Brussel 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ETRO's Bjontegaard Metric implementation for Excel. 2 | 3 | ## Description: 4 | 5 | Excel VBA code for calculating Bjontegaard Delta SNR and Rate, using arbitrary number of data points. The calculated results comply with VCEG-M33 when using 4 data points. 6 | 7 | Provides two functions (all arguments take cell ranges): 8 | 9 | BDSNR(BR1, PSNR1, BR2, PSNR2) 10 | BDBR(BR1, PSNR1, BR2, PSNR2) 11 | 12 | These functions are provided in two versions (both containing the exact same VBA code): 13 | 14 | 1. __bjontegaard_etro_standalone_example.xlsm__ is a stand-alone Excel sheet with the VBA routines internally in the file. It’s a macro-enabled Excel worksheet. 15 | 16 | 2. __bjontegaard_etro.xla__ is an Excel Add-In. By adding this on your system (via Excel Add-In preferences), the two functions become globally available in your Excel install. 17 | 18 | Note: A C++ implementation is also available as the [Bjontegaard CPP project](https://github.com/tbr/bjontegaard_cpp). 19 | 20 | ## Author: 21 | 22 | Tim Bruylants, ETRO, Vrije Universiteit Brussel 23 | 24 | This code was originally developed as part of the following publication: 25 | 26 | Tim Bruylants, Adrian Munteanu, Peter Schelkens, Wavelet based volumetric medical image compression, Signal Processing: Image Communication, Volume 31, February 2015, Pages 112-133, ISSN 0923-5965, http://dx.doi.org/10.1016/j.image.2014.12.007. 27 | Open access URL: http://www.sciencedirect.com/science/article/pii/S0923596514001854 28 | 29 | ## References: 30 | 31 | [1] G. Bjontegaard, Calculation of average PSNR differences between RD-curves (VCEG-M33) 32 | [2] S. Pateux, J. Jung, An excel add-in for computing Bjontegaard metric and its evolution 33 | 34 | _Copyright (C) 2013-2022 Tim Bruylants, ETRO, Vrije Universiteit Brussel._ 35 | -------------------------------------------------------------------------------- /bjontegaard_etro.vba: -------------------------------------------------------------------------------- 1 | ' Bjontegaard Metric implementation for Excel. 2 | ' 3 | ' Provides two functions as Add-In: 4 | ' BDSNR(BR1, PSNR1, BR2, PSNR2) 5 | ' Returns the delta-SNR Bjontegaard (in dB) 6 | ' 7 | ' BDBR(BR1, PSNR1, BR2, PSNR2) 8 | ' Returns the delta-rate Bjontegaard (in %) 9 | ' 10 | ' Author: 11 | ' Tim Bruylants, ETRO, Vrije Universiteit Brussel 12 | ' 13 | ' References: 14 | ' [1] G. Bjontegaard, Calculation of average PSNR differences between RD-curves (VCEG-M33) 15 | ' [2] S. Pateux, J. Jung, An excel add-in for computing Bjontegaard metric and its evolution 16 | ' 17 | ' The MIT License (MIT) 18 | ' Copyright (c) 2013 Tim Bruylants, ETRO, Vrije Universiteit Brussel 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy of this software 21 | ' and associated documentation files (the "Software"), to deal in the Software without 22 | ' restriction, including without limitation the rights to use, copy, modify, merge, publish, 23 | ' distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom 24 | ' the Software is furnished to do so, subject to the following conditions: 25 | ' 26 | ' The above copyright notice and this permission notice shall be included in all copies or 27 | ' substantial portions of the Software. 28 | ' 29 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 30 | ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 31 | ' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 32 | ' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 33 | ' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | ' DEALINGS IN THE SOFTWARE. 35 | 36 | ' Calculates Y(x), where the coefficients of polynomial are given by P 37 | Private Function bjontegaard_polyval(P As Variant, X As Double) 38 | Dim xPow As Double, result As Double 39 | 40 | result = 0 41 | xPow = 1 42 | For i = UBound(P) To 0 Step -1 43 | result = result + xPow * P(i) 44 | xPow = xPow * X 45 | Next i 46 | 47 | bjontegaard_polyval = result 48 | End Function 49 | 50 | ' Fits the curve and calculates the integral 51 | Private Function bjontegaard_polyfit_and_integrate(X As Variant, Y As Variant, lowX As Double, highX As Double) 52 | ' Constants (yes, the array is not a const, thanks to the great VBA language) 53 | Const order As Integer = 3 54 | Dim powerArray() As Variant 55 | powerArray = Array(1, 2, 3) ' match this array with the order const 56 | 57 | ' Get the number of points to use and check validity 58 | Dim noPoints As Integer 59 | noPoints = UBound(X) 60 | If noPoints <> UBound(Y) Then 61 | Err.Raise vbObjectError + 1, "avsnr_polyfit_and_integrate", "Number of X-values does not match the number of Y-values." 62 | End If 63 | 64 | ' Polyfit 3rd order and calculate polynomial coefficients 65 | Dim P 66 | P = Application.WorksheetFunction.LinEst(Y, Application.Power(X, Application.WorksheetFunction.Transpose(powerArray))) 67 | 68 | ' Integrate the polynomial 69 | For i = 1 To order 70 | P(i) = P(i) / (order + 2 - i) ' + 2 to integrate and compensate for initial index (start from 1 vs 0 stuff) 71 | Next i 72 | ReDim Preserve P(UBound(P)) 73 | P(order + 1) = 0 74 | ' At this point, P contains the integrated polynomial coefficients 75 | 76 | ' Use polynomial function to calculate the numerical integral between low and high (and return) 77 | bjontegaard_polyfit_and_integrate = bjontegaard_polyval(P, highX) - bjontegaard_polyval(P, lowX) 78 | End Function 79 | 80 | ' Calculate a Bjontegaard difference value 81 | Private Function bjontegaard_diff(X1 As Variant, Y1 As Variant, X2 As Variant, Y2 As Variant) 82 | Dim lowX As Double, highX As Double 83 | highX = Application.WorksheetFunction.Min(Application.WorksheetFunction.Max(X1), Application.WorksheetFunction.Max(X2)) 84 | lowX = Application.WorksheetFunction.Max(Application.WorksheetFunction.Min(X1), Application.WorksheetFunction.Min(X2)) 85 | 86 | Dim int1, int2 87 | int1 = bjontegaard_polyfit_and_integrate(X1, Y1, lowX, highX) 88 | int2 = bjontegaard_polyfit_and_integrate(X2, Y2, lowX, highX) 89 | 90 | ' Return the difference value 91 | bjontegaard_diff = (int2 - int1) / (highX - lowX) 92 | End Function 93 | 94 | ' Bjontegaard delta-SNR metric (in dB) 95 | Function BDSNR(BR1 As Range, PSNR1 As Range, BR2 As Range, PSNR2 As Range) 96 | ' Error checking 97 | If BR1.Count <> PSNR1.Count Or BR2.Count <> PSNR2.Count Or BR1.Count < 4 Or BR2.Count < 4 Then 98 | BDSNR = CVErr(xlErrRef) 99 | Return 100 | End If 101 | 102 | ' Get data for two curves 103 | Dim BR1data As Variant, PSNR1data As Variant, BR2data As Variant, PSNR2data As Variant 104 | BR1data = WorksheetFunction.Transpose(BR1) 105 | PSNR1data = WorksheetFunction.Transpose(PSNR1) 106 | BR2data = WorksheetFunction.Transpose(BR2) 107 | PSNR2data = WorksheetFunction.Transpose(PSNR2) 108 | 109 | ' Put rates in logarithmic scale 110 | For i = 1 To BR1.Count 111 | BR1data(i) = Application.WorksheetFunction.Ln(BR1data(i)) 112 | Next i 113 | For i = 1 To BR2.Count 114 | BR2data(i) = Application.WorksheetFunction.Ln(BR2data(i)) 115 | Next i 116 | 117 | ' Calculate the Bjontegaard difference 118 | BDSNR = bjontegaard_diff(BR1data, PSNR1data, BR2data, PSNR2data) 119 | End Function 120 | 121 | ' Bjontegaard delta-BR metric (in %) 122 | Function BDBR(BR1 As Range, PSNR1 As Range, BR2 As Range, PSNR2 As Range) 123 | ' Error checking 124 | If BR1.Count <> PSNR1.Count Or BR2.Count <> PSNR2.Count Or BR1.Count < 4 Or BR2.Count < 4 Then 125 | BDBR = CVErr(xlErrRef) 126 | Return 127 | End If 128 | 129 | ' Get data for two curves 130 | Dim BR1data As Variant, PSNR1data As Variant, BR2data As Variant, PSNR2data As Variant 131 | BR1data = WorksheetFunction.Transpose(BR1) 132 | PSNR1data = WorksheetFunction.Transpose(PSNR1) 133 | BR2data = WorksheetFunction.Transpose(BR2) 134 | PSNR2data = WorksheetFunction.Transpose(PSNR2) 135 | 136 | ' Put rates in logarithmic scale 137 | For i = 1 To BR1.Count 138 | BR1data(i) = Application.WorksheetFunction.Ln(BR1data(i)) 139 | Next i 140 | For i = 1 To BR2.Count 141 | BR2data(i) = Application.WorksheetFunction.Ln(BR2data(i)) 142 | Next i 143 | 144 | ' Calculate the Bjontegaard difference 145 | BDBR = (Exp(bjontegaard_diff(PSNR1data, BR1data, PSNR2data, BR2data)) - 1) * 100 146 | End Function 147 | -------------------------------------------------------------------------------- /bjontegaard_etro.xla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tbr/bjontegaard_etro/02c8aaa06ebd4280f9c5df9f0591ada0931a7886/bjontegaard_etro.xla -------------------------------------------------------------------------------- /bjontegaard_etro_standalone_example.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tbr/bjontegaard_etro/02c8aaa06ebd4280f9c5df9f0591ada0931a7886/bjontegaard_etro_standalone_example.xlsm -------------------------------------------------------------------------------- /reference/VCEG-M33.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tbr/bjontegaard_etro/02c8aaa06ebd4280f9c5df9f0591ada0931a7886/reference/VCEG-M33.doc --------------------------------------------------------------------------------