Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using imwrite to write an array of AlphaColorValues where an array of RGB{Ufixed8}s succeeds #200

Closed
yurivish opened this issue Oct 8, 2014 · 5 comments

Comments

@yurivish
Copy link
Contributor

yurivish commented Oct 8, 2014

In Julia 3.1 on OS X and the latest version of Images.jl, I have a 2d array of (Uint8, Uint8, Uint8) that I want to save to a file as an image.

tuple2rgb(x) = RGB{Ufixed8}(map(d -> reinterpret(Ufixed8, d), x)...)
tuple2rgba(x) = AlphaColorValue(
    tuple2rgb(x),
    x[1] == x[2] == x[3] == 0xff ? Ufixed8(0.0) : Ufixed8(1.0)
)

When I do imwrite(map(tuple2rgb, canvas.colors),"out.png")) everything is fine, but when I try imwrite(map(tuple2rgba, canvas.colors),"out.png")) I get the following error:

ERROR: map has no method matching map(::MapNone{AlphaColorValue{BGR{UfixedBase{Uint8,8}},UfixedBase{Uint8,8}}}, ::AlphaColorValue{RGB{UfixedBase{Uint8,8}},UfixedBase{Uint8,8}})
in map! at /Users/yurivish/.julia/v0.3/Images/src/map.jl:336
in map at /Users/yurivish/.julia/v0.3/Images/src/map.jl:307
in image2wand at /Users/yurivish/.julia/v0.3/Images/src/io.jl:292
in imwrite at /Users/yurivish/.julia/v0.3/Images/src/io.jl:163

I've tried playing around with providing different types for the alpha parameter but nothing seems to work. Is this the right way to save an array of transparent colors?

@timholy timholy closed this as completed in 1c6c82b Oct 8, 2014
@timholy
Copy link
Member

timholy commented Oct 8, 2014

For this fix to work, you'll also need to say Pkg.checkout("Color") until the next version of Color gets tagged.

@yurivish
Copy link
Contributor Author

yurivish commented Oct 8, 2014

This is awesome. Wasn't expecting a reply so quickly – thanks!

I seem to still be having trouble getting my code to work, though. I've updated Images.jl and checked out the master branch of Color, and my program now runs successfully, but the image that's saved seems to have alpha=1 at every pixel even when I construct the colors as AlphaColorValue(tuple2rgb(x), Ufixed8(0.5)).

@yurivish
Copy link
Contributor Author

yurivish commented Oct 8, 2014

Oh hang on, I think I'm saving these as jpgs.

@yurivish
Copy link
Contributor Author

yurivish commented Oct 8, 2014

Yep. That was it. :-)

Maybe rather than implicitly dropping an entire channel of the image it should throw an error, and ask that you explicitly specify that you want to do something more like coercing than converting? That would make sense for my use and I wonder if it would be helpful in general.

@timholy
Copy link
Member

timholy commented Oct 8, 2014

You caught me at a good time; it had been days since I'd had a moment to address issues.

Making this an error could be a bit tricky; it depends on the file format, and ImageMagick handles all the details of the file format. If you have any good ideas, I'd be happy to entertain a pull request. Also, any progress on this is currently hampered by JuliaLang/julia#8618, which seems to prevent direct coercion.

BTW, I tagged a new version of Color, so you can Pkg.free("Color").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants