RAW data restructure for Infrared photograpy? - RAW Shooting and Processing - CHDK Forum

RAW data restructure for Infrared photograpy?

  • 20 Replies
  • 5078 Views
RAW data restructure for Infrared photograpy?
« on: 08 / August / 2013, 13:59:58 »
Advertisements
One of my Canon S5is cameras has been converted to full spectrum so I can take infrared photographs. I use CHDK on it to save RAW files, however much of the benefit of the raw file is lost when I post process the file, because one of the first things done in the workflow is to use something like the channel mixer in photoshop to switch the red and blue channels..   but this can't be done to a RAW or DNG file, I have to convert it to a TIF or something.  The white balance setting plays a HUGE role in what the final image will look like, however it is difficult to get it right before you do the channel swap because the colors are all wrong, and after the channel swap, the white balance is very limited because it's not a RAW or DNG file anymore.

So I am wondering,  since CHDK is creating the RAW file for me... IS there any way I could hack it so that it would write out all the 'blue' data where red goes and all the 'red' data where blue goes, thereby making a pre channel swapped raw file that I could work with?     

Does anyone have any ideas on how this could possibly be done, either in camera or with something like the DNG4PS2 program?  Many infrared photographers would be extremely happy if this could be achieved.

*

Offline a1ex

  • *****
  • 671
  • ML dev
Re: RAW data restructure for Infrared photograpy?
« Reply #1 on: 08 / August / 2013, 14:58:09 »
You can try to modify this: https://bitbucket.org/hudson/magic-lantern/src/tip/modules/dual_iso/cr2hdr.c

Should be pretty straightforward. Hint: throw away all that math, keep only the DNG read/write functions.

*

Offline reyalp

  • ******
  • 12364
Re: RAW data restructure for Infrared photograpy?
« Reply #2 on: 08 / August / 2013, 15:58:23 »
So I am wondering,  since CHDK is creating the RAW file for me... IS there any way I could hack it so that it would write out all the 'blue' data where red goes and all the 'red' data where blue goes, thereby making a pre channel swapped raw file that I could work with?     
You could hack the CFAPattern tag in the DNG to swap which pixels are interpreted as R and B. Not sure if this is what you want, but it should be straightforward to do either in camera or after the fact.

Physically swapping the data on camera would be far to slow to be practical.
Don't forget what the H stands for.

*

Offline philmoz

  • *****
  • 3146
    • Photos
Re: RAW data restructure for Infrared photograpy?
« Reply #3 on: 08 / August / 2013, 16:00:30 »
One of my Canon S5is cameras has been converted to full spectrum so I can take infrared photographs. I use CHDK on it to save RAW files, however much of the benefit of the raw file is lost when I post process the file, because one of the first things done in the workflow is to use something like the channel mixer in photoshop to switch the red and blue channels..   but this can't be done to a RAW or DNG file, I have to convert it to a TIF or something.  The white balance setting plays a HUGE role in what the final image will look like, however it is difficult to get it right before you do the channel swap because the colors are all wrong, and after the channel swap, the white balance is very limited because it's not a RAW or DNG file anymore.

So I am wondering,  since CHDK is creating the RAW file for me... IS there any way I could hack it so that it would write out all the 'blue' data where red goes and all the 'red' data where blue goes, thereby making a pre channel swapped raw file that I could work with?     

Does anyone have any ideas on how this could possibly be done, either in camera or with something like the DNG4PS2 program?  Many infrared photographers would be extremely happy if this could be achieved.

If you can compile your own version of CHDK then you might be able to simply change the setting that determines the Bayer sensor pattern in the DNG file.

This is the cam_CFAPattern value in the platform_camera.h file.

Currently it is set to 0x01000201 which means the sensor pattern is
G B
R G

If you change this value to 0x01020001 then you are telling any software that processes the file that the pattern is
G R
B G

I don't know if this will achieve the desired result; but it's worth a try.

If you aren't able to build your own version send me a personal message with an email address and I'll send you a custom build.

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)
  g5x (1.00c, 1.01a, 1.01b)


Re: RAW data restructure for Infrared photograpy?
« Reply #4 on: 08 / August / 2013, 16:33:17 »
You could hack the CFAPattern tag in the DNG to swap which pixels are interpreted as R and B. Not sure if this is what you want, but it should be straightforward to do either in camera or after the fact.

Could you please explain where to find this tag and how to modify it?  It sounds like it would work great and seems so simple.

Re: RAW data restructure for Infrared photograpy?
« Reply #5 on: 08 / August / 2013, 19:13:44 »
I tried looking at some of my DNG files with exiv2, and none of them seem to have CFA pattern entry.   it sounds like modifying the CFA pattern is exactly what I want to do though.

Re: RAW data restructure for Infrared photograpy?
« Reply #6 on: 08 / August / 2013, 19:27:05 »
I tried looking at some of my DNG files with exiv2, and none of them seem to have CFA pattern entry.   it sounds like modifying the CFA pattern is exactly what I want to do though.
philmoz is talking about changing one of the files in the CHDK source code and compiling a special version of CHDK.  Its not really something you can do by tweaking an image.  If you are not able to build your own version of CHDK (and don't want to learn), he volunteered to build one for you.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 12364
Re: RAW data restructure for Infrared photograpy?
« Reply #7 on: 08 / August / 2013, 22:33:49 »
The attached lua script can be used with chdkptp to change the cfa tag on existing DNG files.

Put the hackcfa.lua file in the directory with the other chdkptp lua files, and then enter the following in the chdkptp console
Code: [Select]
!require'hackcfa';hackcfa('input.dng','output.dng',0x01020001)
where input.dng is the name of the existing dng you want ot change, and output.dng is the name you want the modified file to be saved under. You could enter other numbers for the final parameter.

This may be more convenient than running special chdk build
Don't forget what the H stands for.


Re: RAW data restructure for Infrared photograpy?
« Reply #8 on: 09 / August / 2013, 11:06:50 »
philmoz is talking about changing one of the files in the CHDK source code and compiling a special version of CHDK.  Its not really something you can do by tweaking an image.  If you are not able to build your own version of CHDK (and don't want to learn), he volunteered to build one for you.

Actually that direction was in response to reyalp:

You could hack the CFAPattern tag in the DNG to swap which pixels are interpreted as R and B. Not sure if this is what you want, but it should be straightforward to do either in camera or after the fact.

there Is an exif tag called  Exif.Image.CFAPattern and I believe his suggestion was to modify that entry to reverse the red and blue pixels.   I would really like to see if I could that to somehow work in a batch file so I could run the thousands of previous DNG files through it and fix them all.   but when I looked at any of my DNG files with exiv2, that entry is just not there.  I'm not sure if it's really included in the file and I just can't find it or if the DNG files I created with dng4ps2 already processed the bayer data and so that was not needed anymore.

philmoz did compile a version with his recommended change in it,  (thank you very much philmoz!)  and I'm getting ready to go outside and take some test shots.. as soon as my batteries finish charging.  I'll report back on that.   

The attached lua script can be used with chdkptp to change the cfa tag on existing DNG files.

Thanks for this lua file reyalp,  I'll give it a try!  If I can get it to work, perhaps I can use it to convert my previous photos as well somehow.

For this camera, it would be great if it just always made DNG files with the red and blue reversed, as the DNG is created,  because it always needs to be done, and since it's a converted camera, it's only function is to take infrared photos.  but I would also really think it would be great to convert other dng files as I have a converted sony camera as well, and there are a lot of people taking infrared photos with other non-canon cameras and none of them (at least in the groups I am involved in)   know how to achieve the red-blue swap and still keep their raw data, and since the people involved with chdk are quite a bit more knowledgeable about programming and also the details of the DNG file structure (which baffles me)  I'm hoping to come up with a solution that could help the entire infrared community to keep their RAW files and have the red/blue swap. 

What would be great is if I could somehow come up with a program that I can run in a DOS batch file that works just like your hackcfa program...  just read in DNG's and write out converted DNG's   Perhaps I can use the information in hackcfa to learn more about how DNG files work and how to make that happen.   I'll report back on how hackcfa works as well



*

Offline reyalp

  • ******
  • 12364
Re: RAW data restructure for Infrared photograpy?
« Reply #9 on: 09 / August / 2013, 13:19:41 »
Actually that direction was in response to reyalp:
Phils response and mine were suggesting the same thing.
Quote
there Is an exif tag called  Exif.Image.CFAPattern and I believe his suggestion was to modify that entry to reverse the red and blue pixels.   I would really like to see if I could that to somehow work in a batch file so I could run the thousands of previous DNG files through it and fix them all.   but when I looked at any of my DNG files with exiv2, that entry is just not there.  I'm not sure if it's really included in the file and I just can't find it or if the DNG files I created with dng4ps2 already processed the bayer data and so that was not needed anymore.
DNG files must have a CFAPattern tag, but it is in the DNG image IFD, not in the EXIF IFD. A tool like exiftool should show it to you. In fact, I expect exiftool would let you modify it was well.
Quote
What would be great is if I could somehow come up with a program that I can run in a DOS batch file that works just like your hackcfa program...  just read in DNG's and write out converted DNG's   Perhaps I can use the information in hackcfa to learn more about how DNG files work and how to make that happen.   I'll report back on how hackcfa works as well
chdkptp can be run as a command line program (just pass some command line option other than -g), so running a batch conversion should be no problem. It would be easy to make it process every file in a directory, for example. But first, find out if this actually does what you want.

You could run the code I gave you from the command line with
Code: [Select]
chdkptp -e"exec require'hackcfa';hackcfa('input.dng','output.dng',0x01020001)"
For a batch file, you'd need to do some kind of substitution to get the input and output files name right

Quote
For this camera, it would be great if it just always made DNG files with the red and blue reversed, as the DNG is created,  because it always needs to be done, and since it's a converted camera, it's only function is to take infrared photos.
The downside of using a custom build is that if you ever want to update, you need someone to make a new custom build for you. Or learn how to do it yourself.
Don't forget what the H stands for.

 

Related Topics