question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance of saturation

See original GitHub issue

Saturation operator needs to be faster. It’s really slow compared to imagemagick’s modulate.

$ rio info $orig | jq .shape
[
  8192,
  8192
]
$ time rio color $orig f416_rio_lch.tif "saturation 130"

real    1m10.490s
$ time convert $orig -modulate 100,130 f416_magick.tif

real    0m6.954s

Investigating…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
perrygeocommented, Apr 28, 2016

Instead of going through the CLI, a direct comparison might be more illustrative of the performance difference:

with rasterio.open(srcpath) as src:
    arr = src.read().astype('float64') / 255.0
    assert arr.shape == (3, 4096, 4096)

    start = time.time()
    res = skimage_saturation(arr, 120)
    print("Scikit-image based saturation: {} seconds".format(time.time() - start))

    start = time.time()
    res2 = cython_saturation(arr, 120)
    print("Cython saturation: {} seconds".format(time.time() - start))

Saturation on a 4096x4096 array gives us

Scikit-image based saturation: 20.527370929718018 seconds
Cython saturation: 12.189836978912354 seconds

So the Cython is about 68% faster for a large array. Modest but significant.

0reactions
perrygeocommented, Apr 25, 2016

See https://github.com/mapbox/rio-color/pull/22 for cython implementation

Benchmarks

Tested on 4096x4096 tiled, uncompressed, rgba GeoTIFF. New method is significantly faster than old. Not as fast a imagemagick but it works better, retaining the profile of the input data.

method time notes
convert -modulate 1.5s HSV colorspace is way faster
convert -set option:modulate:colorspace lch -modulate 6.8s loses geotiff tags, tiling, compression, trouble with alpha bands
old skimage-based rio color "saturation ..." 12.5s
new cython-based rio color "saturation ..." 8.8s

Bottom line is performance is 1/3 better than the skimage method but still way slower than our HSV-based saturation with convert.

Visuals

The results are not floating-point-exact with the skimage method but, when cast to 8bit rgb there is no perceptual difference.

Here’s a demo of the saturation. I chose to use a stock photo instead of satellite image since it more clearly demonstrates the effect of saturation. This was created by the following rio_color script

from rio_color.colorspace import saturate_rgb
import rasterio

with rasterio.open("test.png") as src:
    arr = src.read().astype('float64') / 255.0
    arr = arr[0:3,]
    prof = src.profile
    prof['count'] = 3
    for sat in range(0, 250, 5):
        with rasterio.open("test_{:0>3}.png".format(sat), 'w', **prof) as dst:
            rgb = saturate_rgb(arr, sat/100.0)
            rgb8 = (rgb * 255).astype('uint8')
            dst.write(rgb8)

saturation ranging from 0 (B&W) to 250% (garishly over-saturated). Sorry about the giffiness of the image - you get the idea though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance - Saturation (Wait Time|Queue Length)
Saturation is where a resource has more load than it can handle. It can be seen either as: the length of a request...
Read more >
Mitigating Performance Saturation in Neural Marked Point ...
Neural marked point processes possess good interpretability of probabilistic models as well as the representational power of neural networks.
Read more >
Performance Bottleneck : High CPU Utilization vs High CPU ...
But what about CPU Saturation? Should we also scale when the CPU is saturated, but the utilization is low (say 40%). Here it...
Read more >
Performance of saturation diving emergency hyperbaric ...
This appendix relates to IOGP 478 – Performance of saturation diving emergency hyperbaric evacuation and recovery. Get it now.
Read more >
Best achievable control system performance: the saturation ...
This paper proposes a methodology for the quantification of the best achievable closed loop control system performance for a linear process in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found