Comments (5)
Wow, I can indeed reproduce this. All is fine when the 1.0 *
is removed.
What happens is that by multiplying with 1.0
the array is converted from uint8 to float64. The writer will convert the code to uint8 again, assuming that the data is between 0 and 1, resulting in overflow, and consequently a cute alien cat.
One thing that should be done is clip the array before converting to uint8. Further, we may also make it smarter and scale the image if we see it's between 0..255. Not sure if this is a good idea or not.
from imageio.
Maybe @stefanv or @blink1073 can chime in here, since this touches on where we lay the boundary between skimage and imageio. The question is: what should imageio do when it receives a floating point array for a format that can only be saved in uint8?
Some options:
- Raise an error: require the user to provide uint8
- Multiply by 255 and convert to uint8 (with clipping)
- Check range, scale that to 0..255 and convert to uint8
- Include skimage's
util.convert()
in imageio and use that
I am leaning towards (4), since the behavior of that function seems well though through. Although maybe this is something the user should call before passing the array to imageio.imsave
.
from imageio.
I'd say if the values are in [0, 1], rescale appropriately to equivalent range in [0, 255], otherwise rescale to fill [0, 255].
from imageio.
I don't know if this help, but if you try to put -1.0
, the image will be correct.
from imageio.
I agree with @blink1073 (a warning might be good)
from imageio.
Related Issues (20)
- super slow video reads HOT 6
- imageio v2.33.0 requieres Pillow>=9.1.0 for GIFs HOT 1
- Trouble using freeimage plugin on MacOS arm64 HOT 2
- 2.33.1: pytest is failing in 5 units HOT 1
- [Question] What tonemapping method does the imageio library use when reading HDR images? HOT 2
- title of the gif got stacked together HOT 2
- UnicodeDecodeError if metadata is not UTF-8 encoded (pyav plugin) HOT 3
- [request] more color/palette control on GIF writing HOT 3
- Transition from v2 ffmpeg read/write to v3 pyav read/write: quality, batching HOT 7
- AttributeError: 'SeekableFileObject' object has no attribute 'readline' HOT 1
- Find out what kwargs are available for each function
- Only partial DICOM layers loading in Google Colab using imageio.volread HOT 6
- How to suppress FFMPEG warning for BluRay files? HOT 1
- How to add a pause between loops of a GIF? HOT 1
- Wrong time unit in documentation of pillow_legacy
- support read gzip data in .nrrd file HOT 2
- can I get frame image filename in imiter when using ffmpeg plugin?
- Test failures with NumPy 2.0.0rc1 HOT 1
- Please make it possible to run tests against `test_images` without Internet access
- Unable to write colored gifs with pyav
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imageio.