Page 1 of 1

Most direct way to resize with tiled/wrapped edges?

Posted: 2014-01-23T17:18:16-07:00
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?

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

Posted: 2014-01-23T17:25:22-07:00
by snibgo
This sounds like "-virtual-pixel tile", which is the default. See http://www.imagemagick.org/script/comma ... #clip-path

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

Posted: 2014-01-23T17:39:31-07:00
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.

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

Posted: 2014-01-23T17:43:36-07:00
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?

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

Posted: 2014-01-23T18:09:16-07:00
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

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

Posted: 2014-01-23T19:36:26-07:00
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.

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

Posted: 2014-01-23T20:12:40-07:00
by CranberryBBQ
Oh, excellent! That's a good bit more convenient than the two-pass montage -> resize + crop solution. Thanks!

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

Posted: 2014-01-23T21:04:45-07:00
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.

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

Posted: 2014-01-23T21:11:31-07:00
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