exposure compensation?
exposure compensation?
Hi,
I've got two images which are 4 stop apart (in 16bits linear TIFF from dcraw). I would like to apply a negative exposure compensation (-4) to the over-exposed image (+4EV). The aim is to create a layer mask to reduce noise from the normal exposed shot.
The mask will be composed of:
- a negate version of the over-exposed image
- a corrected over exposed image from the over-exposed image (that's what I'm trying to do)
- merge the negate image to the alpha channel of the corrected over-exposed image
Finally I'll overlay the mask to the normal image.
So far I've got these:
step 1 --> convert overexposed.tiff -negate negate.tiff
step 2 --> ???
step 3 --> composite -compose CopyOpacity negate.tiff corrected_overexposed.tiff mask.tiff
step 4 --> composite normal.tiff mask.tiff merge.tiff (need to test this, don't know if I need to use -blend)
Can I achieve this with ImageMagick? and do I need to enable HDRI?
Regards,
Ced.
I've got two images which are 4 stop apart (in 16bits linear TIFF from dcraw). I would like to apply a negative exposure compensation (-4) to the over-exposed image (+4EV). The aim is to create a layer mask to reduce noise from the normal exposed shot.
The mask will be composed of:
- a negate version of the over-exposed image
- a corrected over exposed image from the over-exposed image (that's what I'm trying to do)
- merge the negate image to the alpha channel of the corrected over-exposed image
Finally I'll overlay the mask to the normal image.
So far I've got these:
step 1 --> convert overexposed.tiff -negate negate.tiff
step 2 --> ???
step 3 --> composite -compose CopyOpacity negate.tiff corrected_overexposed.tiff mask.tiff
step 4 --> composite normal.tiff mask.tiff merge.tiff (need to test this, don't know if I need to use -blend)
Can I achieve this with ImageMagick? and do I need to enable HDRI?
Regards,
Ced.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: exposure compensation?
you need to explain how you want to correct the overexposed image for step 2, that is what is the formula or processing that you need to do
Re: exposure compensation?
I don't know the maths but I would like to reproduce the following tutorial: http://jtrujillo.net/qpix/
The image A is my normal exposed one, the image C is my over-exposed one and the image B is the one I'm trying to acheive from C.
The image A is my normal exposed one, the image C is my over-exposed one and the image B is the one I'm trying to acheive from C.
Re: exposure compensation?
you can just use -average to combine the two pics (or more)
for the mind blowing hdr style pics, you'd need to use tone mapping, which I don't think there is any support for in IM.
It does support hdr format if you enable hdr while compiling.
for the mind blowing hdr style pics, you'd need to use tone mapping, which I don't think there is any support for in IM.
It does support hdr format if you enable hdr while compiling.
Re: exposure compensation?
It's not really HDR --> http://www.guillermoluijk.com/article/n ... dex_en.htm
Re: exposure compensation?
I've finally found the logarithmic formula... so I've tried to multiply the linear data with 2^-4
convert test.tiff -fx 'u*2^-4' corrected.tiff
I takes ages (with a core2duo) with an images of 3474x2314, is it possible to optimize this?
convert test.tiff -fx 'u*2^-4' corrected.tiff
I takes ages (with a core2duo) with an images of 3474x2314, is it possible to optimize this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: exposure compensation?
If this is really what you need, then you are simply multiplying the image by 2^-4 = 1/2^4 = 1/16 = 0.0625. Multiplying the image by such a small number will make your image very dark. But if that is what you want to do, then use -evaluate multiply 0.0625
See -evaluate at http://www.imagemagick.org/script/comma ... p#evaluate
See -evaluate at http://www.imagemagick.org/script/comma ... p#evaluate
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: exposure compensation?
From what I can see the key is the creation of the image mask, so that you can then use it with a three image composite blend.
That is...
The tricky part is generating the right type of mask which is black where you want the first image, white where you want the second image, and the appropriate shade of gray when you want a blended weighted average between the two images.
One image is the normal exposure, while the other the corrected over exposure image. Which image is which does not matter, as if the images are swapped, you just use a negated mask instead (swap black and white when you swap images).
In many ways this is similar to the 'Double Exposure' technique I example in IM Examples, Photo Handling, but for noise reduction improve the Dynamic range of the resulting image so both the detail in both the bright and dark areas are much more visible.
The article however is not really very clear about how to go about generating that mask, as it is expressed in photoshop terms, such as
That is...
Code: Select all
convert image1.png image2.png blend_mask.png \
-compose Src -composite result.png
One image is the normal exposure, while the other the corrected over exposure image. Which image is which does not matter, as if the images are swapped, you just use a negated mask instead (swap black and white when you swap images).
In many ways this is similar to the 'Double Exposure' technique I example in IM Examples, Photo Handling, but for noise reduction improve the Dynamic range of the resulting image so both the detail in both the bright and dark areas are much more visible.
The article however is not really very clear about how to go about generating that mask, as it is expressed in photoshop terms, such as
and laterthe overexposed image with all the highlights clipped .. copy to clippboard
which is about as clear as MUD.And this the result after some additional processing to boost the shadows
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: exposure compensation?
Thanks a lot, it's much faster! from 6min to 2s...
Here is an example with hdr1.tiff the normal exposed image (full of noise in the shadow) and hdr3.tiff the +4EV over-exposed
My next task is to calculate the real exposure difference between 2 source images. For my example the second image has +4EV but in reality is +3.93EV. By doing this I'll have a smooth blending mask.
The tricky part is to find the correct ratio for the blending...
Here is an example with hdr1.tiff the normal exposed image (full of noise in the shadow) and hdr3.tiff the +4EV over-exposed
Code: Select all
convert hdr3.tiff -negate negate.tiff
ec=$(echo 'e(l(2)*-3.93)' | bc -l)
convert hdr3.tiff -evaluate multiply $ec corrected.tiff
composite -compose CopyOpacity negate.tiff corrected.tiff mask.tiff
composite -blend 90 mask.tiff hdr1.tiff merge.tiff
convert -gamma 2.2 merge.tiff -channel ALL -normalize -quality 100 result.jpg
The tricky part is to find the correct ratio for the blending...
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: exposure compensation?
Do you have two images I can use as an example of doing this? I would like to try to explain how to do this in IM examples Photo Handling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: exposure compensation?
This technique is from this tutorial --> http://www.guillermoluijk.com/tutorial/ ... /index.htm
That's the images I've used to be able to compare from the tutorial
http://www.guillermoluijk.com/download/hdr1.cr2
http://www.guillermoluijk.com/download/hdr3.cr2
Here is the dcraw command lines to get a linear 16bits TIFF with the camera WB:
Before doing a chapter in your documentation, I need to figure out how to calculate the exact exposure and if it's possible to get the optimum blending ratio.
For the exposure difference, can I do this with the IM command line tools or do I need to use the API?
That's the images I've used to be able to compare from the tutorial
http://www.guillermoluijk.com/download/hdr1.cr2
http://www.guillermoluijk.com/download/hdr3.cr2
Here is the dcraw command lines to get a linear 16bits TIFF with the camera WB:
Code: Select all
dcraw -v -w -W -o 0 -q 3 -4 -T hdr1.cr2
dcraw -v -w -W -o 0 -q 3 -4 -T hdr3.cr2
For the exposure difference, can I do this with the IM command line tools or do I need to use the API?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: exposure compensation?
I think you will need to use some mix of Im with some API calculations.cedricb wrote:For the exposure difference, can I do this with the IM command line tools or do I need to use the API?
The tricky part is finding some area of the image that is common to both images BUT which has not been clipped by the over exposure. From this the difference should be calculated and thus determining the adjustment needed using whatever function you use to do the exposure adjustment.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: exposure compensation?
First draft implementation of the exposure calculation between 2 images. I don't know if there is a simple solution or more elegant solution to do this, for the time been it works...
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wand/MagickWand.h>
int main(int argc,char **argv) {
MagickBooleanType status;
MagickPixelPacket pixel1, pixel2;
MagickWand *image1, *image2;
PixelIterator *iterator1, *iterator2;
PixelWand **pixels1, **pixels2;
long y;
register long x;
unsigned long width;
double min = 65536 / pow(2, 6);
double max = 65536 * 0.9;
double sum1 = 0, sum2 = 0;
if (argc != 3) {
fprintf(stdout, "Usage: %s normal-image over-exposed-image\n", argv[0]);
exit(0);
}
MagickWandGenesis();
image1 = NewMagickWand();
status = MagickReadImage(image1, argv[1]);
if (status == MagickFalse) {
return -1;
}
image2 = NewMagickWand();
status = MagickReadImage(image2, argv[2]);
if (status == MagickFalse) {
return -1;
}
iterator1 = NewPixelIterator(image1);
iterator2 = NewPixelIterator(image2);
if ((iterator1 == (PixelIterator *) NULL) || (iterator2 == (PixelIterator *) NULL)) {
return -1;
}
for (y=0; y < (long) MagickGetImageHeight(image1); y++) {
pixels1 = PixelGetNextIteratorRow(iterator1, &width);
pixels2 = PixelGetNextIteratorRow(iterator2, &width);
if ((pixels1 == (PixelWand **) NULL) || (pixels2 == (PixelWand **) NULL)) {
break;
}
for (x=0; x < (long) width; x++) {
PixelGetMagickColor(pixels1[x], &pixel1);
PixelGetMagickColor(pixels2[x], &pixel2);
if ((pixel1.red >= min) && (pixel1.red <= max) && (pixel2.red >= min) && (pixel2.red <= max)) {
sum1 += pixel1.red;
sum2 += pixel2.red;
}
if ((pixel1.green >= min) && (pixel1.green <= max) && (pixel2.green >= min) && (pixel2.green <= max)) {
sum1 += pixel1.green;
sum2 += pixel2.green;
}
if ((pixel1.blue >= min) && (pixel1.blue <= max) && (pixel2.blue >= min) && (pixel2.blue <= max)) {
sum1 += pixel1.blue;
sum2 += pixel2.blue;
}
}
}
if (y < (long) MagickGetImageHeight(image1)) {
return -1;
}
iterator1 = DestroyPixelIterator(iterator1);
image1 = DestroyMagickWand(image1);
iterator2 = DestroyPixelIterator(iterator2);
image2 = DestroyMagickWand(image2);
MagickWandTerminus();
printf("%.100g\n", sum1/sum2);
return(0);
}
Code: Select all
gcc `Magick-config --cflags --cppflags` -o exposure exposure.c `Magick-config --ldflags --libs`