PDA

View Full Version : [Award Winner] Tutorial on how to create seamless textures out of anything



Redrobes
01-12-2008, 06:42 PM
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
01-12-2008, 06:43 PM
Stage 1. Chop out the texture bit and try to ensure that the edges are roughly the same brightness.

Redrobes
01-12-2008, 06:46 PM
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
01-12-2008, 06:54 PM
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
01-12-2008, 06:57 PM
Stage 4. Repeat using a new selection in the horizontal direction to cover the horizontal seam.

Redrobes
01-12-2008, 06:59 PM
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
01-12-2008, 07:03 PM
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
01-12-2008, 07:08 PM
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
01-12-2008, 07:29 PM
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
01-13-2008, 03:15 PM
Good Tut, Redrobes - have some REP! I've got to give this technique a try.

Robbie
01-14-2008, 08:45 PM
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
01-15-2008, 02:30 PM
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
01-16-2008, 11:46 AM
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/showthread.php?p=5842#post5842

-Rob A>

su_liam
01-16-2008, 01:58 PM
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
01-16-2008, 07:37 PM
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
01-16-2008, 09:04 PM
I had posted more detailed steps on the manual method previously here:
http://www.cartographersguild.com/showthread.php?p=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
7. adjust levels (if desired)

Try it to see how it works. Depending on the blur radius, the effect will vary.

-Rob A>

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
01-17-2008, 08:19 AM
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
01-17-2008, 01:07 PM
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
01-17-2008, 01:19 PM
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 :(

-Rob A>

Redrobes
01-17-2008, 01:53 PM
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
01-17-2008, 08:27 PM
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
01-18-2008, 11:28 AM
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 :(

-Rob A>

Redrobes
05-24-2008, 07:59 AM
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
05-24-2008, 08:00 AM
and a few more...

Airith
07-15-2008, 05:24 PM
*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 :)) 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 :P :(

Redrobes
07-15-2008, 06:24 PM
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
10-16-2008, 01:09 PM
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 (http://www.cgtextures.com/texview.php?id=16049&PHPSESSID=a2e1b9c66805621fbf485353984c6320)
7126

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

Run through the filter to make a seamless tile:
7128

And a sample of it tiled (1000x1000):
7129

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

-Rob A>

RobA
10-16-2008, 01:12 PM
Just to compare, here is the default GIMP make seamless result on the same cut out bit:
7131

-Rob A>

Steel General
10-16-2008, 01:19 PM
I dub the newly repped *bonk*

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

Redrobes
10-17-2008, 08:01 AM
Cool ! I reckon the new RR filter is better than theirs ! In name and result ;)

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
10-24-2008, 01:49 PM
As epr the request in the other thread I have updated the script attached in post#27 (http://www.cartographersguild.com/showpost.php?p=35119&postcount=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
03-21-2009, 09:39 PM
Old thread bump..

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

Looks very good.

-Rob A>

Ascension
03-22-2009, 12:11 AM
Never heard of it til now...looks like it does a great job.

ravells
03-22-2009, 06:36 AM
Old thread bump..

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

Looks very good.

-Rob A>

Ohhh but $99 - not cheap...

Ghostman
11-04-2009, 01:05 PM
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 :|

Redrobes
11-04-2009, 01:29 PM
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
01-09-2014, 11:43 AM
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.