WITHDRAWN: request enhancement -evaluate-sequence sum

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

WITHDRAWN: request enhancement -evaluate-sequence sum

Post by fmw42 »

I would like to request an enhancement to add another option to -evaluate-sequence to sum the images together.

The reason is to do a weighted average of images by combining -evaluate multiply on several images with -evaluate-sequence sum. In particular, I want to be able to mix channels to create a grayscale image. Perhaps there is some way that I am missing. I know one could do -evaluate sequence mean -evaluate multiply to achieve the same result, but I suspect the divide followed by the multiply will lose a bit a of resolution/quality. Correct me if I am wrong. Also one could use -compose plus -composite in pairs. But -evaluate-sequence sum seems to be a reasonable solution barring a new function to do weighted averaging of multiple images.

Right now I do for example:


convert image -separate +channel \
\( -clone 0 -evaluate multiply 0.3 \) \
\( -clone 1 -evaluate multiply 0.6 \) \
\( -clone 2 -evaluate multiply 0.1 \) \
-delete 0,1,2 -evaluate-sequence mean -evaluate multiply 3 \
result

I would like to do

convert image -separate +channel \
\( -clone 0 -evaluate multiply 0.3 \) \
\( -clone 1 -evaluate multiply 0.6 \) \
\( -clone 2 -evaluate multiply 0.1 \) \
-delete 0,1,2 -evaluate-sequence sum \
result

This is not high priority. However, I expect that it is not a difficult or time consuming addition to -evaluate-sequence.

So please consider the request and if appropriate do whenever convenient.

Thanks.

Fred
Last edited by fmw42 on 2012-02-18T10:37:42-07:00, edited 2 times in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: request enhancement -evaluate-sequence sum

Post by magick »

What is the difference between '-evaluate-sequence add' (which currently works) and '-evaluate-sequence sum'?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

magick wrote:What is the difference between '-evaluate-sequence add' (which currently works) and '-evaluate-sequence sum'?
Yes, I can confirm that -evaluate-sequence add does work. Thanks for providing that information.

I was not sure that was an option for -evaluate-sequence as it means something different for -evaluate. And there is no list of available options (operators) for -evaluate-sequence showing what each operator means.

convert -list -evaluate-sequence
convert: unrecognized list type `-evaluate-sequence' @ error/convert.c/ConvertImageCommand/1880.


And there is no documentation with list of available operators on the options page for -evaluate-sequence

Thanks, however, for pointing out the "add" option.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

If you can provide me with a list of operators that work with -evaluate-sequence, I can edit the options page.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: request enhancement -evaluate-sequence sum

Post by magick »

All the operators from -evaluate should work with -evaluate-sequence.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

magick wrote:All the operators from -evaluate should work with -evaluate-sequence.
OK, but like the "add" option, some mean different things, and I am not sure what the difference are. For example how would a bit shift or threshold apply to -evaluate-sequence to combine the images?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: request enhancement -evaluate-sequence sum

Post by magick »

For now the only ops that may make sense for -evaluate-sequence is median, mean, and multiply. However all are supported. We could also tweaks some of the operators if it makes sense to treat them differently for a sequence verses just a single image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

magick wrote:For now the only ops that may make sense for -evaluate-sequence is median, mean, and multiply. However all are supported. We could also tweaks some of the operators if it makes sense to treat them differently for a sequence verses just a single image.
Right, plus "add", "min", "max". I will try to write up some further notes on the options page about these. Also I see that Anthony has added -evaluate-sequence to his page at http://www.imagemagick.org/Usage/layers/. I am not sure how long that has been there. But it is a good description of all the above options.

Fred

P.S. I tried to find where you do the -evaluate-sequence operations in the code, but could only find something for -evaluate. Where is the right code, as -evaluate-sequence add means something different from -evaluate add?


Edited -- see bold text above
Last edited by fmw42 on 2012-01-31T18:52:06-07:00, edited 3 times in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: request enhancement -evaluate-sequence sum

Post by magick »

See magick/statistic.c/EvaluateImages().
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

magick wrote:See magick/statistic.c/EvaluateImages().

I don't see where that does the processing for -evaluate-sequence, especially for the "add" option:


case AddEvaluateOperator:
{
result=(MagickRealType) (pixel+value);
break;


That just adds a constant (value) to the pixel value and does not seem to me to handle adding two or more images pixel values together?

What am I missing?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: request enhancement -evaluate-sequence sum

Post by magick »

What happens if you use -evaluate-sequence add 0? If that fails, I'll look a little deeper for a solution.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: request enhancement -evaluate-sequence sum

Post by fmw42 »

magick wrote:What happens if you use -evaluate-sequence add 0? If that fails, I'll look a little deeper for a solution.
Perhaps everthing is correct. I just don't see where multiple images comes in for any of the -evaluate operators as you seem to be using the same code for -evaluate-sequence as for -evaluate. But I don't read code that well, so I might be missing something extra you have for -evaluate-sequence.

With regard to your question above:


convert rose: -colorspace gray rose_gray.png

convert rose_gray.png \
> \( -clone 0 -evaluate multiply 0.3 \) \
> \( -clone 0 -evaluate multiply 0.6 \) \
> \( -clone 0 -evaluate multiply 0.1 \) \
> -delete 0 -evaluate-sequence add 0 \
> rose_gray_ave3.png
convert: unable to open image `0': No such file or directory @ error/blob.c/OpenBlob/2589.
convert: no decode delegate for this image format `0' @ error/constitute.c/ReadImage/532.



However, the following should be equivalent to

convert rose: -colorspace gray rose_gray.png

convert rose: -separate \
> \( -clone 0 -evaluate multiply 0.29900 \) \
> \( -clone 1 -evaluate multiply 0.58700 \) \
> \( -clone 2 -evaluate multiply 0.11400 \) \
> -delete 0,1,2 -evaluate-sequence add \
> rose_gray_mixchannels.png

compare -metric rmse rose_gray.png rose_gray_mixchannels.png null:
11.0938 (0.000169281)


So the results are favorable to it working properly without the value for add.

So I am just puzzled where in the code this difference between -evaluate and -evaluate-sequence is coming from. Not a big priority as it seems to be working correctly.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: request enhancement -evaluate-sequence sum

Post by anthony »

fmw42 wrote: P.S. I tried to find where you do the -evaluate-sequence operations in the code, but could only find something for -evaluate. Where is the right code, as -evaluate-sequence add means something different from -evaluate add?
To track the code find the magick core function name in "wand/mogrify.c". If you do not have 'c-tags' setup you can grep for that function in the magick/*.h files to locate the matching 'c' file containing that function.

In IMv7 the files are "MagickWand/operations.c" as a starting point (still in development, but I have reviewed all the options present - more changed to come later), and the core files are in MagickCore/ sub-directory.

The method names of -evaluate-sequence I have verified are the same as those of -evaluate. I hit that same 'list' fault myself, so prehaps a -list evaluate-sequence item needs to be added to make it easier. Then again the -ordered-dither list is actuually "threshold", and -morphology has two lists "morphology" and "kernel", so the operation to list name is not completely one-to-one.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply