Most direct way to resize with tiled/wrapped edges?

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?".
Post Reply
CranberryBBQ
Posts: 12
Joined: 2014-01-23T17:11:13-07:00
Authentication code: 6789

Most direct way to resize with tiled/wrapped edges?

Post by CranberryBBQ »

I'm wanting to resize some seamlessly tileable images in such a way that the results are also seamlessly tileable. The resize filter therefore needs to sample pixels beyond the image border in a wrapped/repeated/tiled fashion in order to prevent artifacts.

I imagine a montage -> resize -> crop sequence will do what I want, but is there any more direct/simple/efficient method?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Most direct way to resize with tiled/wrapped edges?

Post by snibgo »

This sounds like "-virtual-pixel tile", which is the default. See http://www.imagemagick.org/script/comma ... #clip-path
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Most direct way to resize with tiled/wrapped edges?

Post by fmw42 »

I was under the impression that the default for -virtual-pixel is edge. At least that is what is says below the table at http://www.imagemagick.org/script/comma ... tual-pixel. So there is some confusion here because the table says tile is the default.

If you do

convert rose: -distort srt 45 show:
convert rose: -virtual-pixel tile -distort srt 45 show:
convert rose: -virtual-pixel edge -distort srt 45 show:

The first and third match, so it would appear that edge is the default.

I am not sure what was meant by (default) next to tile. Perhaps it was a typo.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Most direct way to resize with tiled/wrapped edges?

Post by fmw42 »

PS I do not see what -virtual-pixel tile will have to do with resize.

I think you need to use the viewport setting with -distort srt to get what you want by setting the viewport size (and offset) to be bigger than the srt scaled sized

See
http://www.imagemagick.org/Usage/distor ... t_viewport
http://www.imagemagick.org/Usage/distorts/#srt

Perhaps you can show us what exactly you are trying to do?
CranberryBBQ
Posts: 12
Joined: 2014-01-23T17:11:13-07:00
Authentication code: 6789

Re: Most direct way to resize with tiled/wrapped edges?

Post by CranberryBBQ »

Thanks for the help, guys. -virtual-pixel tile sounds like what I want, but it doesn't seem to be working with resize. It might work with distort, but at the moment I'm specifically hoping to work with an orthogonal truncated sinc filter.

To give an example of what I want, consider this source image:
Image

convert Source.png -virtual-pixel tile -filter Sinc -resize 16 Bad_Borders_Resize.png results in this, because the downsampling filter is either omitting samples outside the image or replacing them with the edge pixel (probably the former?):
Image
Blown up with nearest neighbor:
Image

I would like something more like this, which is the result of tiling the image 3x3 in Gimp, resizing to 48 in ImageMagick, and cropping to the middle tile:
Image
i.e.:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Most direct way to resize with tiled/wrapped edges?

Post by fmw42 »

try this (unix syntax on relatively current IM) (if older IM you need to use clones rather than -duplicate)


convert Source.png -duplicate 2 +append -duplicate 2 -append \
-virtual-pixel tile -filter Sinc -resize 48x48 \
-gravity center -crop 33.33x33.33+0+0% +repage \
-filter point -resize 128x128 result.png

or

convert Source.png -duplicate 2 +append -duplicate 2 -append \
-virtual-pixel tile -filter Sinc -resize 48x48 \
-gravity center -crop 16x16+0+0 +repage \
-filter point -resize 128x128 result.png

Leave off the last line if you do not want the final resize for viewing.
CranberryBBQ
Posts: 12
Joined: 2014-01-23T17:11:13-07:00
Authentication code: 6789

Re: Most direct way to resize with tiled/wrapped edges?

Post by CranberryBBQ »

Oh, excellent! That's a good bit more convenient than the two-pass montage -> resize + crop solution. Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Most direct way to resize with tiled/wrapped edges?

Post by fmw42 »

CranberryBBQ wrote:Oh, excellent! That's a good bit more convenient than the two-pass montage -> resize + crop solution. Thanks!
Not much different from montage. With montage, you could tile the image and pipe the result to convert to do the resize.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Most direct way to resize with tiled/wrapped edges?

Post by fmw42 »

Here is another method, but you need to know the input size times 3


convert -size 540x540 tile:Source.png \
-virtual-pixel tile -filter Sinc -resize 48x48 \
-gravity center -crop 16x16+0+0 +repage \
-filter point -resize 128x128 result.png

see
http://www.imagemagick.org/Usage/canvas/#tile
Post Reply