split with overlap

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
robuntu
Posts: 41
Joined: 2012-01-22T10:56:10-07:00
Authentication code: 8675308

split with overlap

Post by robuntu »

Hi forum, (hi anthony, hi fmw42),
I want to split a larg image into rows.

The standard would be (eg: 10.000 pixel into 10x 1000 pixel rows)

Code: Select all

convert large_image.tif -crop 1000x0 +repage +adjoin row_%03d.tif
but I want to have an overlap.

If I use

Code: Select all

convert large_image.tif -crop 10x1@ +repage +adjoin row_%03d.tif
it does the same as above.
So far so good.

I get a 100pixel overlap with

Code: Select all

convert large_image.tif -crop 10x1+100@ +repage +adjoin row_%03d.tif
whith images 1090 pixels wide.
(right, 9 times overlap of 100 pixel results 900 pixel, splitting into 10 rows is 90pixel addition per row)

What I actually want is an overlap crop with absolute pixel numbers as in my first command.
I rather have the last row smaller than the others but set the with with exact pixels.
But when I type

Code: Select all

convert large_image.tif -crop 1000x0+100 +repage +adjoin row_%03d.tif
I get a single one 1000 pixel wide image which is the first row with an offset of 100 pixel.

What I actually want is a set of 10 rows, each 1100 pixels wide with an 100 pixel overlap
and the last row shorter.

Is there a chance to have the offset option without the "@" in the crop command?

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

Re: split with overlap

Post by fmw42 »

I am not aware that -crop supports any kind of overlap. If you are able to do that it may be lucky coincidence or some hidden feature. I had to write my own script to do any overlap cropping. See my bash shell script, overlapcrop, at the link below.

Perhaps Anthony can shed more light on whether overlap cropping is formally supported.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: split with overlap

Post by snibgo »

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: split with overlap

Post by fmw42 »

snibgo wrote:On overlapping crops, see http://www.imagemagick.org/Usage/crop/#crop_equal

Thanks. I had not noticed that before. I guess it is only available when using @ as the offsets mean something else for normal cropping.
robuntu
Posts: 41
Joined: 2012-01-22T10:56:10-07:00
Authentication code: 8675308

Re: split with overlap

Post by robuntu »

@snibgo: That's exactly where I got it from :D

So if there is no "normal" feature for cropping with overlap into fixed pixelsize,
I wrap a pice of code around making sure the image gets enlarged just about that much that
I can do the cropping into equally sized tiles with fixed pixels.

I think I will do a

Code: Select all

-gravity east -splice <pixels>x0
to enlarge the image before cropping.

Can I put these two commands in a "pipe" that I don't have to load the image twice?

Actually I have to do even more steps I could put into that pipe.
I want to splice first, then crop with overlap and than -append a footer to each tile

I can not do this just with

Code: Select all

convert img.tif -gravity east -splice $1x0 -crop $2x1+$3@ -append footer.tif tile_%02d.tif
Do I have to bracket it somehow?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: split with overlap

Post by snibgo »

In general, you can string operations together in one command. Or you can pipe multiple commands together, but I rarely bother with this. Operators (like "-append", "-crop", etc) should be placed after the image(s) they operate on, not before.
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: split with overlap

Post by fmw42 »

You cannot append an image with each of the others. The append will take all the images from the crop and the extra image and append them all together.

I think you have to create all your cropped images. Then loop over each one and do the append. So you need to write a short looping FOR command to append the extra image with each one from the crop.

However you can add a common text label to each one by cropping to stdout and then pipe to stdin in montage and add the text in montage

convert image -splice ... -crop ... miff:- | montage -label 'test' - -tile 1x1 1tmp1_%d.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: split with overlap

Post by anthony »

If you append something on the end you should be able to get the overlaps you are looking for!
But really you are asking for something that is very hard to cater for.

If you do figure it out, please let us know so I can add to the 'overlap cropping' examples. I have 3 styles, so one more for off right edge handling would a good addition.

The 3rd or last (no edge) overlap method would probably be the easiest to work from.
Cropping images, Separating Spaced-out Tiling Images
http://www.imagemagick.org/Usage/crop/#crop_spaced


The other way is to get a clone of the original image, and do your crop with absolute coordinates (no overlap)
now adjust each of the crops (increase size, relative offset adjustment), and then use those adjusted images to extract (compose) from the original image using a "-layers composition", to mask the overlapping areas from the original image. This is rather fancy, and may need a lot of work to get it right.

Remember "-layer composition" is one of the few composition method that understands 'virtual canvas offsets'
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply