dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

Choose color of transparency #80

Closed privefl closed 5 years ago

privefl commented 5 years ago

I'm trying to read this image:

library(imager)
img <- load.image("https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Scatter_diagram_for_quality_characteristic_XXX.svg/1000px-Scatter_diagram_for_quality_characteristic_XXX.svg.png")
plot(img)

I get a black background where it is transparent in the initial image. And I would like this to be white instead. How can I achieve this?

Thanks

ShotaOchi commented 5 years ago

What you need is flatten.alpha function. Try to use it.

img2 <- flatten.alpha(img)
plot(img2)
privefl commented 5 years ago

Hum, I'm not able to load this image on Windows.

privefl commented 5 years ago

On Linux, this does not affect the rendering of the image.

dahtah commented 5 years ago

I think you've hit an old bug caused by the weird file name (.svg.png). It's fixed in the current master, also even in the version you have, if you save the file first, then load, then use flatten.alpha, you should be fine.

privefl commented 5 years ago

Thanks Simon and Shota.