Page 1 of 1

Rounding error when using composite soft_light for fake hdr

Posted: 2010-10-06T09:39:50-07:00
by tryl
Hi

I have pieced a string of commands together to make kind of a fake hdr look. It looks like this (from Bash):

workfile=IMG_5368.JPG
convert -negate -colorspace gray -resize 10% -resize 1000% "$workfile" - | composite -dissolve 85% - "$workfile" - | composite -compose Soft_Light - "$workfile" IMG_5368_processed.JPG

Btw. the files involved are:
Original: http://simonmikkelsen.dk/files/im/IMG_5368.JPG
Tmp (see later): http://simonmikkelsen.dk/files/im/IMG_5368_tmp.JPG
Result: http://simonmikkelsen.dk/files/im/IMG_5 ... cessed.JPG

However, when I do the final Soft_Light it seems there are some rounding errors. On the result file, look at the shadows at the ceiling inside of the garage. Instead of being gray tones, they are dark red and dark yellow/green. The first I think off is rounding errors, but maby I'm doing something wrong? If I do the soft light composite in The Gimp, there are no problems - I get nice smooth gray tones.

The tmp-file is made via
convert -negate -colorspace gray -resize 10% -resize 1000% "$workfile" - | composite -dissolve 85% - "$workfile" IMG_5368_tmp.JPG

so the result file can also be made via:

composite -compose Soft_Light IMG_5368_tmp.JPG IMG_5368.JPG IMG_5368_processed.JPG

I'm using version 6.3.7 06/04/09 Q16

Best regards,
Simon Mikkelsen, Denmark

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-06T21:34:16-07:00
by anthony
tryl wrote:workfile=IMG_5368.JPG
convert -negate -colorspace gray -resize 10% -resize 1000% "$workfile" - | composite -dissolve 85% - "$workfile" - | composite -compose Soft_Light - "$workfile" IMG_5368_processed.JPG
Before we go any further. Use IM correctly, applying opertions in command line order

See IM Examples, Basics.
http://www.imagemagick.org/Usage/basics/

As such the above should be...

Code: Select all

  workfile=IMG_5368.JPG
convert "$workfile"  -negate -colorspace gray -resize 10% -resize 1000%  - | composite -dissolve 85% - "$workfile" - | composite -compose Soft_Light - "$workfile" IMG_5368_processed.JPG
You can also do compositions all in one command!
See Complex Image Processing and Debugging
http://www.imagemagick.org/Usage/basics/#complex

Something like....

Code: Select all

convert IMG_5368.JPG \
         \( -clone 0 -negate -colorspace gray -resize 10% -resize 1000% \) \
         \( -clone 0,1  -compose dissolve  -define compose:args=85%  -composite \) \
         \( -clone 0,2 -compose Soft_Light \) \
         -delete 0--2   IMG_5368_processed.JPG
As your your actual problem -- simply the above to the actual problem!!!!

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T13:07:27-07:00
by tryl
Hi anthony

Thanks for the great answer - it took me a lot of time to digest everything, including reading a lot of your Image Magick guide.
anthony wrote: Before we go any further. Use IM correctly, applying opertions in command line order

See IM Examples, Basics.
http://www.imagemagick.org/Usage/basics/
As far as I can read this should not change the way Image Magick operates, but it will make my script compatible with version 7, which will not be as forgiving as version 6.
anthony wrote: You can also do compositions all in one command!
See Complex Image Processing and Debugging
http://www.imagemagick.org/Usage/basics/#complex

Something like....

Code: Select all

convert IMG_5368.JPG \
         \( -clone 0 -negate -colorspace gray -resize 10% -resize 1000% \) \
         \( -clone 0,1  -compose dissolve  -define compose:args=85%  -composite \) \
         \( -clone 0,2 -compose Soft_Light \) \
         -delete 0--2   IMG_5368_processed.JPG
Just if someone else should find this thread on Google, I had to change the 2nd last line to

Code: Select all

         \( -clone 0,2 -compose Soft_Light -composite \) \ 
to get it to work. I'm not sure, because IM is not easy to fully understand, the final -composite will do the actual compositing, while -compose soft_light will just set the parameters that -composite will use to work. Please correct me if I'm wrong.

Using your (compound?) command and not my own piped, it will run about 20 sec faster on a 12 mega pixel image on my slow/ computer. That sums up to a lot this Saturday, where it will have just one night to process about 1000 pictures from a local fun run.

That command did not work with my old version 6.3.7 06/04/09 Q16, so I downloaded version 6.6.4-9 2010-10-11 Q16 and compiled it with

Code: Select all

--with-quantum-depth=32 --enable-hdri=yes
I haven't had the time to recompile without one or both of those two, but from the documentation using something like that might be used for fixing too low precision.
anthony wrote: As your your actual problem -- simply the above to the actual problem!!!!
Now you sound like one of my math teachers at uni :)

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T16:02:39-07:00
by fmw42
convert IMG_5368.JPG \
\( -clone 0 -negate -colorspace gray -resize 10% -resize 1000% \) \
\( -clone 0,1 -compose dissolve -define compose:args=85% -composite \) \
\( -clone 0,2 -compose Soft_Light \) \
-delete 0--2 IMG_5368_processed.JPG

You are right. There is a typo where -composite should be added to the


\( -clone 0,2 -compose Soft_Light -composite \) \

It is an easy thing to leave out. I catch myself doing that from time to time.


I don't think your hdri or Q32 will make much difference with a JPG image. I think it was just that your old version of IM was too old and some of the compose options have been added or upgraded since then. Also the -compose dissolve -define compose:args=85% -composite approach to dissolve is relatively new usage with convert rather than with composite

see http://www.imagemagick.org/script/compose.php

I think -define compose:args and -set option:compose:args are pretty much the same. I am not sure why Anthony is using the former.

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T17:39:16-07:00
by anthony
fmw42 wrote:I think -define compose:args and -set option:compose:args are pretty much the same. I am not sure why Anthony is using the former.
They are the same. and I have taken to using the -define form as it is simplier. Many areas of IM examples has already been modified, though typically they list both methods.

It also makes it obvious that your are defining a global "Artifact" that are used purly for internal IM operations, rather than a per image "Properity". Artifacts are NOT saved with images, though many properties can. MIFF for example will save all defined properties.

However the -define form can NOT use 'percent escapes' while the special -set option:... form can.

I have been trying to write up basic information about image attributes, settings, properties, and global defines in IM Examples, Basics.
http://www.imagemagick.org/Usage/basics/#attributes
But it is a complex topic.

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T17:50:05-07:00
by fmw42
However the -define form can NOT use 'percent escapes' while the special -set option:... form can.
Good to know!
I have been trying to write up basic information about image attributes, settings, properties, and global defines in IM Examples, Basics.
http://www.imagemagick.org/Usage/basics/#attributes
But it is a complex topic.
That will be most welcome. Agreed it is complex, but long overdue -- any notes will be helpful

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T19:19:07-07:00
by anthony
I have done more work on IM Examples in that area, and actually converts command line into actual image examples. Including the important example of converting a per-image 'properity' (set) into global 'artifact' (define) so that you can generate a label from the properity.

Code: Select all

  convert -size 100x label:Anthony \
          -set option:my_pointsize '%[label:pointsize]' \
          -size 100x label:'at %[my_pointsize]pt' \
          -append  properity_tricky.gif
Image

Re: Rounding error when using composite soft_light for fake

Posted: 2010-10-12T19:52:21-07:00
by fmw42
anthony wrote:I have done more work on IM Examples in that area, and actually converts command line into actual image examples. Including the important example of converting a per-image 'properity' (set) into global 'artifact' (define) so that you can generate a label from the properity.

Code: Select all

  convert -size 100x label:Anthony \
          -set option:my_pointsize '%[label:pointsize]' \
          -size 100x label:'at %[my_pointsize]pt' \
          -append  properity_tricky.gif
Image

Pretty neat.