Restore special casing of grayscale images in PostScript backend. by anntzer · Pull Request #12871 · matplotlib/matplotlib · GitHub
Skip to content

Restore special casing of grayscale images in PostScript backend. - #12871

Closed
anntzer wants to merge 1 commit into
matplotlib:masterfrom
anntzer:ps-grayscale
Closed

anntzer wants to merge 1 commit into
matplotlib:masterfrom
anntzer:ps-grayscale

Conversation

@anntzer

@anntzer anntzer commented Nov 23, 2018

Copy link
Copy Markdown
Contributor

This divides the filesize by ~3 by not storing three identical channels
(e.g. compare the size of

imshow(np.random.rand(255, 255), cmap="gray")
gca().set_axis_off()
savefig("test.ps")

before and after the patch).

Looks like some kind of similar functionality was present before mpl2.0, though with some weird magic factors (https://github.com/matplotlib/matplotlib/pull/5718/files#diff-b465967f537465fec4960b152fa49cffL415), and I stumbled on some vestigial leftovers of it (https://github.com/matplotlib/matplotlib/pull/5718/files#diff-b465967f537465fec4960b152fa49cffL457 where the "image" command comes from)...

No hard numbers but I don't think the performance cost (on non-grayscale images) really matters as we're going to iterate through the array just after to serialize it anyways.

Probably the same thing can be done for the pdf backend -- see grayscale parameter of _writeImg.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

This divides the filesize by ~3 by not storing three identical channels
(e.g. compare the size of
```
imshow(np.random.rand(255, 255), cmap="gray")
gca().set_axis_off()
savefig("test.ps")
```
before and after the patch).
@jklymak

jklymak commented Nov 23, 2018

Copy link
Copy Markdown
Member

@QuLogic

QuLogic commented Nov 24, 2018

Copy link
Copy Markdown
Member

Those factors are luminance conversions.

@anntzer

anntzer commented Nov 24, 2018

Copy link
Copy Markdown
Contributor Author

@anntzer anntzer self-assigned this Nov 26, 2018
@anntzer anntzer closed this Nov 26, 2018
@anntzer anntzer mentioned this pull request Sep 3, 2019
6 tasks
@anntzer
anntzer deleted the ps-grayscale branch March 20, 2022 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants