Page 1 of 1

possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T17:30:45-07:00
by fmw42
IM 6.6.2.0 Q16 Mac OSX Tiger.

I am puzzled. If I do this, I get a strange result with png input to montage

convert -font arial -pointsize 25 label:'line 1' tmp1.png
Image
convert -font arial -pointsize 12 label:'line2' tmp2.png
Image
montage tmp1.png tmp2.png -tile 1x -geometry +0+5 test01.png
Image

But using gif input to montage, I get what I expect for the result:

convert -font arial -pointsize 25 label:'line 1' tmp1.gif
Image
convert -font arial -pointsize 12 label:'line2' tmp2.gif
Image
montage tmp1.gif tmp2.gif -tile 1x -geometry +0+5 test02.png
Image

What am I misunderstanding here or is this a bug?

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T18:10:59-07:00
by magick
The PNG image includes a label. Use -label "" in your montage command line to remove the label.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T18:20:40-07:00
by fmw42
Thanks. I see the label now in the verbose info for tmp1.png and I re-read the montage docs to see that it uses any label in the image. I never knew that using label:"something" would also put the label in the label field of the resulting image file. Learned something new today. Thanks again.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T18:57:03-07:00
by fmw42
testing -label "" does not seem to help

convert -font arial -pointsize 25 label:'line 1' -label "" tmp1.png
convert -font arial -pointsize 12 label:'line2' -label "" tmp2.png
montage tmp1.png tmp2.png -label "" -tile 1x -geometry +0+5 test01.png

I get the same bad result as in my first post above. Nor is the label removed from the verbose info in tmp1.png and tmp2.png

Image


Am I doing this incorrectly?

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T19:46:44-07:00
by anthony
fmw42 wrote:Thanks. I see the label now in the verbose info for tmp1.png and I re-read the montage docs to see that it uses any label in the image. I never knew that using label:"something" would also put the label in the label field of the resulting image file. Learned something new today. Thanks again.
Not all image formats support 'label' meta-data. and some support 'comment' meta-data.

See Labeling Montage Images
http://www.imagemagick.org/Usage/montage/#label

However I did just come across a actual BUG.

In montage you can use -label or -set label to create a new label based in the input image. For example using this test image...

Code: Select all

   convert rose: -set label 'rose'  -set comment '(is a rose)'  rose_with_metadata.png
Image

Montage can show the label (the default)

Code: Select all

   montage rose_with_metadata.png  -geometry +1+1 rose_label.png 
Image
It can show the comment

Code: Select all

   montage rose_with_metadata.png  -set label '%c' -geometry +1+1 rose_comment.png 
Image
But if can not use a 'label escape' to show the label

Code: Select all

   montage rose_with_metadata.png  -set label '%l' -geometry +1+1 rose_label_escape.png 
Image

This means you can not label an image with both its input label and its comment.

Code: Select all

   montage rose_with_metadata.png  -set label '%l\n%c' -geometry +1+1 rose_label_comment.png 
Image

It seems like IM is destorying the 'old' label before applying the format escape sequences.

Cristy reports the above problem with -set label '%l' is now fixed in latest SVN, (for the next ImageMagick 6.6.2-2 release)


However in finding a work around for this bug I found that MIFF file format can save ANY meta-data you like to specify!

For example...

Code: Select all

   convert rose: -set xyzzy 'Xyzzy' miff:- | 
       montage - -set label '%[xyzzy]' -geometry +1+1 rose_xyzzy.png 
Image

I actually use this technique in my new script kernel2image whcih I use to generate kernel images for IM examples
Morphology and Convolution pages
http://www.imagemagick.org/Usage/morphology/
(still under development).

Caution however is recommended with this as some of these are calculated escapes, and not extracted from image meta-data.

ASIDE: Set items without a "options:" prefix are known as "Image Properties" internally and in "identify -verbose", and are saved in MIFF. While items set with "options:" are "Image Attributes" and are generally used for expert or 'out-of-band' options used by various library options.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T19:54:37-07:00
by anthony
fmw42 wrote:testing -label "" does not seem to help

convert -font arial -pointsize 25 label:'line 1' -label "" tmp1.png
convert -font arial -pointsize 12 label:'line2' -label "" tmp2.png
montage tmp1.png tmp2.png -label "" -tile 1x -geometry +0+5 test01.png

I get the same bad result as in my first post above. Nor is the label removed from the verbose info in tmp1.png and tmp2.png

Image


Am I doing this incorrectly?
label: sets the "label" image meta-data automatically.

To remove a label (before saving) use +set label or -set label ''
or while reading montage you can use +label or -label ''. Note that to montage these do NOT have the same meaning. NOTE that -set label will always replace the meta-data label from images in memory.
See IM Examples, Labeling Montage Images
http://www.imagemagick.org/Usage/montage/#label

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T21:37:48-07:00
by fmw42
OK. After reading further at http://www.imagemagick.org/Usage/montage/#label

Using -set label "" after the image is read or created works:

convert -font arial -pointsize 25 label:'line 1' -set label "" tmp1.png
convert -font arial -pointsize 12 label:'line2' -set label "" tmp2.png
montage tmp1.png tmp2.png -tile 1x -geometry +0+5 test01.png

convert -font arial -pointsize 25 label:'line 1' tmp1.png
convert -font arial -pointsize 12 label:'line2' tmp2.png
montage tmp1.png tmp2.png -set label "" -tile 1x -geometry +0+5 test01.png



or using -label "" before creating or reading the images works.

convert -label "" -font arial -pointsize 25 label:'line 1' tmp1.png
convert -label "" -font arial -pointsize 12 label:'line2' tmp2.png
montage tmp1.png tmp2.png -tile 1x -geometry +0+5 test01.png

convert -font arial -pointsize 25 label:'line 1' tmp1.png
convert -font arial -pointsize 12 label:'line2' tmp2.png
montage -label "" tmp1.png tmp2.png -tile 1x -geometry +0+5 test01.png


Perhaps the docs on -label could be made a bit clearer with respect to -label "" and -set label "" and where they need to be used in the command line

This is all very strange to me why two different operations are needed to do the same thing.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-30T23:35:08-07:00
by anthony
fmw42 wrote:This is all very strange to me why two different operations are needed to do the same thing.
See Basics, Setting/Changing Image Attributes
http://www.imagemagick.org/Usage/basics/#settings

-label sets a format that will be applied as an image is read in or created.

-set label applies a lable immediatally to image in memory.

The first is easier to set a different label to each image as it is read in without needing to use parenthesis all the time. The second better for images that are already in memory (often after some very heavy processing, or make a final setting before saving, or using image attributes that are coming from the current or other images.

For example what will the difference in results be for each of the following commands...
Think before you try!

Code: Select all

    montage -label '%wx%h'   rose: -rotate 20   -geometry +3+3 show:
    montage rose: -rotate 20  -set label '%wx%h'  -geometry +3+3 show:
If you got that what should you get for...

Code: Select all

   montage rose: -rotate 20  -set label '%[width]x%[height]'  -geometry +3+3 show:
The two forms are actually essential to getting what you want easily!

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-31T11:12:21-07:00
by fmw42
got the first two, but had to look up how %{width] was defined at http://www.imagemagick.org/script/escape.php

your notes on the montage page are fairly clear. i just had not read them in depth until this came up. :oops:

But I think a note on the label: page that points out that an internal label is also created in the image file that will affect montage and whatever other files that use the internal label would be beneficial.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-31T11:27:17-07:00
by fmw42
This also seems to work compacted to one command line

montage -label "" \( -font arial -pointsize 25 label:'line 1' \) \
\( -font arial -pointsize 12 label:'line2' \) \
-tile 1x -geometry +0+5 test02.png

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-31T16:43:53-07:00
by anthony
fmw42 wrote:But I think a note on the label: page that points out that an internal label is also created in the image file that will affect montage and whatever other files that use the internal label would be beneficial.
I have added an 'expert note' into IM examples for both label and caption with this, including a reference to Basics, Image Attributes and Settings.

Re: possible bug or strange behavior -montage and PNG

Posted: 2010-05-31T16:49:28-07:00
by anthony
fmw42 wrote:This also seems to work compacted to one command line

Code: Select all

montage -label "" \( -font arial -pointsize 25 label:'line 1' \) \
\( -font arial -pointsize 12 label:'line2' \) \
-tile 1x -geometry +0+5 test02.png
Parenthesis is not needed in the above. They do nothing as you don't process the image with any operator after it is created. You only set settings which unless you have '-regard-parenthesis' set will not be restricted by parenthesis.

I would perhaps reset the -font and -pointsize if any of the images actually does have label meta-data attached (not in this case), as these settings at the end of the user given processing is used by montage to generate montage labels and titles.