Page 1 of 1

WITHDRAWN: request enhancement -evaluate-sequence sum

Posted: 2012-01-30T18:00:48-07:00
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

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-30T18:53:08-07:00
by magick
What is the difference between '-evaluate-sequence add' (which currently works) and '-evaluate-sequence sum'?

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-30T19:03:29-07:00
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.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-30T20:03:53-07:00
by fmw42
If you can provide me with a list of operators that work with -evaluate-sequence, I can edit the options page.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T06:38:43-07:00
by magick
All the operators from -evaluate should work with -evaluate-sequence.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T10:43:48-07:00
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?

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T11:20:44-07:00
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.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T17:23:27-07:00
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

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T17:43:34-07:00
by magick
See magick/statistic.c/EvaluateImages().

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T18:45:57-07:00
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?

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T19:18:44-07:00
by magick
What happens if you use -evaluate-sequence add 0? If that fails, I'll look a little deeper for a solution.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T19:31:32-07:00
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.

Re: request enhancement -evaluate-sequence sum

Posted: 2012-01-31T20:52:58-07:00
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.