Pages: Prev 1 2 3 [4] 5 6 Next   Go Down
  Print  
Author Topic: Custom processing for JPEG (Tone curve, CA ...)  (Read 10581 times)
0 Members and 1 Guest are viewing this topic.
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #45 on: 03 / June / 2008, 05:27:39 »

This is very neat stuff, very powerful.  I just realized (it may be just me that is slow)  that the curves can be used to change EV values when developing. 

I am not sure that this can be done just by multiplying or dividing the data by constants.  I did some tests and although it works there seems to be a color shift for large multipliers/divisors.  But for small increase in EV it works nicely.  Say multiply by 1.5 or .75 in the code below.

The overall implementation of the curve is FLAWED and would barely work for multipliers/divisors. That's why things seems to work at some extend for you.
The color shift is due to the non linear response of the RAW data. Since the non linear response of the sensor is not known, it will be very hard to work out something to correct it.

Quote
I have hope that it will be possible to figure out curves that develop at various +/- EV and preserve color.

Hopefully these curves could be created on the fly or loaded automatically.  That way someone would not have to master the details of using curves to simply brighten up a photo.

If the curve becomes non linear color shift may even worsen.
The correct way to do it would be to interpolate, then convert the RGB RAW into for example a HSI space, adjust I and convert back to Bayer RAW for the camera to develop. Which is a double operation and will be to CPU intensive for the camera.
Logged
hiker_jon
Full Member
***

Karma: +9/-0
Offline Offline

Posts: 115


« Reply #46 on: 03 / June / 2008, 06:42:33 »

The overall implementation of the curve is FLAWED and would barely work for multipliers/divisors. That's why things seems to work at some extend for you.
The color shift is due to the non linear response of the RAW data. Since the non linear response of the sensor is not known, it will be very hard to work out something to correct it.


Do you mean that the whole idea of using curves is flawed?  If so I think that you are too pessimistic.  For instance, one curve certainly works great: the identity curve.  Others will probably work well also, the trick is to figure out what sort of curves will work.


Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #47 on: 04 / June / 2008, 15:09:41 »

Do you mean that the whole idea of using curves is flawed?  If so I think that you are too pessimistic.  For instance, one curve certainly works great: the identity curve.  Others will probably work well also, the trick is to figure out what sort of curves will work.

The identity tone curve does nothing. The way the tone curve is implemented will yield unexpected color shift depending on the ratio of and level of each R/G/B component (i.e. on the contents of the picture)

Current implementation:
R' = LookUpRed1(R)
G' = LookUpGreen1(G)
B' = LookUpBlue1(B)

A correct implementation would be to convert the RGB in a HSV space, change V using a look up table and back to RGB assuming that RGB are linear.

An approximate implementation (yet to be tested) would be
L = Luminance(R,G,B)
R' = LookUpRed2(L,R)
G' = LookUpGreen2(L,G)
B' = LookUpBlue2(L,B)

R,G,B will be extracted from the interpolation of the Bayer pattern.
R',G',B' will be reapplied back to the Bayer pattern (not sure how yet).
L function yet to be defined - May be (2R+G1+G2+2B)/6

The computation complexity is much worst and the memory cost would be really bad 1024x1024x3x2 Bytes.
« Last Edit: 14 / July / 2008, 06:09:30 by toinech » Logged
hiker_jon
Full Member
***

Karma: +9/-0
Offline Offline

Posts: 115


« Reply #48 on: 04 / June / 2008, 15:50:50 »

Hi,

Thanks for the reply.  The details of developing from sensor data are a mystery to me.  This is what I guessed (not based on any real knowledge) :  The red, green and blue sensors are linear, but may have different gain and offset.  I hope this gain and offset just depend on the color, but it might be that green sensors in even rows behave differently than ones in odd rows.  To get a consistent linear Rl,Gl,Bl value you calc Rl = R0 + Rg * R, etc.   Once we know what the offset and gain values of each sensor type are, we can anticipate the Canon calculation and produce curves that will work.  At least for changing ev this should be possible.

Jon
Logged
hiker_jon
Full Member
***

Karma: +9/-0
Offline Offline

Posts: 115


« Reply #49 on: 15 / June / 2008, 00:18:17 »

Hi,

I have done some testing with my camera and the curves work great for changing the ev. 

I use my routine
void raw_mul(double mult, double offset)
posted previously in this topic.  This routine multiplies the raw data by mult then adds offset.  Use it on the raw data before raw develop.
The trick is to know what the black value is for your sensor.  This is the nominal value that the sensor records when there is no light.  It is higher than 0 to accommodate noise.  I found this value out by doing the following:
Take a picture of a scene with a black object (inside of a pipe, say) and save the raw data.  Outside the camera I used dcraw -D -4 CRW_1815.CRW.  This produces a 16bit image of the raw data.  ImageJ can read such data.  Looking at the values in the pipe interior I saw that they averaged about 32 (ISO80,A720IS).  This seemed to be the same for the R,G,B sensors.  I think the black value is also the same for other ISO's, but will need to do more testing.
Now to increase or decrease the ev I set mult to what I want (say 2 for ev +1 or .5 for ev -1) and calculate offset = black - mult * black.  (i.e. this effectively subtracts black before doing the mult and adds it back after).

Using this routine enables developing with +/- ev.  Very useful in case the wimpy flash does not sufficiently illuminate your subject.  Or for "shooting right", i.e. deliberately overexposing your subject then developing the raw at minus ev to get a properly exposed and less noisy image.

Of course our cameras only have 10bit raws so the usefulness of this is limited to low changes in ev.  Probably +- 1 is the limit for high quality, but +2 has worked for me in redeveloping a picture I took in a cave where my flash could not reach.

Implementing curves that are usually applied in RGB space should also work.  You just have to remember to deal with the black offset and also to convert the curve to linear space.

Jon
« Last Edit: 15 / June / 2008, 00:20:09 by hiker_jon » Logged
ifaxi
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7


« Reply #50 on: 16 / June / 2008, 09:51:21 »

Pardon my French but...THIS SH** is COOL!!! Thanks to all of you who got this put together, now I dont have to carry around a grey cand, and color cards!
Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #51 on: 17 / June / 2008, 01:00:00 »

The trick is to know what the black value is for your sensor.  This is the nominal value that the sensor records when there is no light.

You may be able to get the value in any case since there is part of the sensor that is not exposed. Possibly the average value of the first row.

Some publication also indicated that you can avoid the color shift and desaturation by using the following formula:

R = (Y'/Y*(R+Y) + R - Y)/2
G = (Y'/Y*(G+Y) + G - Y)/2
B = (Y'/Y*(B+Y) + B - Y)/2

Where Y is the luminance value before the change and Y' is the luminance value after the change.

It kind of partially works but cause some loss of contrast. Color correction seems a little bit more controllable.

I attached the code if you want to have some fun with it.

Note:
- I stored directly in the curvex[] table the (Y'/Y)*1024 value to avoid division which is not in ARM native instruction.
- I also cheated:
  Y = (R+G)/2 for the red line
  Y = (B+G)/2 for the blue line

Outdated attachment removed...
« Last Edit: 11 / July / 2008, 15:09:34 by toinech » Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #52 on: 17 / June / 2008, 01:08:52 »

Take a picture of a scene with a black object (inside of a pipe, say) and save the raw data.  Outside the camera I used dcraw -D -4 CRW_1815.CRW.  This produces a 16bit image of the raw data.  ImageJ can read such data.  Looking at the values in the pipe interior I saw that they averaged about 32 (ISO80,A720IS).  This seemed to be the same for the R,G,B sensors.  I think the black value is also the same for other ISO's, but will need to do more testing.
Now to increase or decrease the ev I set mult to what I want (say 2 for ev +1 or .5 for ev -1) and calculate offset = black - mult * black.  (i.e. this effectively subtracts black before doing the mult and adds it back after).

You may want to avoid all the pain if you use the GetPixel.exe that I attached in an earlier post.
Here again...
Logged
hiker_jon
Full Member
***

Karma: +9/-0
Offline Offline

Posts: 115


« Reply #53 on: 17 / June / 2008, 15:30:24 »

You may want to avoid all the pain if you use the GetPixel.exe that I attached in an earlier post.

Hi,

I tried getpixel and it works great.  Question: how do you determine the raw coordinates of a pixel from the coordinates in an image?

Here is an example of in-camera raw develop.  I took some pictures at Chumash Painted Cave above Santa Barbara.  The entrance is blocked by an iron grate.  I had to stick my camera through the grate and take pictures from there.  At the deeper parts of the cave the wimpy flash on my A720 didn't reach.
EV0:

EV+2:


« Last Edit: 17 / June / 2008, 15:42:34 by hiker_jon » Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #54 on: 18 / June / 2008, 07:35:06 »

I tried getpixel and it works great.  Question: how do you determine the raw coordinates of a pixel from the coordinates in an image?

The pixel is determined the same way as for the curve_apply routine.
The pixel position is in fact the position in the Bayer matrix including all 4 colors (RGGB)
The following applies:
Pix(2a,2b) => Red
Pix(2a+1,3b) => Green
Pix(2a,2b+1) => Green
Pix(2a+1,2b+1)=> Blue

Nice pictures.
Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #55 on: 04 / July / 2008, 20:24:08 »

Updated curves.c to include the black level adjust as per john_hiker recommendation.
This version multiply the channels with a set of  multipliers derived from the luminance.
This will help mitigate color shift when apply curves.

Remove binaries to make room in post.
« Last Edit: 12 / July / 2008, 22:29:24 by toinech » Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #56 on: 12 / July / 2008, 23:01:05 »

Since I'm often slightly under-exposing (-2/3 EV) to avoid blow-out, I'm looking for a curve to bring out the shadows (a-la D-Lighting in Nikon DSLRs).

I attached the changes in curve that will fit your need here.
Just need to set the curve mode to "Auto DR" use the standard EV comp feature by looking at the Zebra. The system will apply the proper amplification to the shadow based on the EV comp.

Side effect of "Auto DR": added 2 more steps on the ISO (+1EV and +2EV) - and unfortunately the noise...  Sad

Hopefully Jucifer will have some time to push it in.

BTW: The SYSCURVES.CVF file has to be put in the A/CHDK directory
« Last Edit: 19 / July / 2008, 03:29:29 by toinech » Logged
madcrow
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 1


« Reply #57 on: 15 / July / 2008, 18:10:54 »

Does anybody have a library of already-made curves or at least a link to a website where various useful/fun curves are shown visually?

Also, this is just a heads-up to let folks know that the Curve Editor works great in Linux under Wine, so long as you've used winetricks to install the VB runtime stuff.
Logged
toinech
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 65


« Reply #58 on: 17 / July / 2008, 01:32:51 »

Does anybody have a library of already-made curves or at least a link to a website where various useful/fun curves are shown visually?

Not really - follow this though: Curve Anthology

Attached some curve samples below.
« Last Edit: 27 / July / 2008, 02:56:23 by toinech » Logged
acorrias
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 17

[A650IS]


« Reply #59 on: 27 / July / 2008, 10:49:24 »

HI
i'm experimenting with tone curve. Could you tell me about the differente between the CV and CVF files? Should I put them in the curves directory?

could you explain me how to use auto DR? you wrote: "Just need to set the curve mode to "Auto DR" use the standard EV comp feature by looking at the Zebra."

is this the correct workfow?

1) take a shoot with raw enabled
2) set tone curve to auto dr
3) develop the raw

my problem is how using zebra in the workflow. I dont understand how to use (or set) EV comp.

Another question: is it possoble to define a curve that simulates a velvia effect?

thanks in advance
alex
« Last Edit: 27 / July / 2008, 11:00:37 by acorrias » Logged
Pages: Prev 1 2 3 [4] 5 6 Next   Go Up
  Print  
 
Jump to: