SX60HS Porting - page 83 - DryOS Development - CHDK Forum  

SX60HS Porting

  • 915 Replies
  • 204600 Views
*

Offline reyalp

  • ******
  • 11924
Re: SX60HS Porting
« Reply #820 on: 29 / November / 2017, 16:25:04 »
Advertisements
I can't remember if it also corrects the CR2 raw file as well, or whether this done in Canon and Adobe software. 
The data in the CR2 is not corrected, it's done by the raw processing software.  I'm not sure if the information necessary for the correction is included in the CR2 format, my impression is not since software generally has to update to support new camera models.
Don't forget what the H stands for.

Re: SX60HS Porting
« Reply #821 on: 29 / November / 2017, 18:06:49 »
Canon firmware must have lens distortion parameters embedded somewhere in order to make jpegs. 

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: SX60HS Porting
« Reply #822 on: 29 / November / 2017, 18:19:57 »
Canon firmware must have lens distortion parameters embedded somewhere in order to make jpegs.


I spent some time trying to find this a few years ago - no luck I'm afraid. I don't think Canon write this to the CR2 files - I suspect Adobe uses their own correction matrices in their software. It's possible the correction is done in the Digic processor on the camera, not the main CPU.


I was able to convert a Canon .CR2 image to an Adobe DNG then use the dngvalidate program to see the Adobe lens correction matrix in the DNG file.
I did this for the G1X since it also has heavy distortion at the wide end.


Adding this Adobe lens correction data to the CHDK DNG files, produces a distortion corrected image; but it messes up the demosiacing and produces weird colours. I suspect that Adobe software expects demosaiced 'raw' data in the DNG file.


Phil.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

Re: SX60HS Porting
« Reply #823 on: 30 / November / 2017, 11:54:47 »
I'm no expert, but wouldn't demosaicing be done before any distortion corrections are applied?


*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: SX60HS Porting
« Reply #824 on: 30 / November / 2017, 14:06:41 »
I'm no expert, but wouldn't demosaicing be done before any distortion corrections are applied?


That's my understanding. I believe that DNG files created by Adobe software (DNG convertor, LR, PS) store the main 'raw' image already demosaiced. (There is an option to also store a copy of the original raw data.)


That's the main reason I don't convert my DSLR raw images to DNG - you can't take advantage of future improvements in demosaicing algorithms unless you also store the original raw, which makes the files a lot bigger.


When I tried adding correction data to a CHDK DNG file (using the WarpRectilinear opcode if memory serves), the result was not pretty. I'll see if I can dig up some examples.


Phil.





CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline reyalp

  • ******
  • 11924
Re: SX60HS Porting
« Reply #825 on: 30 / November / 2017, 16:46:44 »
I'm no expert, but wouldn't demosaicing be done before any distortion corrections are applied?
That's my understanding. I believe that DNG files created by Adobe software (DNG convertor, LR, PS) store the main 'raw' image already demosaiced.
I don't think this is correct. A G7X CR2 converted to DNG with Adobe DNG converter is still bayer, and is uncorrected if I look at it in rawtherapee
Quote
(There is an option to also store a copy of the original raw data.)
I think this option is to store the entire original raw image file
Don't forget what the H stands for.

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: SX60HS Porting
« Reply #826 on: 30 / November / 2017, 23:09:07 »
I'm no expert, but wouldn't demosaicing be done before any distortion corrections are applied?
That's my understanding. I believe that DNG files created by Adobe software (DNG convertor, LR, PS) store the main 'raw' image already demosaiced.
I don't think this is correct. A G7X CR2 converted to DNG with Adobe DNG converter is still bayer, and is uncorrected if I look at it in rawtherapee


Every possibility I've done something wrong and my analysis is incorrect :)


I've redone the earlier test on my G1X, attached are some resulting image comparisons (using Lightroom).


In each image the Canon .CR2 file is on the left, the CHDK DNG on the right.


In the first comparison (IMG_2704), there is no WarpRectilinear in the CHDK DNG file - you can see the distortion compared to the CR2 and the corner vignette.


In the second comparison I took the WarpRectilinear from a DNG converted from the CR2 using the Adobe DNG Convertor. I added this to the opcode list in the CHDK DNG file and took another image (IMG_2707). Using dng_validate I checked that the WarpRectilinear opcode is in the DNG file and has the expected values.


As you can see - the distortion is corrected; but i get funky colours.


Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline reyalp

  • ******
  • 11924
Re: SX60HS Porting
« Reply #827 on: 01 / December / 2017, 01:02:06 »
Every possibility I've done something wrong and my analysis is incorrect :)
To be clear, the only part I disagree with is that the adobe converted DNG are debayered, since exiftool and dng_validate still report they are CFA images (and creating debayered DNGs would kind of negate the purpose.)
Quote
As you can see - the distortion is corrected; but i get funky colours.
That is pretty weird. It seems like there must be some other difference that triggers this, but skimming the spec for WarpRectilinear doesn't provide any obvious clues.

The adobe converted DNG I have for G7 X does specify opcodes for each color (which the spec states can be used to correct for CA) but even if they were wrong (i.e. green warp being applied to red) it's hard to see it causing such a severe effect.

Is lightroom the only program you've tried to convert/view the modified CHDK DNG with? Might be worth trying converting it with dng_validate if you haven't.
Don't forget what the H stands for.


*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: SX60HS Porting
« Reply #828 on: 01 / December / 2017, 01:23:36 »
Is lightroom the only program you've tried to convert/view the modified CHDK DNG with? Might be worth trying converting it with dng_validate if you haven't.


dng_validate produces the same result, as does the Adobe DNG convertor.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: SX60HS Porting
« Reply #829 on: 01 / December / 2017, 16:57:15 »
Is lightroom the only program you've tried to convert/view the modified CHDK DNG with? Might be worth trying converting it with dng_validate if you haven't.


dng_validate produces the same result, as does the Adobe DNG convertor.


Doh! Found my mistake. There are up to three opcode lists in the DNG file, I was adding the WarpRectilinear opcode to the same one we use for the badpixel fix (OpCodeList1); but this is processed against the raw bayer data.


I needed to put the warp in OpCodeList3 which is processed after demosaicing and colour space conversion - pays to read the whole manual.


So it is theoretically possible to add distortion correction data to the CHDK DNG files.
Whether it's worth doing is another question. It seems that, once again, only Adobe software seems to use the opcode, and finding/creating the appropriate WarpRectilinear data could be complex. We would also need to add code the CHDK to determine the correct warp (based on zoom level), and add it to the DNG file.


Phil.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

 

Related Topics