jcjohnson / neural-style

Torch implementation of neural style algorithm
MIT License
18.31k stars 2.7k forks source link

Skip pixels with Alpha=0 #200

Open jbartolozzi opened 8 years ago

jbartolozzi commented 8 years ago

Is it possible to output a png image with alpha values < 1? Id like to feed in a png source image with a background masked out and have the output also obey the mask / skip pixels with an alpha of 0 from the source.

htoyryla commented 8 years ago

James Bartolozzi notifications@github.com kirjoitti 7.4.2016 kello 21.51:

Is it possible to output a png image with alpha values < 1? Id like to feed in a png source image with a background masked out and have the output also obey the mask / skip pixels with an alpha of 0 from the source.

The Torch image package does not appear to support alpha channel: the images may have either 1 channel (grayscale) or 3 three channels (usually RGB). The image package converts the image into a Tensor for processing in Torch, and this tensor is of dimensions (number of channels) x (width) x (height).

Similarly, from the code it appears that neural-style handles the images in the form of such tensors, so no alpha channel there. Furthermore, even if it one could add one more channel to the tensor to accomodate the alpha channel, it can be questioned if there would be any meaning in feeding the alpha channels through the neural network.

For background masking, it seems to me, the simplest and correct procedure is to separate it before neural-style and then reapply the mask after neural-style. This should not be too difficult to arrange external to neural-style. This should doable using Imagemagick to extract the alpha channel to a mask image, then running the png through neural-style and then copying the alpha channel with Imagemagick to the result png.

Hannu

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub