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.
Adding blank data after croping
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding blank data after croping
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.
-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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adding blank data after croping
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding blank data after croping
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
try this:
convert rose: -background white -extent 90x90 -crop 30x30 rose_tiled.jpg
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adding blank data after croping
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Adding blank data after croping
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.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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adding blank data after croping
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/