chainer-fast-neuralstyle icon indicating copy to clipboard operation
chainer-fast-neuralstyle copied to clipboard

Keep original colors?

Open artnose opened this issue 8 years ago • 5 comments

Is it possible to add a flag to keep original color of the image and only transfer the style?

// from jcjohnson's neural style -- Combine the Y channel of the generated image and the UV channels of the -- content image to perform color-independent style transfer.

artnose avatar Dec 13 '16 16:12 artnose

Pass --keep_colors option.

yusuketomoto avatar Dec 16 '16 08:12 yusuketomoto

That would be awesome, but I'm getting an error..
Traceback (most recent call last): File "generate.py", line 55, in <module> med = original_colors(original, med) File "generate.py", line 27, in original_colors return Image.merge('HSV', (h, s, vs)).convert('RGB') File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2404, in merge raise ValueError("size mismatch") ValueError: size mismatch

artnose avatar Dec 16 '16 14:12 artnose

Hmm, so, input image was 800x531 and output image is 800x528 with out --keep_colors
so, it's cropping it and then the color merge doesn't work

artnose avatar Dec 16 '16 14:12 artnose

I'm getting very similar error, and only when I use the --keep_colors option.

I'm using the "resize-conv" branch. I have this working on Windows 10 with GPU.

Here the my console dump for a --keep_colors option: Traceback (most recent call last): File "generate.py", line 55, in med = original_colors(original, med) File "generate.py", line 27, in original_colors return Image.merge('HSV', (h, s, vs)).convert('RGB') File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 2444, in merge raise ValueError("size mismatch") ValueError: size mismatch

HappyCoderMan avatar Mar 15 '17 13:03 HappyCoderMan

Both image dimensions have to be divisible by 4, otherwise the output resolution won't match the input and original_colors function needs them to be identical.

For arbitrary dimensions to work, just resize one of the images to match the resolution before calling the function. Replace the condition with the following code:

if args.keep_colors:
    med = original_colors(original.resize((med.size), 3), med)

6o6o avatar Apr 14 '17 17:04 6o6o