# Mapping Resources > Tutorials/How-To >  [Award Winner] Tutorial on how to create seamless textures out of anything

## Redrobes

I am going to post my tried and trusted way of creating seamless textures out of any photo that has some basic properties in PSP but I would think any significant paint package should be fine.

EDIT##############################################  #################################################
##### See lower down this tutorial for a script to automate all of this process including the image flattening to give a uniform brightness ######
##################################################  ################################################

The basic property is that the pattern on the image has an interesting texture that has basically uniform brightness across it. Now I have a tool to force images to become steady brightness so I can do any image but without this you will have to find some photo that matches this property and that is not a significant limitation.

So here is a photo I took in a park. I am notorious for taking photos of interesting plants in garden centers ! A great free resource if you ask me !

----------


## Redrobes

Stage 1. Chop out the texture bit and try to ensure that the edges are roughly the same brightness.

----------


## Redrobes

Stage 2. Resample to a convenient size like 1024x1024. Then create a new image double size e.g. 2048x2048 and paste in the first into 4 quadrants of the second ensuring that its exactly in the corners and lined up.

----------


## Redrobes

Stage 3. Keep the original cut one handy and get out the freehand selection tool or it might be called the lasso tool. In PSP you need to set the options of this to make the freehand selection feather something quite large like 80 or 100 or about 10 - 20% of the size of the image.

Now cut a shape out of the first original cut image with this kind of pattern, copy that and paste it over the vertical joins of the quadrant image such that the top dumbell end is one quarter way down the vertical join so that the bottom of the dumbell is at the three quarter way down the vertical join. You may need more than one paste to cover the vertical seam.

Like this :-

----------


## Redrobes

Stage 4. Repeat using a new selection in the horizontal direction to cover the horizontal seam.

----------


## Redrobes

Stage 5. Cut out the middle 1024x1024 (or the original size of image). The easiest way to do this is to use the Image/Canvas Size and set it to 1024x1024 and ask it to center it with the two check boxes.

----------


## Redrobes

Your done. There is an optional stage if you like...

Stage 6. You may if you desire cut out the center circle of your original image and blend this over the final image. Dont touch the edges of course as they are now nicely tiled.

Anyway, to see what this image looks like tiled. This is a 3x3 tile of the image.

I have been using this technique for years and it always works. Some images don't like to be tiled and you have to munge them a bit but in general this is a fail safe way of taking texture sources and getting them seamless.

----------


## Redrobes

Like I mentioned at the start you need to keep the overall tone uniform for it not to repeat. Using my internal program I can generate this image and tile it 3x3 like this which allows a better look. If you want me to run this for a texture you have then email me and ill do that for you, but if your careful then you wont need it.

----------


## Redrobes

One final note. You can do this with 3D objects too. I originally developed this photo technique from adapting it from a 3D object tutorial on the web somewhere. You can create a pavement by creating paved tiles as 3D objects then taking the right hand side paving stones of a patch and placing them on the left and vice versa and then also for the top and bottom then slice the 3D object in a square cutting the edge paving slabs into halves and then your 3D bit of paving can be tiled.

End of tutorial - any questions or comments ?

----------


## Gamerprinter

Good Tut, Redrobes - have some REP! I've got to give this technique a try.

----------


## Robbie

That tool you have...is that similar to high pass?  I've used high pass on textures before to even the brightness, but it kills off the colors.

----------


## Redrobes

The program I use is a spatial filter which does Fourier analysis. If either of those things mean much then ill talk about it and share filters as it can be indispensable but otherwise its a hard technique to use.

I am using a high pass filter but I am keeping the average or DC component. The program allows you to set how much of the high pass to keep. I am only knocking out a little of the low pass - just enough to even out the brightness.

In theory if you use a high pass and a very very large blur - enough to average the whole image to a single shade and then add the two together then it should produce the same effect. Generally tho, most paint packages clip the high pass or center it around the mid grey mark so that when you add them it would not look right.

----------


## RobA

> In theory if you use a high pass and a very very large blur - enough to average the whole image to a single shade and then add the two together then it should produce the same effect.


I had posted more detailed steps on the manual method previously here:
http://www.cartographersguild.com/sh...=5842#post5842

-Rob A>

----------


## su_liam

FFT and IFT. Two photoshop filters I can't get for mac. On my budget anyway. I've been interested in direct frequency synthesis for some time, but I can't seem to find the tools.

GeoTerSys is really starting to sound like an, "everything-plus-one-kitchen-sink," tool. Good luck building it, mate.

----------


## Redrobes

> FFT and IFT. Two photoshop filters I can't get for mac. On my budget anyway. I've been interested in direct frequency synthesis for some time, but I can't seem to find the tools.
> 
> GeoTerSys is really starting to sound like an, "everything-plus-one-kitchen-sink," tool. Good luck building it, mate.


I didnt realize that photoshop could do FFT's. I tried looking for a freebie image processor which includes an FFT/DFT transformer but I had no luck. I did come across this which has a lot of write up about what they are all about.

http://student.kuleuven.be/~m0216922/CG/fourier.html

Fascinating is that half way down it talks about doing high pass filters and keeping the DC component and then not two images underneath is a section about tiling images with a texture not that dissimilar from the tutorial above. Obviously its not just me that does this then.

A spatial filter can do some really magic stuff that would seem impossible. For example it can remove a grid from images pretty efficiently without altering the original. This is showing a bit of Publius December challenge where the hatching has been removed. It does destroy a bit of the normal image but its not that bad becuase the filter is so strongly targetted.

My little app is not part of Geo. Its very old actually but its another of those hard to use - well hard to explain how to use apps that gathers no interest outside of a specialist world.

----------


## Redrobes

> I had posted more detailed steps on the manual method previously here:
> http://www.cartographersguild.com/sh...=5842#post5842
> 
> -Rob A>


Rob, I checked out this post as follows...




> One way to get rid of the pattern artifacts (in the grass layer) is to apply a high pass filter effect (using the following steps)
> 
> 1. duplicate the grass layer
> 2. gaussian blur the new layer
> 3. invert the blurred layer
> 4. desaturate the now inverted, blurred layer
> 4. switch layer mode to overlay
> 5. play with the opacity if required
> 6. merge down
> ...


What you are doing here is generating the low pass version and removing that from the image leaving the high pass only which would even out the brightness. Its that step of desaturating thats a bit odd. What I reckon you need for this technique is to take an image and call it A. Clone it to B and again to C. Take C and blur it so massively that its one uniform shade. Take B and remove C from it - thats sort of like the ultimate desaturation. Take that result and blur it a little and then remove this image from A. Then you would be removing the low frequencies but not the DC component so it should give the high pass but keep the DC colour. Its the same as doing the high pass and adding back in the DC of course as its A - (B - C) which is A - B + C. I'm still not sure how you can actually achieve this without the colour values going negative which would be clamped and then it wont work correctly. The only way I can see of getting around this is to split the images up into parts lighter than DC and parts darker than DC and process separately. I'll try this out offline and see if I can get that to work.

----------


## Redrobes

I tried this technique and its fine so here are the steps. Its a lot like RobA's but it wont have the desaturation stage and its probably more predictable because of it.

Get an image 1.
Blur it quite a lot 2.
Blur it until its a constant colour 3.
Use Image arithmetic to generate 2 - 3 => 4
Use Image arithmetic to generate 3 - 2 => 5
Take 1 and subtract 4 and add 5 => 6

...which is the equivalent to the spatial filtered image for high pass but with DC left in. You can do these stages to the tiled image if required.

----------


## su_liam

Back in the Dark Ages I had the google-fu and infinite wells of patience to research ift and fft filters for photoshop. I found at least one commercial filter and I could swear I found a free filter for Windoze. I also downloaded an open source frequency synthesis image app. Unfortunately, the source was included in a self-opening archive, an exe. At that point, after wading through pages and pages of irrelevant(although sometimes interesting) entries, I gave up and washed my hands of it. Apparently FFT and IFT are very common in sound editing apps...

I'm wondering if the desat he's using isn't to retain a bit more of the color information. Like retaining the DC component in the high pass rather than adding 128-grey. I'll have to mess with that meself.

----------


## RobA

IIR the desaturation was due to combining that layer using an overlay blend...it seemed to give the results I was looking for...Now I need to go back and play with yours (which makes the most sense having read that reference you provided on FFT and image processing.)  I'd rep you for the reference, but I can't  :Frown: 

-Rob A>

----------


## Redrobes

I reckon that the desat is having a similar effect as keeping some of the DC component. By removing the blur (merging the negative of it) the desat stage is to not take as much of that DC away as if you would if you didn't do it. If you didn't then the image would drop to near black.

Anyway, I am a big fan of ImageMagick (.org) and so I was thinking of a) getting some scripts together to do the tiling and the flattening of the images into tiles and then b) convert script into cgi and make a web page out of it so that you can upload an image and then push a button to get its tiled equiv. That would be well handy for everyone not least me.

Anyone know if this web host run Perl based CGI ?

----------


## Redrobes

I have written the script file now and I am including a zip below. To use this script you will need to put the contents of the zip in a fresh directory and ensure that you have a version of ImageMagick installed.

To run it, put an image to be tiled into that directory and call it start.png. Open up a command prompt and navigate to the directory. Type :-



```
GenTiled.bat 1 start.png
```

The first parameter is how much flattening you want. 0 is none, 1 is low, 2 is medium, 3 is high.

It should run for a while printing out a little status message now and again until it quits. You should get the image Final.png and Array.png which is a 3x3 tiled array of them to look at and see how well itd done it.

You can change the starting image filename to whatever you want and it can be of any size and aspect but the Final.png will always be of size 1024x1024 and of PNG type unless you modify the script.

It takes a little too long to run as a CGI script. I dont think my ISP would approve of the processing power consumed. If any of you are running a private web server then you could convert to a CGI script which would make an easy interface for the conversion.

Bugs and comments welcome as usual.

----------


## RobA

I tried it out and it works beautifully!  The only think that would be nice is a resize back down to the original image size...

I'd offer to host it on my personal server, but it really doesn't have the horsepower  :Frown: 

-Rob A>

----------


## Redrobes

I have seen a lot of people with tiling issues recently in maps and so I thought Id put a few demos of this automated seamless generator up. These textures come from www.CGTextures.com which is an excellent place to get a load of different types. Each set takes less than a minute to generate so theres no reason not to have them tiled any more. Some before and after images...

----------


## Redrobes

and a few more...

----------


## Airith

> *snip*
> To run it, put an image to be tiled into that directory and call it start.png. Open up a command prompt and navigate to the directory. Type :-
> 
> 
> ```
> GenTiled.bat 1 start.png
> ```
> 
> *snip*


Just wanted to say, that you need the contents of the zip in the ImageMagick directory. Took me forever to figure this out, it worked though so I hope it's not just me xD  btw: This worked great, now I'm looking for more pictures to make seamless

and if anyone isn't familiar with cmd prompt (ME  :Smile: ) then to get to the .bat, type "cd <directory of .bat>" and then just enter the code.  I spent a lot of time trying to figure out the really easy stuff  :Razz:   :Frown:

----------


## Redrobes

> Just wanted to say, that you need the contents of the zip in the ImageMagick directory.


No you dont. BUT, you do need to ensure that the 'convert.exe' of imagemagick is the one that is used when you run it on the command line. By default you will get the Windows OS conversion utility - in typical MS lets call everything by its most generic name - syndrome (Although IM could have helped itself by calling its command IMConvert.exe too). So when you set up IM, go to the 'path' settings on the computer/advanced/environment vars and double check that IM is before sys32 and then it will be fine. You can test by running up cmd.exe, ensure that the current directory is not sys32 and type convert.exe. If you get a message about converting OS then thats bad. If you get a huge list of image conversion command options then thats good and it should be alright. I would recommend checking and changing the path anyway.

You should have pinged me if you were having trouble. Its good to know that you tried to have a go tho. Glad it worked ok - its not perfect but its not too bad at most stuff, esp where the pattern is pretty random.

----------


## RobA

Bit of a thread bump...

Attached is a Gimp script that makes a seamless tile using this method.  It will work on any rectangular image, and creates a new seamless version.

It registers in the same menu as the default Make Seamless, as *Filters->Map->RR Make Seamless...*

The name is "RR Make seamless" (Thanks for the technique, RedRobes, I also credit you and your site in the script.)

The only parameter is a "Flatten" amount that lets you adjust the amount of high pass to apply.  The default is good in  most cases.

Here is an nice autumnal image from CG Texturess


And a random sized crop of the upper left hand corner:


Run through the filter to make a seamless tile:


And a sample of it tiled (1000x1000):


A zip of the script is attached  :Smile:   Just unzip and save into your Gimp script folder...

-Rob A>

----------


## RobA

Just to compare, here is the default GIMP make seamless result on the same cut out bit:


-Rob A>

----------


## Steel General

I dub the newly repped *bonk*

You've done it again oh master of the GIMP!  :Very Happy:

----------


## Redrobes

Cool ! I reckon the new RR filter is better than theirs ! In name and result  :Wink: 

Well done Rob - I will really have to have another go at Gimp one day. I just don't use normal image editors as much as I used to.

----------


## RobA

As epr the request in the other thread I have updated the script attached in post#27 to have an option to tile only horizontally and vertically.

It also now exposes the "copy the center and paste it" option available as a parameter so it can be turned off.

If tiling only horizontally or vertically, it would be best to set the flatten parameter quite low to prevent colour bleeding.

----------


## RobA

Old thread bump..

Has anyone used ImageSynth2 http://www.luxology.com/whatismodo/imageSynth/

Looks very good.

-Rob A>

----------


## Ascension

Never heard of it til now...looks like it does a great job.

----------


## ravells

> Old thread bump..
> 
> Has anyone used ImageSynth2 http://www.luxology.com/whatismodo/imageSynth/
> 
> Looks very good.
> 
> -Rob A>


Ohhh but $99 - not cheap...

----------


## Ghostman

I wish I could grasp batch file scripting well enough to make Redrobes' script to operate on all image files in a folder rather than a single file. Doing hundreds of files one at a time is pretty tiresome  :Neutral:

----------


## Redrobes

Well theres two options.

One is to get a list of all the files that need making seamless and then call the script on them. That can be done fairly easily with the command prompt by using "dir /b > files.txt" which gives a bare word listing of the files in files.txt then you can edit up the script by putting the call in front of each. Sounds bad and... well ok its not good. I would use a macro and that would sort that out so no so bad for me. You can also use a 'grep' type thing on DOS command line syntax to make it run over all the files in a directory too. Which would be easy if only I could remember the voodoo for doing that but its a foreach statement thing. Maybe someone could comment on that too.

But secondly RobA took my script and made an equivalent Gimp script fu python thingy out of it and I am pretty sure that those scripts can be called to operate on directories at once. So you need to set up Gimp with python enabled. I don't know if thats python first then Gimp or vice-versa but once you have scriptable Gimp then I think you can add Robs one to the list and it will save you. Hoping that Rob might comment here.

But I am sure we can deliver a solution.

----------


## Notsonoble

Does anyone know if this still works in 2.8.6, I'm getting back into things and can't find the script after reloading it.
Nevermind, restarting gimp a second time made it show up.

----------


## amm17

How can I homogenize only corners brightness? does someone some way with imagemagick or Gimp?

----------


## Azélor

By corner, you mean the place were the repetition of the texture meets? I think the best way would be to add another layer on top and add some bright colours.

----------


## Redrobes

The script I posted includes a blur amount so that you can set how even it needs to be. I am uncertain what the question is beyond this. Maybe post an image of what the initial image looks like and if its not obvious then what you want it to look like.

----------


## johnvanvliet

The Gimp has come a long way in since 2008 

"make seamless" is ,and has been, a default part of the program 

open a image 
go to  " Filters / Map "
and click on "Make Seamless" 
( original image from Post #2 )

this option has been here for many YEARS it is not new 

or 
build the "resynthesizer " plugin ( builds just fine using MinGW on windows) 
http://www.logarithmic.net/pfh/resynthesizer
https://github.com/bootchk/resynthesizer

and this has a opting to make a NEW image that is tileable
 Filter / map / resynthes
and select the option to
 " make horizontally  tileable "
and 
 " make vertically  tileable "
( original image from Post #2 )

using a bigger "Neighborhood size ( 90 default is 30)  "

----------


## Mouse

That's an excellent way to deal with the problem - especially when bespoke texturing tools are so very expensive these days.

Thanks for the tutorial, Redrobes  :Smile:

----------

