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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.sony` 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_SLog,

11 log_decoding_SLog2,

12 log_decoding_SLog3,

13 log_encoding_SLog,

14 log_encoding_SLog2,

15 log_encoding_SLog3,

16)

17 from colour.utilities import domain_range_scale, ignore_numpy_errors

18

19 __author__ = "Colour Developers"

20 __copyright__ = "Copyright 2013 Colour Developers"

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

22 __maintainer__ = "Colour Developers"

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

24 __status__ = "Production"

25

26 __all__ = [

27 "TestLogEncoding_SLog",

28 "TestLogDecoding_SLog",

29 "TestLogEncoding_SLog2",

30 "TestLogDecoding_SLog2",

31 "TestLogEncoding_SLog3",

32 "TestLogDecoding_SLog3",

33]

34

35

36 class TestLogEncoding_SLog:

37 """

38 Define :func:`colour.models.rgb.transfer_functions.sony.\

39 log_encoding_SLog` definition unit tests methods.

40 """

41

42 def test_log_encoding_SLog(self) -> None:

43 """

44 Test :func:`colour.models.rgb.transfer_functions.sony.\

45 log_encoding_SLog` definition.

46 """

47

48 np.testing.assert_allclose(

49 log_encoding_SLog(0.0),

50 0.088251291513446,

51 atol=TOLERANCE_ABSOLUTE_TESTS,

52 )

53

54 np.testing.assert_allclose(

55 log_encoding_SLog(0.18),

56 0.384970815928670,

57 atol=TOLERANCE_ABSOLUTE_TESTS,

58 )

59

60 np.testing.assert_allclose(

61 log_encoding_SLog(0.18, 12),

62 0.384688786026891,

63 atol=TOLERANCE_ABSOLUTE_TESTS,

64 )

65

66 np.testing.assert_allclose(

67 log_encoding_SLog(0.18, 10, False),

68 0.376512722254600,

69 atol=TOLERANCE_ABSOLUTE_TESTS,

70 )

71

72 np.testing.assert_allclose(

73 log_encoding_SLog(0.18, 10, False, False),

74 0.359987846422154,

75 atol=TOLERANCE_ABSOLUTE_TESTS,

76 )

77

78 np.testing.assert_allclose(

79 log_encoding_SLog(1.0),

80 0.638551684622532,

81 atol=TOLERANCE_ABSOLUTE_TESTS,

82 )

83

84 def test_n_dimensional_log_encoding_SLog(self) -> None:

85 """

86 Test :func:`colour.models.rgb.transfer_functions.sony.\

87 log_encoding_SLog` definition n-dimensional arrays support.

88 """

89

90 x = 0.18

91 y = log_encoding_SLog(x)

92

93 x = np.tile(x, 6)

94 y = np.tile(y, 6)

95 np.testing.assert_allclose(

96 log_encoding_SLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

97 )

98

99 x = np.reshape(x, (2, 3))

100 y = np.reshape(y, (2, 3))

101 np.testing.assert_allclose(

102 log_encoding_SLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

103 )

104

105 x = np.reshape(x, (2, 3, 1))

106 y = np.reshape(y, (2, 3, 1))

107 np.testing.assert_allclose(

108 log_encoding_SLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

109 )

110

111 def test_domain_range_scale_log_encoding_SLog(self) -> None:

112 """

113 Test :func:`colour.models.rgb.transfer_functions.sony.\

114 log_encoding_SLog` definition domain and range scale support.

115 """

116

117 x = 0.18

118 y = log_encoding_SLog(x)

119

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

121 for scale, factor in d_r:

122 with domain_range_scale(scale):

123 np.testing.assert_allclose(

124 log_encoding_SLog(x * factor),

125 y * factor,

126 atol=TOLERANCE_ABSOLUTE_TESTS,

127 )

128

129 @ignore_numpy_errors

130 def test_nan_log_encoding_SLog(self) -> None:

131 """

132 Test :func:`colour.models.rgb.transfer_functions.sony.\

133 log_encoding_SLog` definition nan support.

134 """

135

136 log_encoding_SLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

137

138

139 class TestLogDecoding_SLog:

140 """

141 Define :func:`colour.models.rgb.transfer_functions.sony.\

142 log_decoding_SLog` definition unit tests methods.

143 """

144

145 def test_log_decoding_SLog(self) -> None:

146 """

147 Test :func:`colour.models.rgb.transfer_functions.sony.\

148 log_decoding_SLog` definition.

149 """

150

151 np.testing.assert_allclose(

152 log_decoding_SLog(0.088251291513446),

153 0.0,

154 atol=TOLERANCE_ABSOLUTE_TESTS,

155 )

156

157 np.testing.assert_allclose(

158 log_decoding_SLog(0.384970815928670),

159 0.18,

160 atol=TOLERANCE_ABSOLUTE_TESTS,

161 )

162

163 np.testing.assert_allclose(

164 log_decoding_SLog(0.384688786026891, 12),

165 0.18,

166 atol=TOLERANCE_ABSOLUTE_TESTS,

167 )

168

169 np.testing.assert_allclose(

170 log_decoding_SLog(0.376512722254600, 10, False),

171 0.18,

172 atol=TOLERANCE_ABSOLUTE_TESTS,

173 )

174

175 np.testing.assert_allclose(

176 log_decoding_SLog(0.359987846422154, 10, False, False),

177 0.18,

178 atol=TOLERANCE_ABSOLUTE_TESTS,

179 )

180

181 np.testing.assert_allclose(

182 log_decoding_SLog(0.638551684622532),

183 1.0,

184 atol=TOLERANCE_ABSOLUTE_TESTS,

185 )

186

187 def test_n_dimensional_log_decoding_SLog(self) -> None:

188 """

189 Test :func:`colour.models.rgb.transfer_functions.sony.\

190 log_decoding_SLog` definition n-dimensional arrays support.

191 """

192

193 y = 0.384970815928670

194 x = log_decoding_SLog(y)

195

196 y = np.tile(y, 6)

197 x = np.tile(x, 6)

198 np.testing.assert_allclose(

199 log_decoding_SLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

200 )

201

202 y = np.reshape(y, (2, 3))

203 x = np.reshape(x, (2, 3))

204 np.testing.assert_allclose(

205 log_decoding_SLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

206 )

207

208 y = np.reshape(y, (2, 3, 1))

209 x = np.reshape(x, (2, 3, 1))

210 np.testing.assert_allclose(

211 log_decoding_SLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

212 )

213

214 def test_domain_range_scale_log_decoding_SLog(self) -> None:

215 """

216 Test :func:`colour.models.rgb.transfer_functions.sony.\

217 log_decoding_SLog` definition domain and range scale support.

218 """

219

220 y = 0.384970815928670

221 x = log_decoding_SLog(y)

222

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

224 for scale, factor in d_r:

225 with domain_range_scale(scale):

226 np.testing.assert_allclose(

227 log_decoding_SLog(y * factor),

228 x * factor,

229 atol=TOLERANCE_ABSOLUTE_TESTS,

230 )

231

232 @ignore_numpy_errors

233 def test_nan_log_decoding_SLog(self) -> None:

234 """

235 Test :func:`colour.models.rgb.transfer_functions.sony.\

236 log_decoding_SLog` definition nan support.

237 """

238

239 log_decoding_SLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

240

241

242 class TestLogEncoding_SLog2:

243 """

244 Define :func:`colour.models.rgb.transfer_functions.sony.\

245 log_encoding_SLog2` definition unit tests methods.

246 """

247

248 def test_log_encoding_SLog2(self) -> None:

249 """

250 Test :func:`colour.models.rgb.transfer_functions.sony.\

251 log_encoding_SLog2` definition.

252 """

253

254 np.testing.assert_allclose(

255 log_encoding_SLog2(0.0),

256 0.088251291513446,

257 atol=TOLERANCE_ABSOLUTE_TESTS,

258 )

259

260 np.testing.assert_allclose(

261 log_encoding_SLog2(0.18),

262 0.339532524633774,

263 atol=TOLERANCE_ABSOLUTE_TESTS,

264 )

265

266 np.testing.assert_allclose(

267 log_encoding_SLog2(0.18, 12),

268 0.339283782857486,

269 atol=TOLERANCE_ABSOLUTE_TESTS,

270 )

271

272 np.testing.assert_allclose(

273 log_encoding_SLog2(0.18, 10, False),

274 0.323449512215013,

275 atol=TOLERANCE_ABSOLUTE_TESTS,

276 )

277

278 np.testing.assert_allclose(

279 log_encoding_SLog2(0.18, 10, False, False),

280 0.307980741258647,

281 atol=TOLERANCE_ABSOLUTE_TESTS,

282 )

283

284 np.testing.assert_allclose(

285 log_encoding_SLog2(1.0),

286 0.585091059564112,

287 atol=TOLERANCE_ABSOLUTE_TESTS,

288 )

289

290 def test_n_dimensional_log_encoding_SLog2(self) -> None:

291 """

292 Test :func:`colour.models.rgb.transfer_functions.sony.\

293 log_encoding_SLog2` definition n-dimensional arrays support.

294 """

295

296 x = 0.18

297 y = log_encoding_SLog2(x)

298

299 x = np.tile(x, 6)

300 y = np.tile(y, 6)

301 np.testing.assert_allclose(

302 log_encoding_SLog2(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

303 )

304

305 x = np.reshape(x, (2, 3))

306 y = np.reshape(y, (2, 3))

307 np.testing.assert_allclose(

308 log_encoding_SLog2(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

309 )

310

311 x = np.reshape(x, (2, 3, 1))

312 y = np.reshape(y, (2, 3, 1))

313 np.testing.assert_allclose(

314 log_encoding_SLog2(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

315 )

316

317 def test_domain_range_scale_log_encoding_SLog2(self) -> None:

318 """

319 Test :func:`colour.models.rgb.transfer_functions.sony.\

320 log_encoding_SLog2` definition domain and range scale support.

321 """

322

323 x = 0.18

324 y = log_encoding_SLog2(x)

325

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

327 for scale, factor in d_r:

328 with domain_range_scale(scale):

329 np.testing.assert_allclose(

330 log_encoding_SLog2(x * factor),

331 y * factor,

332 atol=TOLERANCE_ABSOLUTE_TESTS,

333 )

334

335 @ignore_numpy_errors

336 def test_nan_log_encoding_SLog2(self) -> None:

337 """

338 Test :func:`colour.models.rgb.transfer_functions.sony.\

339 log_encoding_SLog2` definition nan support.

340 """

341

342 log_encoding_SLog2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

343

344

345 class TestLogDecoding_SLog2:

346 """

347 Define :func:`colour.models.rgb.transfer_functions.sony.\

348 log_decoding_SLog2` definition unit tests methods.

349 """

350

351 def test_log_decoding_SLog2(self) -> None:

352 """

353 Test :func:`colour.models.rgb.transfer_functions.sony.\

354 log_decoding_SLog2` definition.

355 """

356

357 np.testing.assert_allclose(

358 log_decoding_SLog2(0.088251291513446),

359 0.0,

360 atol=TOLERANCE_ABSOLUTE_TESTS,

361 )

362

363 np.testing.assert_allclose(

364 log_decoding_SLog2(0.339532524633774),

365 0.18,

366 atol=TOLERANCE_ABSOLUTE_TESTS,

367 )

368

369 np.testing.assert_allclose(

370 log_decoding_SLog2(0.339283782857486, 12),

371 0.18,

372 atol=TOLERANCE_ABSOLUTE_TESTS,

373 )

374

375 np.testing.assert_allclose(

376 log_decoding_SLog2(0.323449512215013, 10, False),

377 0.18,

378 atol=TOLERANCE_ABSOLUTE_TESTS,

379 )

380

381 np.testing.assert_allclose(

382 log_decoding_SLog2(0.307980741258647, 10, False, False),

383 0.18,

384 atol=TOLERANCE_ABSOLUTE_TESTS,

385 )

386

387 np.testing.assert_allclose(

388 log_decoding_SLog2(0.585091059564112),

389 1.0,

390 atol=TOLERANCE_ABSOLUTE_TESTS,

391 )

392

393 def test_n_dimensional_log_decoding_SLog2(self) -> None:

394 """

395 Test :func:`colour.models.rgb.transfer_functions.sony.\

396 log_decoding_SLog2` definition n-dimensional arrays support.

397 """

398

399 y = 0.339532524633774

400 x = log_decoding_SLog2(y)

401

402 y = np.tile(y, 6)

403 x = np.tile(x, 6)

404 np.testing.assert_allclose(

405 log_decoding_SLog2(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

406 )

407

408 y = np.reshape(y, (2, 3))

409 x = np.reshape(x, (2, 3))

410 np.testing.assert_allclose(

411 log_decoding_SLog2(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

412 )

413

414 y = np.reshape(y, (2, 3, 1))

415 x = np.reshape(x, (2, 3, 1))

416 np.testing.assert_allclose(

417 log_decoding_SLog2(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

418 )

419

420 def test_domain_range_scale_log_decoding_SLog2(self) -> None:

421 """

422 Test :func:`colour.models.rgb.transfer_functions.sony.\

423 log_decoding_SLog2` definition domain and range scale support.

424 """

425

426 y = 0.339532524633774

427 x = log_decoding_SLog2(y)

428

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

430 for scale, factor in d_r:

431 with domain_range_scale(scale):

432 np.testing.assert_allclose(

433 log_decoding_SLog2(y * factor),

434 x * factor,

435 atol=TOLERANCE_ABSOLUTE_TESTS,

436 )

437

438 @ignore_numpy_errors

439 def test_nan_log_decoding_SLog2(self) -> None:

440 """

441 Test :func:`colour.models.rgb.transfer_functions.sony.\

442 log_decoding_SLog2` definition nan support.

443 """

444

445 log_decoding_SLog2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

446

447

448 class TestLogEncoding_SLog3:

449 """

450 Define :func:`colour.models.rgb.transfer_functions.sony.\

451 log_encoding_SLog3` definition unit tests methods.

452 """

453

454 def test_log_encoding_SLog3(self) -> None:

455 """

456 Test :func:`colour.models.rgb.transfer_functions.sony.\

457 log_encoding_SLog3` definition.

458 """

459

460 np.testing.assert_allclose(

461 log_encoding_SLog3(0.0),

462 0.092864125122190,

463 atol=TOLERANCE_ABSOLUTE_TESTS,

464 )

465

466 np.testing.assert_allclose(

467 log_encoding_SLog3(0.18),

468 0.41055718475073,

469 atol=TOLERANCE_ABSOLUTE_TESTS,

470 )

471

472 np.testing.assert_allclose(

473 log_encoding_SLog3(0.18, 12),

474 0.410557184750733,

475 atol=TOLERANCE_ABSOLUTE_TESTS,

476 )

477

478 np.testing.assert_allclose(

479 log_encoding_SLog3(0.18, 10, False),

480 0.406392694063927,

481 atol=TOLERANCE_ABSOLUTE_TESTS,

482 )

483

484 np.testing.assert_allclose(

485 log_encoding_SLog3(0.18, 10, False, False),

486 0.393489294768447,

487 atol=TOLERANCE_ABSOLUTE_TESTS,

488 )

489

490 np.testing.assert_allclose(

491 log_encoding_SLog3(1.0),

492 0.596027343690123,

493 atol=TOLERANCE_ABSOLUTE_TESTS,

494 )

495

496 def test_n_dimensional_log_encoding_SLog3(self) -> None:

497 """

498 Test :func:`colour.models.rgb.transfer_functions.sony.\

499 log_encoding_SLog3` definition n-dimensional arrays support.

500 """

501

502 x = 0.18

503 y = log_encoding_SLog3(x)

504

505 x = np.tile(x, 6)

506 y = np.tile(y, 6)

507 np.testing.assert_allclose(

508 log_encoding_SLog3(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

509 )

510

511 x = np.reshape(x, (2, 3))

512 y = np.reshape(y, (2, 3))

513 np.testing.assert_allclose(

514 log_encoding_SLog3(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

515 )

516

517 x = np.reshape(x, (2, 3, 1))

518 y = np.reshape(y, (2, 3, 1))

519 np.testing.assert_allclose(

520 log_encoding_SLog3(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

521 )

522

523 def test_domain_range_scale_log_encoding_SLog3(self) -> None:

524 """

525 Test :func:`colour.models.rgb.transfer_functions.sony.\

526 log_encoding_SLog3` definition domain and range scale support.

527 """

528

529 x = 0.18

530 y = log_encoding_SLog3(x)

531

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

533 for scale, factor in d_r:

534 with domain_range_scale(scale):

535 np.testing.assert_allclose(

536 log_encoding_SLog3(x * factor),

537 y * factor,

538 atol=TOLERANCE_ABSOLUTE_TESTS,

539 )

540

541 @ignore_numpy_errors

542 def test_nan_log_encoding_SLog3(self) -> None:

543 """

544 Test :func:`colour.models.rgb.transfer_functions.sony.\

545 log_encoding_SLog3` definition nan support.

546 """

547

548 log_encoding_SLog3(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

549

550

551 class TestLogDecoding_SLog3:

552 """

553 Define :func:`colour.models.rgb.transfer_functions.sony.\

554 log_decoding_SLog3` definition unit tests methods.

555 """

556

557 def test_log_decoding_SLog3(self) -> None:

558 """

559 Test :func:`colour.models.rgb.transfer_functions.sony.\

560 log_decoding_SLog3` definition.

561 """

562

563 np.testing.assert_allclose(

564 log_decoding_SLog3(0.092864125122190),

565 0.0,

566 atol=TOLERANCE_ABSOLUTE_TESTS,

567 )

568

569 np.testing.assert_allclose(

570 log_decoding_SLog3(0.41055718475073),

571 0.18,

572 atol=TOLERANCE_ABSOLUTE_TESTS,

573 )

574

575 np.testing.assert_allclose(

576 log_decoding_SLog3(0.410557184750733, 12),

577 0.18,

578 atol=TOLERANCE_ABSOLUTE_TESTS,

579 )

580

581 np.testing.assert_allclose(

582 log_decoding_SLog3(0.406392694063927, 10, False),

583 0.18,

584 atol=TOLERANCE_ABSOLUTE_TESTS,

585 )

586

587 np.testing.assert_allclose(

588 log_decoding_SLog3(0.393489294768447, 10, False, False),

589 0.18,

590 atol=TOLERANCE_ABSOLUTE_TESTS,

591 )

592

593 np.testing.assert_allclose(

594 log_decoding_SLog3(0.596027343690123),

595 1.0,

596 atol=TOLERANCE_ABSOLUTE_TESTS,

597 )

598

599 def test_n_dimensional_log_decoding_SLog3(self) -> None:

600 """

601 Test :func:`colour.models.rgb.transfer_functions.sony.\

602 log_decoding_SLog3` definition n-dimensional arrays support.

603 """

604

605 y = 0.41055718475073

606 x = log_decoding_SLog3(y)

607

608 y = np.tile(y, 6)

609 x = np.tile(x, 6)

610 np.testing.assert_allclose(

611 log_decoding_SLog3(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

612 )

613

614 y = np.reshape(y, (2, 3))

615 x = np.reshape(x, (2, 3))

616 np.testing.assert_allclose(

617 log_decoding_SLog3(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

618 )

619

620 y = np.reshape(y, (2, 3, 1))

621 x = np.reshape(x, (2, 3, 1))

622 np.testing.assert_allclose(

623 log_decoding_SLog3(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

624 )

625

626 def test_domain_range_scale_log_decoding_SLog3(self) -> None:

627 """

628 Test :func:`colour.models.rgb.transfer_functions.sony.\

629 log_decoding_SLog3` definition domain and range scale support.

630 """

631

632 y = 0.41055718475073

633 x = log_decoding_SLog3(y)

634

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

636 for scale, factor in d_r:

637 with domain_range_scale(scale):

638 np.testing.assert_allclose(

639 log_decoding_SLog3(y * factor),

640 x * factor,

641 atol=TOLERANCE_ABSOLUTE_TESTS,

642 )

643

644 @ignore_numpy_errors

645 def test_nan_log_decoding_SLog3(self) -> None:

646 """

647 Test :func:`colour.models.rgb.transfer_functions.sony.\

648 log_decoding_SLog3` definition nan support.

649 """

650

651 log_decoding_SLog3(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))