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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
|
""" Test npz plugin functionality.
"""
from __future__ import division
import numpy as np
import json
import pytest
import imageio.v2 as iio
from imageio.core import Request
from conftest import deprecated_test
# Set file names for test images in imageio-binaries repo
LFR_FILENAME = "Ankylosaurus_&_Stegosaurus.LFR"
THUMB_FILENAME = "Ankylosaurus_&_Stegosaurus_Thumbnail.jpg"
RAW_ILLUM_FILENAME = "lenslet_whiteimage.RAW"
RAW_ILLUM_META_FILENAME = "lenslet_whiteimage.TXT"
LFP_FILENAME = "Guitar.lfp"
RAW_F0_FILENAME = "IMG_0001__frame.raw"
RAW_F0_META_FILENAME = "IMG_0001__frame.json"
PNG_FILENAME = "chelsea.png"
@deprecated_test
def test_lytro_lfr_format(test_images):
"""
Test basic read/write properties of LytroLfrFormat
"""
# Get test images
lfr_file = test_images / LFR_FILENAME
raw_illum_file = test_images / RAW_ILLUM_FILENAME
lfp_file = test_images / LFP_FILENAME
raw_f01_file = test_images / RAW_F0_FILENAME
png_file = test_images / PNG_FILENAME
# Test lytro lfr format
format = iio.formats["lytro-lfr"]
assert format.name == "LYTRO-LFR"
assert format.__module__.endswith("lytro")
# Test can read
assert format.can_read(Request(lfr_file, "ri"))
# Test cannot read, cannot write
assert not format.can_write(Request(lfr_file, "wi"))
assert not format.can_write(Request(lfp_file, "wi"))
assert not format.can_write(Request(raw_f01_file, "wi"))
assert not format.can_write(Request(raw_illum_file, "wi"))
assert not format.can_write(Request(png_file, "wi"))
@deprecated_test
def test_lytro_illum_raw_format(test_images):
"""
Test basic read/write properties of LytroRawFormat
"""
# Get test images
lfr_file = test_images / LFR_FILENAME
raw_illum_file = test_images / RAW_ILLUM_FILENAME
lfp_file = test_images / LFP_FILENAME
raw_f01_file = test_images / RAW_F0_FILENAME
png_file = test_images / PNG_FILENAME
# Test lytro raw format
format = iio.formats["lytro-illum-raw"]
assert format.name == "LYTRO-ILLUM-RAW"
assert format.__module__.endswith("lytro")
# Test can read, cannot write
assert format.can_read(Request(raw_illum_file, "ri"))
# Test cannot read, cannot write
assert not format.can_write(Request(raw_illum_file, "wi"))
assert not format.can_write(Request(lfr_file, "wi"))
assert not format.can_write(Request(lfp_file, "wi"))
assert not format.can_write(Request(raw_f01_file, "wi"))
assert not format.can_write(Request(png_file, "wi"))
@deprecated_test
def test_lytro_f01_raw_format(test_images):
"""
Test basic read/write properties of LytroRawFormat
"""
# Get test images
lfr_file = test_images / LFR_FILENAME
raw_illum_file = test_images / RAW_ILLUM_FILENAME
lfp_file = test_images / LFP_FILENAME
raw_f01_file = test_images / RAW_F0_FILENAME
png_file = test_images / PNG_FILENAME
# Test lytro raw format
format = iio.formats["lytro-illum-raw"]
assert format.name == "LYTRO-ILLUM-RAW"
assert format.__module__.endswith("lytro")
# Test can read, cannot write
assert format.can_read(Request(raw_f01_file, "ri"))
# Test cannot read, cannot write
assert not format.can_write(Request(raw_f01_file, "wi"))
assert not format.can_write(Request(lfr_file, "wi"))
assert not format.can_write(Request(lfp_file, "wi"))
assert not format.can_write(Request(raw_illum_file, "wi"))
assert not format.can_write(Request(png_file, "wi"))
@deprecated_test
def test_lytro_lfp_format(test_images):
"""
Test basic read/write properties of LytroRawFormat
"""
# Get test images
lfr_file = test_images / LFR_FILENAME
raw_illum_file = test_images / RAW_ILLUM_FILENAME
lfp_file = test_images / LFP_FILENAME
raw_f01_file = test_images / RAW_F0_FILENAME
png_file = test_images / PNG_FILENAME
# Test lytro raw format
format = iio.formats["lytro-lfp"]
assert format.name == "LYTRO-LFP"
assert format.__module__.endswith("lytro")
# Test can read, cannot write
assert format.can_read(Request(lfp_file, "ri"))
# Test cannot read, cannot write
assert not format.can_write(Request(lfp_file, "wi"))
assert not format.can_write(Request(lfr_file, "wi"))
assert not format.can_write(Request(raw_f01_file, "wi"))
assert not format.can_write(Request(raw_illum_file, "wi"))
assert not format.can_write(Request(png_file, "wi"))
def test_lytro_lfr_reading(test_images):
"""Test reading of lytro .lfr file"""
# Get test images
lfr_file = test_images / LFR_FILENAME
thumb_file = test_images / THUMB_FILENAME
# Read image and thumbnail
img = iio.imread(lfr_file, format="lytro-lfr")
thumb_gt = iio.imread(thumb_file)
# Test image shape and some pixel values
# Pixel values are extracted from the Matlab reference implementation
assert img.shape == (5368, 7728)
assert round(img[14, 32], 15) == 0.100684261974585
assert round(img[1531, 95], 15) == 0.250244379276637
assert round(img[1619, 94], 15) == 0.286412512218964
assert round(img[1619, 3354], 15) == 0.345063538611926
assert round(img[1747, 3660], 15) == 0.222873900293255
assert round(img[1813, 5789], 15) == 0.079178885630499
assert round(img[4578, 7352], 15) == 0.256109481915934
assert round(img[5086, 7568], 15) == 0.106549364613881
assert round(img[4951, 2025], 15) == 0.348973607038123
# Test extracted thumbnail against downloaded one
assert np.array_equal(img._meta["thumbnail"]["image"], thumb_gt)
# Test metadata and privateMetadata against ground truth data
metadata_gt = {
"image": {
"width": 7728,
"orientation": 1,
"modulationExposureBias": 0.2689966559410095,
"pixelPacking": {"bitsPerPixel": 10, "endianness": "little"},
"limitExposureBias": 0.0,
"height": 5368,
"pixelFormat": {
"white": {"gr": 1023, "r": 1023, "b": 1023, "gb": 1023},
"black": {"gr": 64, "r": 64, "b": 64, "gb": 64},
"rightShift": 0,
},
"iso": 80,
"originOnSensor": {"x": 0, "y": 0},
"mosaic": {"tile": "r,gr:gb,b", "upperLeftPixel": "gr"},
"color": {
"whiteBalanceGain": {
"gr": 1.0,
"r": 1.378859281539917,
"b": 1.1484659910202026,
"gb": 1.0,
},
"ccm": [
2.2271547317504883,
-1.055293321609497,
-0.1718614399433136,
-0.4269128441810608,
1.7458617687225342,
-0.3189488351345062,
-0.20497213304042816,
-0.7469924688339233,
1.9519646167755127,
],
},
},
"generator": "lightning",
"schema": "http://schema.lytro.com/lfp/lytro_illum_public/"
+ "1.3.5/lytro_illum_public_schema.json",
"camera": {
"make": "Lytro, Inc.",
"model": "ILLUM",
"firmware": "1.1.1 (23)",
},
"devices": {
"clock": {
"zuluTime": "2015-05-17T13:31:37.412Z",
"isTimeValid": True,
},
"sensor": {
"pixelPitch": 1.4e-06,
"normalizedResponses": [
{
"b": 0.7344976663589478,
"gb": 1.0,
"cct": 5100,
"gr": 1.0,
"r": 0.7761663198471069,
}
],
"perCcm": [
{
"ccm": [
2.006272077560425,
-0.5362802147865295,
-0.46999192237854004,
-0.6019303798675537,
1.836044430732727,
-0.23411400616168976,
-0.8173090815544128,
-1.6435128450393677,
3.4608218669891357,
],
"cct": 2850.0,
},
{
"ccm": [
2.4793264865875244,
-1.2747985124588013,
-0.20452789962291718,
-0.5189455151557922,
1.6118407249450684,
-0.09289517253637314,
-0.3602483570575714,
-1.0115599632263184,
2.3718082904815674,
],
"cct": 4150.0,
},
{
"ccm": [
2.1902196407318115,
-1.0231428146362305,
-0.16707684099674225,
-0.4134329855442047,
1.7654914855957031,
-0.3520585000514984,
-0.18222910165786743,
-0.7082417607307434,
1.8904708623886108,
],
"cct": 6500.0,
},
],
"pixelWidth": 7728,
"bitsPerPixel": 10,
"mosaic": {"tile": "r,gr:gb,b", "upperLeftPixel": "gr"},
"pixelHeight": 5368,
"baseIso": 80,
"analogGain": {"gr": 1.0, "r": 1.0, "b": 1.0, "gb": 1.0},
},
"shutter": {
"mechanism": "focalPlaneCurtain",
"frameExposureDuration": 0.000784054514952004,
"pixelExposureDuration": 0.000784054514952004,
"maxSyncSpeed": 0.004,
},
"mla": {
"config": "com.lytro.mla.3",
"rotation": -0.0005426123971119523,
"tiling": "hexUniformRowMajor",
"scaleFactor": {"x": 1.0, "y": 1.0003429651260376},
"lensPitch": 2e-05,
"sensorOffset": {
"x": 8.421777725219726e-06,
"y": -9.545820355415345e-07,
"z": 3.7e-05,
},
},
"lens": {
"fNumber": 2.199776378914589,
"exitPupilOffset": {"z": 0.09728562164306641},
"zoomStep": -297,
"focusStep": 309,
"opticalCenterOffset": {
"x": 1.48461913340725e-05,
"y": 3.083264164160937e-05,
},
"focalLength": 0.024199465511189833,
"infinityLambda": 33.89023289728373,
},
"battery": {
"make": "Lytro",
"chargeLevel": 8,
"model": "B01-3760",
"cycleCount": 5,
},
"accelerometer": {
"samples": [
{
"x": -0.3689117431640625,
"y": 9.022918701171875,
"time": 0.0,
"z": -1.339324951171875,
}
]
},
},
"settings": {
"exposure": {
"bracketCount": 3,
"compensation": 0.30000001192092896,
"mode": "program",
"meter": {
"mode": "evaluative",
"roiMode": "af",
"roi": [{"top": 0.0, "left": 0.0, "bottom": 1.0, "right": 1.0}],
},
"bracketEnable": False,
"bracketStep": 1.0,
"bracketOffset": 0.0,
"aeLock": False,
},
"whiteBalance": {"tint": -76.0, "mode": "auto", "cct": 6199},
"shutter": {
"selfTimerEnable": False,
"selfTimerDuration": 2.0,
"driveMode": "single",
},
"focus": {
"afActuationMode": "single",
"mode": "auto",
"ringLock": False,
"bracketCount": 3,
"bracketEnable": False,
"afDriveMode": "single",
"bracketStep": 3.0,
"bracketOffset": 0.0,
"roi": [{"top": 0.0, "left": 0.0, "bottom": 1.0, "right": 1.0}],
"captureLambda": -4.0,
},
"zoom": {"ringLock": False},
"flash": {
"mode": "unknown",
"exposureCompensation": 0.0,
"zoomMode": "auto",
"curtainTriggerSync": "front",
"afAssistMode": "auto",
},
"depth": {"assist": "on", "histogram": "on", "overlay": "on"},
},
"algorithms": {
"awb": {
"roi": "fullFrame",
"computed": {
"cct": 6199,
"gain": {
"gr": 1.0,
"r": 1.378859281539917,
"b": 1.1484659910202026,
"gb": 1.0,
},
},
},
"ae": {"computed": {"ev": 1.0}, "roi": "followAf", "mode": "live"},
"af": {"computed": {"focusStep": 309}, "roi": "focusRoi"},
},
"picture": {
"totalFrames": 1,
"frameIndex": 0,
"dcfDirectory": "100PHOTO",
"dcfFile": "IMG_0813",
},
}
private_metadata_gt = {
"generator": "lightning",
"schema": "http://schema.lytro.com/lfp/lytro_illum_private/"
+ "1.1.1/lytro_illum_private_schema.json",
"devices": {"sensor": {"serialNumber": "0C220593"}},
"camera": {"serialNumber": "B5143909630"},
}
assert img._meta["metadata"] == metadata_gt
assert img._meta["privateMetadata"] == private_metadata_gt
# Read metadata only (with thumbnail)
img = iio.imread(lfr_file, format="lytro-lfr", meta_only=True)
assert np.array_equal(img, [])
assert img._meta["metadata"] == metadata_gt
assert img._meta["privateMetadata"] == private_metadata_gt
assert np.array_equal(img._meta["thumbnail"]["image"], thumb_gt)
# Read metadata only (without thumbnail)
img = iio.imread(
lfr_file, format="lytro-lfr", meta_only=True, include_thumbnail=False
)
assert np.array_equal(img, [])
assert img._meta["metadata"] == metadata_gt
assert img._meta["privateMetadata"] == private_metadata_gt
assert "thumbnail" not in img._meta.keys()
# Test fail
test_reader = iio.read(lfr_file, "lytro-lfr")
with pytest.raises(IndexError):
test_reader.get_data(-1)
with pytest.raises(IndexError):
test_reader.get_data(3)
def test_lytro_lfp_reading(test_images):
"""Test reading of lytro .lfr file"""
# Get test images
lfp_file = test_images / LFP_FILENAME
# Read image and thumbnail
img = iio.imread(lfp_file, format="lytro-lfp")
# Test image shape and some pixel values
# Pixel values are extracted from the Matlab reference implementation
assert img.shape == (3280, 3280)
assert round(img[171, 94], 15) == 0.284249084249084
assert round(img[701, 292], 15) == 0.289865689865690
assert round(img[1280, 94], 15) == 0.065201465201465
assert round(img[2364, 2640], 15) == 0.056166056166056
assert round(img[2733, 1549], 15) == 0.100366300366300
assert round(img[2739, 2585], 15) == 0.078388278388278
assert round(img[1032, 2230], 15) == 0.354578754578755
assert round(img[1480, 1758], 15) == 0.098656898656899
# Test metadata and privateMetadata against ground truth data
metadata_gt = {
"type": "lightField",
"image": {
"width": 3280,
"height": 3280,
"orientation": 1,
"representation": "rawPacked",
"rawDetails": {
"pixelFormat": {
"rightShift": 0,
"black": {"r": 168, "gr": 168, "gb": 168, "b": 168},
"white": {"r": 4095, "gr": 4095, "gb": 4095, "b": 4095},
},
"pixelPacking": {"endianness": "big", "bitsPerPixel": 12},
"mosaic": {"tile": "r,gr:gb,b", "upperLeftPixel": "b"},
},
"color": {
"ccmRgbToSrgbArray": [
3.1115827560424805,
-1.9393929243087769,
-0.172189861536026,
-0.3629055917263031,
1.6408803462982178,
-0.27797481417655945,
0.07896701246500015,
-1.1558042764663696,
2.0768373012542725,
],
"gamma": 0.41666001081466675,
"applied": {},
"whiteBalanceGain": {"r": 1, "gr": 1, "gb": 1, "b": 1.2578125},
},
"modulationExposureBias": -1.1139298677444458,
"limitExposureBias": 0,
},
"devices": {
"clock": {"zuluTime": "2014-05-16T13:31:21.000Z"},
"sensor": {
"bitsPerPixel": 12,
"mosaic": {"tile": "r,gr:gb,b", "upperLeftPixel": "b"},
"iso": 207,
"analogGain": {"r": 5.625, "gr": 4.125, "gb": 4.125, "b": 4.75},
"pixelPitch": 1.3999999761581417e-06,
},
"lens": {
"infinityLambda": 18.033008575439453,
"focalLength": 0.006840000152587891,
"zoomStep": 943,
"focusStep": 672,
"fNumber": 1.9199999570846558,
"temperature": 23.642822265625,
"temperatureAdc": 2896,
"zoomStepperOffset": -2,
"focusStepperOffset": 25,
"exitPupilOffset": {"z": 0.22357696533203125},
},
"ndfilter": {"exposureBias": 0},
"shutter": {
"mechanism": "sensorOpenApertureClose",
"frameExposureDuration": 0.016554275527596474,
"pixelExposureDuration": 0.016554275527596474,
},
"soc": {"temperature": 27.0545654296875, "temperatureAdc": 3319},
"accelerometer": {
"sampleArray": [
{
"x": -0.019607843831181526,
"y": 1.015686273574829,
"z": 0.03529411926865578,
"time": 0,
}
]
},
"mla": {
"tiling": "hexUniformRowMajor",
"lensPitch": 1.3999999999999998e-05,
"rotation": -0.0008588103810325265,
"defectArray": [],
"config": "com.lytro.mla.11",
"scaleFactor": {"x": 1, "y": 1.0003734827041626},
"sensorOffset": {
"x": -8.177771568298344e-06,
"y": 8.002278804779054e-07,
"z": 2.5e-05,
},
},
},
"modes": {
"creative": "tap",
"regionOfInterestArray": [
{
"type": "exposure",
"x": 0.5125047564506531,
"y": 0.723964273929596,
},
{
"type": "creative",
"x": 0.5125047564506531,
"y": 0.723964273929596,
},
],
"manualControls": False,
"exposureDurationMode": "auto",
"isoMode": "auto",
"ndFilterMode": "auto",
"exposureLock": False,
"overscan": 1.0526316165924072,
},
"camera": {
"make": "Lytro, Inc.",
"model": "F01",
"firmware": "v1.0a208, vv1.2.2, Wed Sep 4 14:43:36 PDT 2013, "
"fec5f2a239a2823b391a385b94ec6fc8c56bb5b1, "
"mods=0, ofw=0",
},
}
private_metadata_gt = {
"devices": {"sensor": {"sensorSerial": "0x408F1FB8B3515D9A"}},
"camera": {"serialNumber": "A303134643"},
}
assert img._meta["metadata"] == metadata_gt
assert img._meta["privateMetadata"] == private_metadata_gt
# Read metadata only
img = iio.imread(lfp_file, format="lytro-lfp", meta_only=True)
assert np.array_equal(img, [])
assert img._meta["metadata"] == metadata_gt
assert img._meta["privateMetadata"] == private_metadata_gt
# Test fail
test_reader = iio.read(lfp_file, "lytro-lfp")
with pytest.raises(IndexError):
test_reader.get_data(-1)
with pytest.raises(IndexError):
test_reader.get_data(3)
def test_lytro_raw_illum_reading(test_images):
"""Test reading of lytro .raw file"""
# Get test images
raw_file = test_images / RAW_ILLUM_FILENAME
raw_meta_file = test_images / RAW_ILLUM_META_FILENAME
# Read image and metadata file
img = iio.imread(raw_file, format="lytro-illum-raw")
meta_gt = json.load(open(raw_meta_file))
# Test image shape and some pixel values
# Pixel values are extracted from the Matlab reference implementation
assert img.shape == (5368, 7728)
assert round(img[24, 48], 15) == 0.738025415444770
assert round(img[3692, 86], 15) == 0.132942326490714
assert round(img[258, 1658], 15) == 0.687194525904203
assert round(img[1349, 6765], 15) == 0.113391984359726
assert round(img[210, 6761], 15) == 0.162267839687195
assert round(img[5231, 6459], 15) == 0.784946236559140
assert round(img[5213, 7477], 15) == 0.095796676441838
assert round(img[2745, 3789], 15) == 0.760508308895406
assert round(img[1428, 4192], 15) == 0.621700879765396
# Test extracted metadata against extracted metadata from .txt file
assert img._meta == meta_gt
# Read metadata only
img = iio.imread(raw_file, format="lytro-illum-raw", meta_only=True)
assert np.array_equal(img, [])
assert img._meta == meta_gt
# Test fail
test_reader = iio.read(raw_file, "lytro-illum-raw")
with pytest.raises(IndexError):
test_reader.get_data(-1)
with pytest.raises(IndexError):
test_reader.get_data(3)
def test_lytro_raw_f0_reading(test_images):
"""Test reading of lytro .raw file"""
# Get test images
raw_file = test_images / RAW_F0_FILENAME
raw_meta_file = test_images / RAW_F0_META_FILENAME
# Read image and metadata file
img = iio.imread(raw_file, format="lytro-f01-raw")
meta_gt = json.load(open(raw_meta_file))
# Test image shape and some pixel values
# Pixel values are extracted from the Matlab reference implementation
assert img.shape == (3280, 3280)
assert round(img[16, 7], 15) == 0.044688644688645
assert round(img[803, 74], 15) == 0.064713064713065
assert round(img[599, 321], 15) == 0.059340659340659
assert round(img[1630, 665], 15) == 0.198046398046398
assert round(img[940, 2030], 15) == 0.130647130647131
assert round(img[3164, 2031], 15) == 0.129914529914530
assert round(img[3235, 3250], 15) == 0.136019536019536
assert round(img[2954, 889], 15) == 0.159706959706960
assert round(img[1546, 1243], 15) == 0.227350427350427
# Test extracted metadata against extracted metadata from .txt file
assert img._meta == meta_gt
# Read metadata only
img = iio.imread(raw_file, format="lytro-f01-raw", meta_only=True)
assert np.array_equal(img, [])
assert img._meta == meta_gt
# Test fail
test_reader = iio.read(raw_file, "lytro-f01-raw")
with pytest.raises(IndexError):
test_reader.get_data(-1)
with pytest.raises(IndexError):
test_reader.get_data(3)
|