neural-style icon indicating copy to clipboard operation
neural-style copied to clipboard

Tiling images to increase the size and detail of the final output image

Open ProGamerGov opened this issue 8 years ago • 9 comments

Previously these kinds of things looked ugly due to the bordered between the different tiles. A Reddit user recently came up with a solution to this problem, but there's a catch. Currently the only working method involved use paid Adobe InDesign software. I am told that ImageMagick is capable of the same thing, but we need a working script first. Maybe down the road, Neural-Style can have this built in.

Currently the Neural-Style Wiki only lists the method using InDesign.

Similar to issue: https://github.com/jcjohnson/neural-style/issues/36

Technique described here: https://www.reddit.com/r/deepdream/comments/4qvuju/buscemi_6k/d4yg4qk, and here: https://www.reddit.com/r/imagemagick/comments/4r8h0x/how_to_crop_an_image_into_overlapping_tiles/

From the Reddit post:

  1. Crop/Split an image using an overlapping system or grid so we end up with 9 or 12 pieces (these twelve images will be uprezzed in with an inbetween step using deep dream)
  2. Feather each of the result images edges
  3. Assemble the grid of now larger images with the proportional overlapping edges making use of the feathered alpha from the previous step (to blend the grid result minimizing a grid look.) Here is the idea in a nutshell. We are trying to "dream" a deep style painting and then enlarge the image using cropped tiles and more dreaming/processing. So we'd need to crop the initial result into overlapping segments, process/dream the segmented image to gain more detail and then reassemble the now larger pieces into an overlapping grid WITH feathered edges. (The overlap and feather are necessary to avoid a grid effect in the final output) See bottom links for visual example of what I'm talking about. Here are some resources I found on the topic. The first link here looks especially useful but I don't even know how to call the script. (I downloaded it, but fail to understand its usage in practice I need an example of where to place the usage code or how to call the script. If anybody feels like helping with even just this step I'd really appreciate it) Cropping split with overlap: http://www.fmwconcepts.com/imagemagick/overlapcrop/index.php http://imagemagick.org/discourse-server/viewtopic.php?t=22942 Feathered edges: http://www.imagemagick.org/Usage/thumbnails/#soft_edges Montage image compilation: http://www.imagemagick.org/Usage/montage/#overlap For even further explanation here at the bottom are some example steps of the same process but setup in Indesign if it helps illustrate what I'm trying to achieve.

Step 1. Dream a neural-style result image Step 2. In Adobe InDesign setup an overlapping grid and then paste the result image into each box. Step 3. Set the document size to match your grid box size and make multiple pages for each box Step 4. Output each of the pages as their own jpeg image using the export function. Step 5. Dream each of the 12 images using the original style image. Best to setup a loop so you don't have to wait around running each one. Step 6. Use the grid from step 2 and create a new document the exact size of the whole grid. Drag each of your new result images into each step of the grid and fit photo size to box. Step 7. Use Gradient and Basic feather effects to blend the tile edges together Step 8. Output final result image. Note - Since my Indesign document was setup at the size of the original result the final image resolution doesn't match the available resolution since each box now contains a higher resolution than the original 72dpi. To compensate I just up the resolution within the output settings and you gain detail in the final output.

Maybe this process could become part

ProGamerGov avatar Jul 05 '16 04:07 ProGamerGov

I have found a working method to crop the image into over lapping crops!

This was done on Ubuntu 14.04.4:

First we need to install the software and it's dependencies:

$ cd ~

$ git clone https://github.com/SpringRoll/image-tiler

$ npm install zpad

$ npm install untildify

$ npm install pngjs

$ npm install png-crop

$ sudo ln -s /usr/bin/nodejs /usr/bin/node

My command structure example:

./index.js --in "~/magick/malibu_Sunset.png" --out ~/magick/zones/ --width 256 --height 256 --overlap 50

The --overlap value is how many pixels of over lap there are between the individual small crops.

Now, the trick is running the images through neural style and then putting them back together.


My attempts at piecing it back together: https://imgur.com/a/50Wvy Using these commands:

  montage null:   malibu_Sunset_*.png   null: \
-tile 5x4 -geometry -56-10  montage_overlap.jpg

And

montage malibu_Sunset_00.png malibu_Sunset_01.png malibu_Sunset_02.png malibu_Sunset_03.png malibu_Sunset_04.png malibu_Sunset_05.png malibu_Sunset_06.png malibu_Sunset_07.png malibu_Sunset_08.png malibu_Sunset_09.png malibu_Sunset_10.png malibu_Sunset_11.png malibu_Sunset_12.png malibu_Sunset_12.png malibu_Sunset_13.png malibu_Sunset_14.png malibu_Sunset_15.png malibu_Sunset_16.png malibu_Sunset_17.png malibu_Sunset_18.png malibu_Sunset_19.png \-mode Concatenate -tile x5 montage_array.jpg

The main issue seems to be that when I add the --overlap value, it creates a few crops that are not the same size as the rest. The -geometry value for putting the images back together seems to have to be less than the --overlap value.

Maybe recombining with a different program would be better?

Making progress!

ProGamerGov avatar Jul 05 '16 06:07 ProGamerGov

look at enblend to recombine tiles http://enblend.sourceforge.net/

lulu1315 avatar Jul 11 '16 12:07 lulu1315

Tried it. Tiled images need to have alpha chanel to combine them with enblend. Could you explain how to do that? As well as that - it seems that just slicing images and process them throw neural style algorithm with the same style without changing style image or splitting it is able to give a good result

Allycen avatar Jul 14 '16 21:07 Allycen

@ProGamerGov how did you run the images through neural style witthout getting different styles for tiles? As far as I understand each tile will be a unique artwork . image

s-a avatar Aug 18 '16 18:08 s-a

@s-a Did you follow the guide on the Neural-Style wiki? The way how you keep the tiles from being random, is you run your image through neural-style first before you chop it up into overlapping tiles. This initial neural-style run's settings should be used for each of the tiles so that the style remains the same.

How did you arrive at your image? Are you using InDesign?

ProGamerGov avatar Aug 18 '16 18:08 ProGamerGov

@ProGamerGov I am using the same setup for two tiles in my example but after 1000 iterations they differ as we can see. seems i understand not right... Is It possible to apply learned setting of 1000th iteration for each tile? Then I would expect no random effect.

s-a avatar Aug 18 '16 20:08 s-a

@s-a Normally I save the tile pieces at 50,150, 250, and 500 iterations, then I piece them together and see which iteration blends the best. I find that depending on the style and settings, the iteration you use for the tiles can vary greatly.

ProGamerGov avatar Aug 18 '16 20:08 ProGamerGov

@ProGamerGov i am experimenting with image magic to create a no cost solution. tryied a few variations but get always super ugly edges ;( @jcjohnson any progress out there using tile or another technique?

s-a avatar Aug 21 '16 14:08 s-a

@s-a There is now a version of Neural-Style which utilizes internal tiling located, here: https://github.com/VaKonS/neural-style. Because the tiling is internal, and due to a few other tricks, it's pretty much impossible to tell where the tile edges are on the output image.

ProGamerGov avatar Jan 15 '18 22:01 ProGamerGov