MCPcopy Create free account
hub / github.com/NVlabs/SegFormer / test_adjust_gamma

Function test_adjust_gamma

tests/test_data/test_transform.py:343–376  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

341
342
343def test_adjust_gamma():
344 # test assertion if gamma <= 0
345 with pytest.raises(AssertionError):
346 transform = dict(type='AdjustGamma', gamma=0)
347 build_from_cfg(transform, PIPELINES)
348
349 # test assertion if gamma is list
350 with pytest.raises(AssertionError):
351 transform = dict(type='AdjustGamma', gamma=[1.2])
352 build_from_cfg(transform, PIPELINES)
353
354 # test with gamma = 1.2
355 transform = dict(type='AdjustGamma', gamma=1.2)
356 transform = build_from_cfg(transform, PIPELINES)
357 results = dict()
358 img = mmcv.imread(
359 osp.join(osp.dirname(__file__), '../data/color.jpg'), 'color')
360 original_img = copy.deepcopy(img)
361 results['img'] = img
362 results['img_shape'] = img.shape
363 results['ori_shape'] = img.shape
364 # Set initial values for default meta_keys
365 results['pad_shape'] = img.shape
366 results['scale_factor'] = 1.0
367
368 results = transform(results)
369
370 inv_gamma = 1.0 / 1.2
371 table = np.array([((i / 255.0)**inv_gamma) * 255
372 for i in np.arange(0, 256)]).astype('uint8')
373 converted_img = mmcv.lut_transform(
374 np.array(original_img, dtype=np.uint8), table)
375 assert np.allclose(results['img'], converted_img)
376 assert str(transform) == f'AdjustGamma(gamma={1.2})'
377
378
379def test_rerange():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected