crop image-lines (1px) from one image and montage/append them to new images

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
neffets
Posts: 1
Joined: 2019-02-21T08:48:52-07:00
Authentication code: 1152

crop image-lines (1px) from one image and montage/append them to new images

Post by neffets »

I am using ImageMagick 7.0.3-5 Q16 x64 with Batch-File/Commad-Line

I would be very grateful for any help on this "appending issue". The thing is that my current solutiuon has a very poor performance - it should be possible to process this much faster.

I have a list of source TIF-images (more than 2000), width x height=4000 x 2000 px.

I would like to take the first source TIF slice it into its single lines (4000 x 1 px) and append the result to 2000 target TIF.

image0001 slice into its 2000 single lines and append all lines to target TIF 1-2000 (line 1 to 0001.tif, line 2 to 0002.tif, ... line 2000 to 2000.tif)
image0002 slice into its 2000 single lines and append all lines to target TIF 1-2000 (line 1 to the same target file as previously 0001.tif, line 2 to 0002.tif, ... line 2000 to 2000.tif)
image0002 slice into its 2000 single lines and append all lines to target TIF 1-2000 (line 1 to the same target file as previously 0001.tif, line 2 to 0002.tif, ... line 2000 to 2000.tif)

What I would like to have is something like
load image0001 into memory and then append all the lines of this image into the 2000 target TIFs
load image0002 into memory and then append all the lines of this image into the same 2000 target TIFs


What I did so far is
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0000.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0001.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0002.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0003.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0004.tif
...
magick montage image0001.tif -crop 4000x1+0+2000 -tile x4000 -geometry +0+0 all-slits/2000.tif
...
magick montage image2000.tif -crop 4000x1+0+2000 -tile x4000 -geometry +0+0 all-slits/2000.tif

The problem is that this way each source image is loaded into memory 2000 times, although "read once and append all lines of the current file to the target files" would be much faster.

I tried this and that, without succes. Anybody an idea. Thank you very much
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: crop image-lines (1px) from one image and montage/append them to new images

Post by fmw42 »

I am not sure I understand your problem. Perhaps a diagram might help. It would appear that one way or the other, you will have to load 2000 images into memory to do what you want efficiently.

Nevertheless, rather than using magick montage, you can just use magick image0001.tif -crop 4000x1 ... to do tiled cropping into 4000 single line images. See https://imagemagick.org/Usage/crop/#crop_tile
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: crop image-lines (1px) from one image and montage/append them to new images

Post by snibgo »

neffets wrote:What I did so far is
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0000.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0001.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0002.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0003.tif
magick montage image0001.tif -crop 4000x1+0+0 -tile x4000 -geometry +0+0 all-slits/0004.tif
...
You create a bunch of identical output files. Make just one, then copy it. Or use "-write XXX" as many times as you want.
snibgo's IM pages: im.snibgo.com
Post Reply