Page 1 of 1

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

Posted: 2019-02-21T09:14:55-07:00
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

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

Posted: 2019-02-21T09:48:10-07:00
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

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

Posted: 2019-02-21T09:50:51-07:00
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.