Page 1 of 1

Adding blank data after croping

Posted: 2011-02-20T18:55:56-07:00
by ddayan
I'm splitting an image into 256x256 tiles, the boundary tiles are smaller than 256*256, I wonder what would be the fastest (least resources use) do add blank(white) data to a cropped image (in order to make it 256x256)?

I tried to add a border, but adding it to the original image takes too long and a lot of memory. Adding the border to the tile adds a border on both directions, so the size is greater than 256x256. I can crop the larger tile again but I was wondering if there's a better way to do this.

Thanks to all helpers.

Re: Adding blank data after croping

Posted: 2011-02-20T19:16:57-07:00
by fmw42
you can use

-gravity ... -background white -extent 256x256

or

-background white -splice ...

but -extent is easier as you can simply tell it how big to make the image. -splice needs to know how much to add to one or more sides.

see

http://www.imagemagick.org/Usage/crop/#extent
http://www.imagemagick.org/Usage/crop/#splice


Don't know about speed issues.

You may also want to see the -crop options at http://www.imagemagick.org/Usage/crop/#crop for example for more even cropping of tiles.

Re: Adding blank data after croping

Posted: 2011-02-20T23:35:21-07:00
by anthony
Is your 'thinner' boundary equal on all sides? I gather that is the case as you were trying to use border.

In that case assign a vitual offset (that is just an assignment so practically zero time) to the whole image of the boundary size.

See.... Centered Tile Cropping
http://www.imagemagick.org/Usage/crop/# ... e_centered

Afterward you can use other techniques to 'fill out the borders' on individual border images.

If you want to limit your 'filling' to just the border tiles you can name your tile images using the technique shown in the example immediately before that centered tile crop.

That way you know by the tile filenames which images are 'border' images, and how they should be 'fixed'.
There are also shell scripts such as my "mv_renum" script, that can fill out the filename numbers with leading zeros, so the tiles 'sort' alphabetically properly.

Let us know how you go.

Re: Adding blank data after croping

Posted: 2011-02-21T11:41:26-07:00
by fmw42
why don't you use -extent to extend the size of the input image to a multiple of the tile size, then do -crop. that way each tile will be padded as needed at the end.

try this:


convert rose: -background white -extent 90x90 -crop 30x30 rose_tiled.jpg

Re: Adding blank data after croping

Posted: 2011-02-21T18:10:28-07:00
by anthony
Using extent will fail with large images, just as border will.

At one point you end up with three large images in memory! The original, the new canvas, and the resulting composition.

Better to try and crop the image first, then extent or fill out the individule pieces. as then you only generate extra images for each of the smaller tiles, one tile at a time.

NOTE: crop will still need at least double the memory needs. You may need to use stream to extract smaller crops to work with first. You don't need to use stream to crop to the final size. A larger multiple of the final crop can be extracted first.

Re: Adding blank data after croping

Posted: 2011-02-23T12:59:28-07:00
by ddayan
anthony wrote:Using extent will fail with large images, just as border will.

At one point you end up with three large images in memory! The original, the new canvas, and the resulting composition.

Better to try and crop the image first, then extent or fill out the individule pieces. as then you only generate extra images for each of the smaller tiles, one tile at a time.

NOTE: crop will still need at least double the memory needs. You may need to use stream to extract smaller crops to work with first. You don't need to use stream to crop to the final size. A larger multiple of the final crop can be extracted first.
I can't understand how to use stream, I read the documentation but I still can't produce tiles using the stream command. I would be grateful if you could help me with an example.

Re: Adding blank data after croping

Posted: 2011-02-23T19:25:06-07:00
by anthony
My understanding is stream will not produce tiles, but it will crop out a area from the larger image.
You can use stream to crop out a few large (but more manageable) areas from the original image, then use normal IM to convert those into tiles.

NOTE I have never used it myself, only made notes about it in
http://www.imagemagick.org/Usage/files/#massive

Feedback and updates are most welcome.