Coder Social home page Coder Social logo

Comments (5)

almarklein avatar almarklein commented on May 1, 2024

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.

almarklein avatar almarklein commented on May 1, 2024

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:

  1. Raise an error: require the user to provide uint8
  2. Multiply by 255 and convert to uint8 (with clipping)
  3. Check range, scale that to 0..255 and convert to uint8
  4. 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.

blink1073 avatar blink1073 commented on May 1, 2024

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.

gabriel-almeida avatar gabriel-almeida commented on May 1, 2024

I don't know if this help, but if you try to put -1.0, the image will be correct.

from imageio.

stefanv avatar stefanv commented on May 1, 2024

I agree with @blink1073 (a warning might be good)

from imageio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.