Coverage for models/rgb/transfer_functions/tests/test_fujifilm_f_log.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\

3 fujifilm_f_log` module.

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import (

10 log_decoding_FLog,

11 log_decoding_FLog2,

12 log_encoding_FLog,

13 log_encoding_FLog2,

14)

15 from colour.utilities import domain_range_scale, ignore_numpy_errors

16

17 __author__ = "Colour Developers"

18 __copyright__ = "Copyright 2013 Colour Developers"

19 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

20 __maintainer__ = "Colour Developers"

21 __email__ = "colour-developers@colour-science.org"

22 __status__ = "Production"

23

24 __all__ = [

25 "TestLogEncoding_FLog",

26 "TestLogDecoding_FLog",

27 "TestLogEncoding_FLog2",

28 "TestLogDecoding_FLog2",

29]

30

31

32 class TestLogEncoding_FLog:

33 """

34 Define :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

35 log_encoding_FLog` definition unit tests methods.

36 """

37

38 def test_log_encoding_FLog(self) -> None:

39 """

40 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

41 log_encoding_FLog` definition.

42 """

43

44 np.testing.assert_allclose(

45 log_encoding_FLog(0.0),

46 0.092864000000000,

47 atol=TOLERANCE_ABSOLUTE_TESTS,

48 )

49

50 np.testing.assert_allclose(

51 log_encoding_FLog(0.18),

52 0.459318458661621,

53 atol=TOLERANCE_ABSOLUTE_TESTS,

54 )

55

56 np.testing.assert_allclose(

57 log_encoding_FLog(0.18, 12),

58 0.459318458661621,

59 atol=TOLERANCE_ABSOLUTE_TESTS,

60 )

61

62 np.testing.assert_allclose(

63 log_encoding_FLog(0.18, 10, False),

64 0.463336510514656,

65 atol=TOLERANCE_ABSOLUTE_TESTS,

66 )

67

68 np.testing.assert_allclose(

69 log_encoding_FLog(0.18, 10, False, False),

70 0.446590337236003,

71 atol=TOLERANCE_ABSOLUTE_TESTS,

72 )

73

74 np.testing.assert_allclose(

75 log_encoding_FLog(1.0),

76 0.704996409216428,

77 atol=TOLERANCE_ABSOLUTE_TESTS,

78 )

79

80 def test_n_dimensional_log_encoding_FLog(self) -> None:

81 """

82 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

83 log_encoding_FLog` definition n-dimensional arrays support.

84 """

85

86 L_in = 0.18

87 V_out = log_encoding_FLog(L_in)

88

89 L_in = np.tile(L_in, 6)

90 V_out = np.tile(V_out, 6)

91 np.testing.assert_allclose(

92 log_encoding_FLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

93 )

94

95 L_in = np.reshape(L_in, (2, 3))

96 V_out = np.reshape(V_out, (2, 3))

97 np.testing.assert_allclose(

98 log_encoding_FLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

99 )

100

101 L_in = np.reshape(L_in, (2, 3, 1))

102 V_out = np.reshape(V_out, (2, 3, 1))

103 np.testing.assert_allclose(

104 log_encoding_FLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

105 )

106

107 def test_domain_range_scale_log_encoding_FLog(self) -> None:

108 """

109 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

110 log_encoding_FLog` definition domain and range scale support.

111 """

112

113 L_in = 0.18

114 V_out = log_encoding_FLog(L_in)

115

116 d_r = (("reference", 1), ("1", 1), ("100", 100))

117 for scale, factor in d_r:

118 with domain_range_scale(scale):

119 np.testing.assert_allclose(

120 log_encoding_FLog(L_in * factor),

121 V_out * factor,

122 atol=TOLERANCE_ABSOLUTE_TESTS,

123 )

124

125 @ignore_numpy_errors

126 def test_nan_log_encoding_FLog(self) -> None:

127 """

128 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

129 log_encoding_FLog` definition nan support.

130 """

131

132 log_encoding_FLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

133

134

135 class TestLogDecoding_FLog:

136 """

137 Define :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

138 log_decoding_FLog` definition unit tests methods.

139 """

140

141 def test_log_decoding_FLog(self) -> None:

142 """

143 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

144 log_decoding_FLog` definition.

145 """

146

147 np.testing.assert_allclose(

148 log_decoding_FLog(0.092864000000000),

149 0.0,

150 atol=TOLERANCE_ABSOLUTE_TESTS,

151 )

152

153 np.testing.assert_allclose(

154 log_decoding_FLog(0.459318458661621),

155 0.18,

156 atol=TOLERANCE_ABSOLUTE_TESTS,

157 )

158

159 np.testing.assert_allclose(

160 log_decoding_FLog(0.459318458661621, 12),

161 0.18,

162 atol=TOLERANCE_ABSOLUTE_TESTS,

163 )

164

165 np.testing.assert_allclose(

166 log_decoding_FLog(0.463336510514656, 10, False),

167 0.18,

168 atol=TOLERANCE_ABSOLUTE_TESTS,

169 )

170

171 np.testing.assert_allclose(

172 log_decoding_FLog(0.446590337236003, 10, False, False),

173 0.18,

174 atol=TOLERANCE_ABSOLUTE_TESTS,

175 )

176

177 np.testing.assert_allclose(

178 log_decoding_FLog(0.704996409216428),

179 1.0,

180 atol=TOLERANCE_ABSOLUTE_TESTS,

181 )

182

183 def test_n_dimensional_log_decoding_FLog(self) -> None:

184 """

185 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

186 log_decoding_FLog` definition n-dimensional arrays support.

187 """

188

189 V_out = 0.459318458661621

190 L_in = log_decoding_FLog(V_out)

191

192 V_out = np.tile(V_out, 6)

193 L_in = np.tile(L_in, 6)

194 np.testing.assert_allclose(

195 log_decoding_FLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

196 )

197

198 V_out = np.reshape(V_out, (2, 3))

199 L_in = np.reshape(L_in, (2, 3))

200 np.testing.assert_allclose(

201 log_decoding_FLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

202 )

203

204 V_out = np.reshape(V_out, (2, 3, 1))

205 L_in = np.reshape(L_in, (2, 3, 1))

206 np.testing.assert_allclose(

207 log_decoding_FLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

208 )

209

210 def test_domain_range_scale_log_decoding_FLog(self) -> None:

211 """

212 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

213 log_decoding_FLog` definition domain and range scale support.

214 """

215

216 V_out = 0.459318458661621

217 L_in = log_decoding_FLog(V_out)

218

219 d_r = (("reference", 1), ("1", 1), ("100", 100))

220 for scale, factor in d_r:

221 with domain_range_scale(scale):

222 np.testing.assert_allclose(

223 log_decoding_FLog(V_out * factor),

224 L_in * factor,

225 atol=TOLERANCE_ABSOLUTE_TESTS,

226 )

227

228 @ignore_numpy_errors

229 def test_nan_log_decoding_FLog(self) -> None:

230 """

231 Test :func:`colour.models.rgb.transfer_functions.fujifilm_f_log.\

232 log_decoding_FLog` definition nan support.

233 """

234

235 log_decoding_FLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

236

237

238 class TestLogEncoding_FLog2:

239 """

240 Define :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

241 log_encoding_FLog2` definition unit tests methods.

242 """

243

244 def test_log_encoding_FLog2(self) -> None:

245 """

246 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

247 log_encoding_FLog2` definition.

248 """

249

250 np.testing.assert_allclose(

251 log_encoding_FLog2(0.0),

252 0.092864000000000,

253 atol=TOLERANCE_ABSOLUTE_TESTS,

254 )

255

256 np.testing.assert_allclose(

257 log_encoding_FLog2(0.18),

258 0.39100724189123,

259 atol=TOLERANCE_ABSOLUTE_TESTS,

260 )

261

262 np.testing.assert_allclose(

263 log_encoding_FLog2(0.18, 12),

264 0.39100724189123,

265 atol=TOLERANCE_ABSOLUTE_TESTS,

266 )

267

268 np.testing.assert_allclose(

269 log_encoding_FLog2(0.18, 10, False),

270 0.383562110108137,

271 atol=TOLERANCE_ABSOLUTE_TESTS,

272 )

273

274 np.testing.assert_allclose(

275 log_encoding_FLog2(0.18, 10, False, False),

276 0.371293971820387,

277 atol=TOLERANCE_ABSOLUTE_TESTS,

278 )

279

280 np.testing.assert_allclose(

281 log_encoding_FLog2(1.0),

282 0.568219370444443,

283 atol=TOLERANCE_ABSOLUTE_TESTS,

284 )

285

286 def test_n_dimensional_log_encoding_FLog2(self) -> None:

287 """

288 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

289 log_encoding_FLog2` definition n-dimensional arrays support.

290 """

291

292 L_in = 0.18

293 V_out = log_encoding_FLog2(L_in)

294

295 L_in = np.tile(L_in, 6)

296 V_out = np.tile(V_out, 6)

297 np.testing.assert_allclose(

298 log_encoding_FLog2(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

299 )

300

301 L_in = np.reshape(L_in, (2, 3))

302 V_out = np.reshape(V_out, (2, 3))

303 np.testing.assert_allclose(

304 log_encoding_FLog2(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

305 )

306

307 L_in = np.reshape(L_in, (2, 3, 1))

308 V_out = np.reshape(V_out, (2, 3, 1))

309 np.testing.assert_allclose(

310 log_encoding_FLog2(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS

311 )

312

313 def test_domain_range_scale_log_encoding_FLog2(self) -> None:

314 """

315 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

316 log_encoding_FLog2` definition domain and range scale support.

317 """

318

319 L_in = 0.18

320 V_out = log_encoding_FLog2(L_in)

321

322 d_r = (("reference", 1), ("1", 1), ("100", 100))

323 for scale, factor in d_r:

324 with domain_range_scale(scale):

325 np.testing.assert_array_equal(

326 log_encoding_FLog2(L_in * factor), V_out * factor

327 )

328

329 @ignore_numpy_errors

330 def test_nan_log_encoding_FLog2(self) -> None:

331 """

332 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

333 log_encoding_FLog2` definition nan support.

334 """

335

336 log_encoding_FLog2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

337

338

339 class TestLogDecoding_FLog2:

340 """

341 Define :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

342 log_decoding_FLog2` definition unit tests methods.

343 """

344

345 def test_log_decoding_FLog2(self) -> None:

346 """

347 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

348 log_decoding_FLog2` definition.

349 """

350

351 np.testing.assert_allclose(

352 log_decoding_FLog2(0.092864000000000),

353 0.0,

354 atol=TOLERANCE_ABSOLUTE_TESTS,

355 )

356

357 np.testing.assert_allclose(

358 log_decoding_FLog2(0.391007241891230),

359 0.18,

360 atol=TOLERANCE_ABSOLUTE_TESTS,

361 )

362

363 np.testing.assert_allclose(

364 log_decoding_FLog2(0.391007241891230, 12),

365 0.18,

366 atol=TOLERANCE_ABSOLUTE_TESTS,

367 )

368

369 np.testing.assert_allclose(

370 log_decoding_FLog2(0.383562110108137, 10, False),

371 0.18,

372 atol=TOLERANCE_ABSOLUTE_TESTS,

373 )

374

375 np.testing.assert_allclose(

376 log_decoding_FLog2(0.371293971820387, 10, False, False),

377 0.18,

378 atol=TOLERANCE_ABSOLUTE_TESTS,

379 )

380

381 np.testing.assert_allclose(

382 log_decoding_FLog2(0.568219370444443),

383 1.0,

384 atol=TOLERANCE_ABSOLUTE_TESTS,

385 )

386

387 def test_n_dimensional_log_decoding_FLog2(self) -> None:

388 """

389 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

390 log_decoding_FLog2` definition n-dimensional arrays support.

391 """

392

393 V_out = 0.39100724189123

394 L_in = log_decoding_FLog2(V_out)

395

396 V_out = np.tile(V_out, 6)

397 L_in = np.tile(L_in, 6)

398 np.testing.assert_allclose(

399 log_decoding_FLog2(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

400 )

401

402 V_out = np.reshape(V_out, (2, 3))

403 L_in = np.reshape(L_in, (2, 3))

404 np.testing.assert_allclose(

405 log_decoding_FLog2(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

406 )

407

408 V_out = np.reshape(V_out, (2, 3, 1))

409 L_in = np.reshape(L_in, (2, 3, 1))

410 np.testing.assert_allclose(

411 log_decoding_FLog2(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS

412 )

413

414 def test_domain_range_scale_log_decoding_FLog2(self) -> None:

415 """

416 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

417 log_decoding_FLog2` definition domain and range scale support.

418 """

419

420 V_out = 0.39100724189123

421 L_in = log_decoding_FLog2(V_out)

422

423 d_r = (("reference", 1), ("1", 1), ("100", 100))

424 for scale, factor in d_r:

425 with domain_range_scale(scale):

426 np.testing.assert_array_equal(

427 log_decoding_FLog2(V_out * factor),

428 L_in * factor,

429 )

430

431 @ignore_numpy_errors

432 def test_nan_log_decoding_FLog2(self) -> None:

433 """

434 Test :func:`colour.models.rgb.transfer_functions.fujifilm_flog.\

435 log_decoding_FLog2` definition nan support.

436 """

437

438 log_decoding_FLog2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))