yusuketomoto/chainer-fast-neuralstyle

Keep original colors?

Opened this issue · 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.

Pass --keep_colors option.

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

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

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

6o6o commented

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)