Frame counter on sequences that don't start at frame 1
Frame counter on sequences that don't start at frame 1
Hey there,
Trying to add a frame counter to a sequence of image files. It seems I can use -annotate %[scene] for this purpose for most sequences.
Unfortunately, the sequence also needs to be offset and when I add -scene the annotation gets screwed up.
Our architecture requirements impose the limitation that I probably need to do this in a single call (unless there is a way to modify the files in place with subsequent calls)
So this works because the resulting frames start at 1...
convert infile-%04d.tif[1-3] -annotate 0 "frame# %[scene]" outfile-%04d.tif
This fails because I try and offset the frame range...
convert infile-%04d.tif[1-3] -annotate 0 "frame# %[scene]" -scene 4 outfile-%04d.tif
Any suggestions?
Trying to add a frame counter to a sequence of image files. It seems I can use -annotate %[scene] for this purpose for most sequences.
Unfortunately, the sequence also needs to be offset and when I add -scene the annotation gets screwed up.
Our architecture requirements impose the limitation that I probably need to do this in a single call (unless there is a way to modify the files in place with subsequent calls)
So this works because the resulting frames start at 1...
convert infile-%04d.tif[1-3] -annotate 0 "frame# %[scene]" outfile-%04d.tif
This fails because I try and offset the frame range...
convert infile-%04d.tif[1-3] -annotate 0 "frame# %[scene]" -scene 4 outfile-%04d.tif
Any suggestions?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Frame counter on sequences that don't start at frame 1
Make a loop. For each image, find its scene number, offset it as new variable, then use that variable in -annotate.
Re: Frame counter on sequences that don't start at frame 1
ok so the best that I can tell, it looks like -scene destroys some per frame data.
I've tried to handle this by renumbering the images before I have to process them, so that I don't need to use the -scene option to do this.
convert infile-%04d.tif[4-8] -annotate 0 "frame# %[scene]" outfile-%04d.tif
This only seems to work on *some* images. That is, occasionally I have a sequence of image files that run from [4-8] as input, and the resulting output of the above statement is the creation of files with the same numbering [4-8]. *Other* image sequences that are the same format and also run from [4-8] result in output where the frame numbering is renumbered [0-4].
Why do some files get re-numbered and others do not? How can I tell if a sequence would be re-numbered or not?
I've tried to handle this by renumbering the images before I have to process them, so that I don't need to use the -scene option to do this.
convert infile-%04d.tif[4-8] -annotate 0 "frame# %[scene]" outfile-%04d.tif
This only seems to work on *some* images. That is, occasionally I have a sequence of image files that run from [4-8] as input, and the resulting output of the above statement is the creation of files with the same numbering [4-8]. *Other* image sequences that are the same format and also run from [4-8] result in output where the frame numbering is renumbered [0-4].
Why do some files get re-numbered and others do not? How can I tell if a sequence would be re-numbered or not?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Frame counter on sequences that don't start at frame 1
I would always expect the former behavior that the annotation and numbering of the outputs would always correspond to the frame number of the input.
If I do:
convert rose: rose: rose: rose: rose: rose: rose: rose: rose.tif
convert rose.tif[3-6] -fill white -pointsize 24 -gravity center -annotate 0 "%[scene]" +adjoin rose3-6_%d.tif
I get images:
rose3-6_3.tif
rose3-6_4.tif
rose3-6_5.tif
rose3-6_6.tif
each has the numbers 3 through 6 correspondingly in the center of the image.
Is it possible that your input tif has more frames than you think.
Try posting a link to one of your input images for which you do not get this behavior.
If I do:
convert rose: rose: rose: rose: rose: rose: rose: rose: rose.tif
convert rose.tif[3-6] -fill white -pointsize 24 -gravity center -annotate 0 "%[scene]" +adjoin rose3-6_%d.tif
I get images:
rose3-6_3.tif
rose3-6_4.tif
rose3-6_5.tif
rose3-6_6.tif
each has the numbers 3 through 6 correspondingly in the center of the image.
Is it possible that your input tif has more frames than you think.
Try posting a link to one of your input images for which you do not get this behavior.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Frame counter on sequences that don't start at frame 1
See my answer in the bug report...
viewtopic.php?f=3&t=16829#p62265
viewtopic.php?f=3&t=16829#p62265
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Frame counter on sequences that don't start at frame 1
You can reproduce my current problem by doing the following:
1. Take any sequence of images that doesn't start at frame 0. (I'm using a test.0004.tif thru test.0008.tif )
2. Run imageMagick on them, the type of processing doesn't seem to matter. Here I'm changing the size of the image:
.\ImageMagick-6.5.9-Q16\convert ./Src/test.%04d.tif[4-8] +adjoin -gravity center -background rgb(0,0,0) -extent 960x720 ./Step1/test.%04d.tif
So far so good...we get ./Step1/test.0004.tif thru test.0008.tif. The frame range has not been changed.
3. Run imageMagick on the newly created frames. I'm running the same process, but I have tried others:
.\ImageMagick-6.5.9-Q16\convert ./Step1/test.%04d.tif[4-8] +adjoin -gravity center -background rgb(0,0,0) -extent 960x720 ./Step2/test.%04d.tif
Now the resulting frames are numbered [0-4]!
That is the issue I would like to understand. Previously I was adding -scene to my commands to ensure that it always started at the correct frame. But when I use that command the resulting %[scene] are incorrect, so that's not really an option to resolve this.
Thanks
1. Take any sequence of images that doesn't start at frame 0. (I'm using a test.0004.tif thru test.0008.tif )
2. Run imageMagick on them, the type of processing doesn't seem to matter. Here I'm changing the size of the image:
.\ImageMagick-6.5.9-Q16\convert ./Src/test.%04d.tif[4-8] +adjoin -gravity center -background rgb(0,0,0) -extent 960x720 ./Step1/test.%04d.tif
So far so good...we get ./Step1/test.0004.tif thru test.0008.tif. The frame range has not been changed.
3. Run imageMagick on the newly created frames. I'm running the same process, but I have tried others:
.\ImageMagick-6.5.9-Q16\convert ./Step1/test.%04d.tif[4-8] +adjoin -gravity center -background rgb(0,0,0) -extent 960x720 ./Step2/test.%04d.tif
Now the resulting frames are numbered [0-4]!
That is the issue I would like to understand. Previously I was adding -scene to my commands to ensure that it always started at the correct frame. But when I use that command the resulting %[scene] are incorrect, so that's not really an option to resolve this.
Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Frame counter on sequences that don't start at frame 1
Please clarify. These are separate images not separate frames. Each image could have its own set of frames or could be just one frame.1. Take any sequence of images that doesn't start at frame 0. (I'm using a test.0004.tif thru test.0008.tif )
For example:
convert rose: rose: rose: rose: rose: rose: rose: rose: rose8.tif
identify rose8.tif
rose8.tif[0] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.019
rose8.tif[1] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[2] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[3] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[4] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[5] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[6] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
rose8.tif[7] TIFF 70x46 70x46+0+0 8-bit DirectClass 80KB 0.000u 0:00.010
convert rose8.tif[3-6] -gravity center -background black -extent 100x100 rose8b_%d.tif
produces
rose8b_3.tif
rose8b_4.tif
rose8b_5.tif
rose8b_6.tif
What is wrong with that?
If you are trying to process multiple images to multiple outputs (via wildcards), you cannot do that with convert. You can use mogrify to process a directory of images to one output per image in the directory.
Re: Frame counter on sequences that don't start at frame 1
Thanks for the reply.
I'll take your suggestion and look into mogrify, see if I can get it to do this.
My tests are separate images and separate frames. That is, 1 frame per image. The confusion here may be that I am using .tif as an example. This effect is reproducible with other image formats as well (png, jpg, bmp)Please clarify. These are separate images not separate frames. Each image could have its own set of frames or could be just one frame.
Seemingly nothing. But that's not what I'm doing.What is wrong with that?
Isn't that what +adjoin does? I guess the part that confuses me is that it does work, provided I don't use images that were previously processed by ImageMagick. Using convert to create multiple images to multiple outputs works once, any attempt to use these generated files produces output that is renumbered.If you are trying to process multiple images to multiple outputs (via wildcards), you cannot do that with convert.
I'll take your suggestion and look into mogrify, see if I can get it to do this.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Frame counter on sequences that don't start at frame 1
Perhaps I misunderstand about your filenames test_%04d.tif[4-8]? Are these wild card sequences of one multiple images with multiple frames or is that just one image with multiple frames?
If the former, multiple images with multiple frames, then you are trying to get outputs from each image and separate the frames?
+adjoin only separates the frames of a given image into individual images rather than writing it as a single image with multiple frames.
I guess I am still confused about what you are trying to do. So until I understand better, perhaps my suggestion of mogrify may be premature.
I was not aware that one could do in convert the following:
convert image1 image2 image3... some processing result1 result2 result3...
Whether they had multiple frames or not.
For examples:
convert rose: rose: rose: -flip rose1.png rose2.png rose3.png
will not process at all. One gets error messages. You can use wild cards for input, so long as you have only one output (with multiple frames). see http://www.imagemagick.org/script/comma ... .php#input. But you cannot process multiple images to multiple outputs.
Using wildcards for input is the same as having multiple input images.
So can you clarify further with a simpler example?
If the former, multiple images with multiple frames, then you are trying to get outputs from each image and separate the frames?
+adjoin only separates the frames of a given image into individual images rather than writing it as a single image with multiple frames.
I guess I am still confused about what you are trying to do. So until I understand better, perhaps my suggestion of mogrify may be premature.
I was not aware that one could do in convert the following:
convert image1 image2 image3... some processing result1 result2 result3...
Whether they had multiple frames or not.
For examples:
convert rose: rose: rose: -flip rose1.png rose2.png rose3.png
will not process at all. One gets error messages. You can use wild cards for input, so long as you have only one output (with multiple frames). see http://www.imagemagick.org/script/comma ... .php#input. But you cannot process multiple images to multiple outputs.
Using wildcards for input is the same as having multiple input images.
So can you clarify further with a simpler example?
Last edited by fmw42 on 2010-08-12T14:50:08-07:00, edited 1 time in total.
Re: Frame counter on sequences that don't start at frame 1
I have the following files...
Each file is a single image.
I run the following command...
I now have the following generated files....
Each file is again a single image.
I run the exact same command on the new files.
I now have the following...
I'd like to know why these images only get renamed the second time I run convert.
Code: Select all
C:/Src/test.0004.tif
C:/Src/test.0005.tif
C:/Src/test.0006.tif
C:/Src/test.0007.tif
C:/Src/test.0008.tif
I run the following command...
Code: Select all
convert C:/Src/test.%04d.tif[4-8] C:/Step1/test.%04d.tif
Code: Select all
C:/Step1/test.0004.tif
C:/Step1/test.0005.tif
C:/Step1/test.0006.tif
C:/Step1/test.0007.tif
C:/Step1/test.0008.tif
I run the exact same command on the new files.
Code: Select all
convert C:/Step1/test.%04d.tif[4-8] C:/Step2/test.%04d.tif
Code: Select all
C:/Step2/test.0000.tif
C:/Step2/test.0001.tif
C:/Step2/test.0002.tif
C:/Step2/test.0003.tif
C:/Step2/test.0004.tif
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Frame counter on sequences that don't start at frame 1
On IM 6.6.3.4 Q16 Mac OSX Tiger:
convert rose: rose_01.tif
convert rose: rose_02.tif
convert rose: rose_03.tif
convert rose: rose_04.tif
convert rose: rose_05.tif
convert rose: rose_06.tif
convert rose_%02d.tif[3-5] rose2_%02d.tif
produces
rose2_00.tif
rose2_01.tif
rose2_02.tif
But
convert rose_%02d.tif[3-5] -scene 3 rose2_%02d.tif
produces
rose2_03.tif
rose2_04.tif
rose2_05.tif
convert rose2_%02d.tif[3-5] rose3_%02d.tif
produces
rose3_00.tif
rose3_01.tif
rose3_02.tif
and
convert rose2_%02d.tif[3-5] -scene 3 rose3_%02d.tif
produces
rose3_03.tif
rose3_04.tif
rose3_05.tif
see http://www.imagemagick.org/Usage/files/#scene
I think your problem is that IM will write starting at 0 if no -scene is specified. When you leave -scene off, it starts with 0 because your second set does not have any images numbered 0000, 0001, 0002, 00003
I think the numbering corresponds to the sequence number of the images in the command line (always starting with 0) and not the numbers in the names of the files.
convert rose: rose_01.tif
convert rose: rose_02.tif
convert rose: rose_03.tif
convert rose: rose_04.tif
convert rose: rose_05.tif
convert rose: rose_06.tif
convert rose_%02d.tif[3-5] rose2_%02d.tif
produces
rose2_00.tif
rose2_01.tif
rose2_02.tif
But
convert rose_%02d.tif[3-5] -scene 3 rose2_%02d.tif
produces
rose2_03.tif
rose2_04.tif
rose2_05.tif
convert rose2_%02d.tif[3-5] rose3_%02d.tif
produces
rose3_00.tif
rose3_01.tif
rose3_02.tif
and
convert rose2_%02d.tif[3-5] -scene 3 rose3_%02d.tif
produces
rose3_03.tif
rose3_04.tif
rose3_05.tif
see http://www.imagemagick.org/Usage/files/#scene
I think your problem is that IM will write starting at 0 if no -scene is specified. When you leave -scene off, it starts with 0 because your second set does not have any images numbered 0000, 0001, 0002, 00003
I think the numbering corresponds to the sequence number of the images in the command line (always starting with 0) and not the numbers in the names of the files.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Frame counter on sequences that don't start at frame 1
What is needed is a proper definition of %[scene] %s and %n and any other escapes that may be added,
as well as have it work properly for multi-image reads, and for looped single image operations.
For example you may want to reference the original scene number, but have a different output scene number, which is also different to the images current 'index' for its in memory position.
NOTE you may not have set a 'output scene number' (typically by using -scene) in which case it should default to ... WHAT? typically that should be the current index number at the time of write, as most images would have a input scene number of '0'. It also prevents posible duplicate output scene numbers.
So the bug as I see it is that
as well as have it work properly for multi-image reads, and for looped single image operations.
- For example percent escapes could specify....
- the scene number READ FROM a multi-image file (related to filename and should be hard to change)
- the scene for OUTPUT image
- the image index number in the current image list
For example you may want to reference the original scene number, but have a different output scene number, which is also different to the images current 'index' for its in memory position.
NOTE you may not have set a 'output scene number' (typically by using -scene) in which case it should default to ... WHAT? typically that should be the current index number at the time of write, as most images would have a input scene number of '0'. It also prevents posible duplicate output scene numbers.
So the bug as I see it is that
- the first two are current represents %[scene]. They probably should be separated!
- often %[scene] is getting trashed by the current image index number
- loop over list image operations are not giving a correct 'index' number or even a correct 'scene' number
This is especially important for things like -set and -annotate. - What the output scene number should be is unclear.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/