Create seamless texture

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
User avatar
shveicar
Posts: 42
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Create seamless texture

Post by shveicar »

Hello.
Is there a method in ImageMagick to create a seamless texture, which after combining will be one whole picture?
for example I have this original image:

Image

After applying the seamless image creation method in GIMP https://www.gameartguppy.com/tutorial-h ... e-in-gimp/
I get this result:

Image

Which in the future can always be used to create a composite image of a given size. Like this:

Image

I would like to use the method of converting the original image to a seamless one without using GIMP's windowed interface, but I hope that ImageMagick also has ways to do this.

P.s I'm using Windows with (imagick Version: 7.0.7.15).
Windows, ImageMagick 7.0.8 version

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create seamless texture

Post by snibgo »

The Gimp scheme seems to be masked (ie blended) composites of the original with four copies, offset so the centre of the original is replicated at each corner. Windows BAT syntax:

Code: Select all

set SRC=b9a5004b4324a41a77bcc6649f1e7312.png

magick ^
  %SRC% +write mpr:INP ^
  mpr:INP ^
  ( +clone ^
    -sparse-color bilinear 0,0,White,%%[fx:w/2],%%[fx:h/2],Black ^
    -function sinusoid 0.5,-90,0.5,0.5 ^
    +write mpr:MSK ^
  ) ^
  -geometry -%%[fx:w/2]-%%[fx:h/2] -composite ^
  mpr:INP ^
  ( mpr:MSK -rotate 90 ) ^
  -geometry +%%[fx:w/2]-%%[fx:h/2] -composite ^
  mpr:INP ^
  ( mpr:MSK -rotate 180 ) ^
  -geometry +%%[fx:w/2]+%%[fx:h/2] -composite ^
  mpr:INP ^
  ( mpr:MSK -rotate 270 ) ^
  -geometry -%%[fx:w/2]+%%[fx:h/2] -composite ^
  bluetile.png
Image

Test the tile:

Code: Select all

%IMG7%magick ^
  -size 600x400 xc: ^
  -tile bluetile.png -draw "color 0,0 reset" ^
  blue_tiled.png
Image
There are other methods, besides blending, for creating seamless tiles.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create seamless texture

Post by snibgo »

We get the same result, but faster, by using roll:

Code: Select all

magick ^
  %SRC% ^
  ( +clone -roll +%%[fx:w/2]+%%[fx:h/2] +write r.png ) ^
  ( +clone ^
    -sparse-color bilinear 0,0,White,%%[fx:w/2],%%[fx:h/2],Black ^
    -function sinusoid 0.5,-90,0.5,0.5 ^
    ( +clone -rotate 90 ) ^
    ( +clone -rotate 90 ) ^
    ( +clone -rotate 90 ) ^
    -background None ^
    -compose Lighten -layers flatten ^
  ) ^
  -alpha off ^
  -compose Over -composite ^
  bluetile2.png
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create seamless texture

Post by fmw42 »

Neat!

User avatar
shveicar
Posts: 42
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Re: Create seamless texture

Post by shveicar »

snibgo, fmw42
Thanks.
I'm trying to split this long command and see why it doesn't work for me. Maybe this [fx:w/2] and [fx:h/2] functions may not work..
I use the Autoit script and Portable version of ImageMagick so it's important for me to see how all parts of the command work directly through the console.
Prompt that I could understand better, this command:

Code: Select all

convert b9a5004b4324a41a77bcc6649f1e7312.png -roll +%%[fx:w/2]+%%[fx:h/2] fin.png
and this command:

Code: Select all

convert b9a5004b4324a41a77bcc6649f1e7312.png -roll +%%127+%%127 fin.png
should produce the same results? If we assume that the original image has size 254x254.
Windows, ImageMagick 7.0.8 version

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create seamless texture

Post by fmw42 »

The inline computations for -roll +%%[fx:w/2]+%%[fx:h/2] in your first command do not work in IM 6 with convert, only in IM 7 with magick.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create seamless texture

Post by snibgo »

shveicar wrote:... how all parts of the command work directly through the console.
A Windows console? Then don't double the percent signs %.
shveicar wrote:convert b9a5004b4324a41a77bcc6649f1e7312.png -roll +%%127+%%127 fin.png
Remove the percent signs entirely.

As Fred says, %[fx:...] in "-roll" needs v7 "magick".
snibgo's IM pages: im.snibgo.com

User avatar
shveicar
Posts: 42
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Re: Create seamless texture

Post by shveicar »

I downloaded the latest version of ImageMagick-7.0.8-68-portable-Q16-x86.zip
but there I see error 2625 when calling

Image

This may be due to a lack of any elements or discrepancies in the builds for Linux and Windows..
But if these functions just transform the dimensions for width and height, then this is not a problem. I can calculate these values through a third-party utility and insert them at runtime. I'll try.


Perfectly. I managed to get the same result as and you with this command and using an older version of ImageMagick.

Code: Select all

convert.exe b9a5004b4324a41a77bcc6649f1e7312.png ( +clone -roll +127+127 ) ( +clone -sparse-color bilinear 0,0,White,127,127,Black -function sinusoid 0.5,-90,0.5,0.5 ( +clone -rotate 90 ) ( +clone -rotate 90 ) ( +clone -rotate 90 ) -background None -compose Lighten -layers flatten ) -alpha off -compose Over -composite test.png
Now I see how it will work in my script.
Windows, ImageMagick 7.0.8 version

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create seamless texture

Post by snibgo »

Fred and I have both told you it works only with "magick". It doesn't work with "convert".
snibgo's IM pages: im.snibgo.com

User avatar
shveicar
Posts: 42
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Re: Create seamless texture

Post by shveicar »

snibgo Oh, I'm sorry, I didn't know there was such a big difference.
with magick it started to work :)
snibgo wrote:
2019-10-23T10:49:55-07:00
There are other methods, besides blending, for creating seamless tiles.
And what other alternative ways for get anothe seamless texture can be used?
Windows, ImageMagick 7.0.8 version

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create seamless texture

Post by fmw42 »

See my bash unix shell script tiler at my link below for examples. Only works on Windows 10 unix or with Cygwin. But here is the method. Works best on random-like textures.
Swap diagonal quadrants, exending the borders to get overlap and then composite blending the extended quadrants.

Werty
Posts: 69
Joined: 2010-08-06T05:37:36-07:00
Authentication code: 8675308

Re: Create seamless texture

Post by Werty »

Also for more info on tiling check out the imagemagick examples canvas creation about tiled images.
https://imagemagick.org/Usage/canvas/#tile

Not exactly what you need here but a good read anyways.
Windows 10 user

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Create seamless texture

Post by GeeMack »

shveicar wrote:
2019-10-23T14:39:53-07:00
And what other alternative ways for get anothe seamless texture can be used?
Here is a method that also uses a gradient mask like snibgo's examples above. It should work pretty well with input images that are square and have no transparency.

Code: Select all

magick square.png -gravity center ^
   ( -clone 0,0 +append +duplicate -append -extent 50% +repage ) ^
   ( -clone 0 -colorize 100 -resize 75% -rotate 45 -blur 0x20 ) ^
   -alpha off -composite tile.png
Inside the first parentheses it makes a 2x2 tiled grid of the input image, then crops a square from the center the size of the input. Inside the second parentheses it makes a grayscale gradient mask.

The default action of "-composite" is to use a third image as a mask, so here we've composited the input image, the tiled square, and the mask. That creates a tile that can be duplicated and appended to assemble a seamless finished output.

This should work just the same with IM v6 by changing "magick" to "convert".

To use in a Windows BAT script double the percent signs "%%"

User avatar
shveicar
Posts: 42
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Re: Create seamless texture

Post by shveicar »

Yes, it works well.
Thanks GeeMack
Windows, ImageMagick 7.0.8 version

Locked