How to create synthetic RAW image?

Thanks for the suggestion. I have done that too.

BTW not sure who should be notified about this but all email notifications sent by this forum end up in the Spam folder in Gmail. When looking at the headers I see that SPF: softfail and there are no DKIM and DMARC records which is obviously the reason. I hope someone who takes care of this will look into it.

This is too vague. If you simply want the mosaiced image, then it’s trivial (e.g creation of DNG is pretty simple). If you want to generate the whole as-if camera raw, then it could be as complicated as acquiring a camera and messing with it’s electronics and firmware in order to trick it into compressing your data into the camera-specific compression/etc.

I am willing to be able to control the hardware WB (uniwb) add noise or not, generate particular pixel patterns, gradients and other things, and obviously that should be mosaiced and linear so that it is like a real raw. I am not looking to simulate the electronics of a particular camera body but rather (as explained) to create data free from these particular influences (which we usually consider imperfections).

Do you know how to do this?

Well, if you can generate the data, containering it into DNG is trivial

Thanks but I haven’t touched C code for 15 years, so I am not quite sure what to do with that :slight_smile: If you can explain how to turn this into executable code hopefully I may give it a try. (I am on Linux)

You could create a DNG file using ExifTool and ImageMagick/GraphicsMagick. If you want it mosaiced, I think G’MIC has a filter.
http://rawpedia.rawtherapee.com/Film_Simulation#Advanced_-_Identity_DNG

Thanks. That’s interesting and sounds easy. But after running the 3 command lines and opening the resulting DNG in RawTherapee it looks strange (as if wrong):

Do you have any idea why? (I haven’t applied any G’MIC filter)

G’MIC does have a filter, -rgb2bayer. Go here:

http://gmic.eu/reference.shtml

Search for ‘rgb2bayer’. Doesn’t describe specifically what the transform is, but would be a good start.

George has an equivalent thread going at dpreview. Based on the discourse there, the workflow that makes sense to me would be:

  1. Make the desired synthetic image in whatever drawing program, save as TIFF
  2. Use G’MIC to do the ‘reverse-engineering’ to a raw:
  • de-scale
  • white/black point
  • rgb2bayer
  • save as TIFF
  1. Maybe use exiftool to write the TIFF into the image array of a .DNG (I’m less familiar with this use of exiftool)

Yes, quite a lot of words on dpreview but still no clear methodology.

What is de-scale and white/black point? I have never used G’MIC but looking at the online filter gallery of G’MIC I don’t see those.

Also how do you write the TIFF to DNG? See above what happens when I used exiftool for this.

Works fine here:

1 Like

de-scale: The image you create in whatever program will contain pixel values scaled to the full extent of the data type, e.g., 0-255 for 8-bit values, accommodating the behavior of human vision. The raw image from a camera looks dark to the human eye because the sensor records the light values linearly, e.g., white in a raw I just opened without applying processing is 64,64,64 in a 0-255 extent. So, you’ll need to essentially apply ‘reverse-gamma’ to the synthetic image, where 2.2 is nominally the gamma applied when raw/linear is converted to sRGB, so do the inverse. G’MIC may be able to do this with -adjust_colors, which has a gamma input.

black/white point: you may not have to do this for a synthetic image, if the reverse gamma does what I think it should.

Generally, G’MIC is the tool I believe to be most suited to your needs, but like any powerful tool, you’ll have to learn it. The documentation is a bit obtuse, but it’s cheap to craft a command, run it, and see what it does. Also, David Tschumperlé, the primary programmer behind G’MIC, posts here and would probably be very happy to answer specific questions about it.

Okay, try this:

gmic [input_image] -mul 0.25 -rgb2bayer 0 -o [output_image]

-mul seems to do the proper scaling.

Edit: still not right, still need to apply the gamma:

gmic [input_image] -mul 0.25 -adjust_colors 0,0,-100 -rgb2bayer 0 -o [output_image]

There, that produces a reversed image with a histogram approximate to that of the raw data.

How did you do that? Here is a screen recording showing what exactly I do:

https://goo.gl/BvSEY9

Thanks Glenn. Could you just clarify please about input and output, i.e. is the input_image the clean TIFF which I create manually in Photoshop and is output_image a TIFF or DNG?

ETA: I tried both. If I set the output to be a .dng file - RT shows nothing, blank. If it is .TIFF which I convert after that using exiftool - it looks like this:

One more thing which I notice (and seen on the video I posted): there is no way to select demosaic method on any of the DNG files generated this way. RT simply doesn’t have this menu for these files.

That means the data is already demosaiced or is not detected as raw data.

Input is the TIFF created in the drawing program. Output is also TIFF, with the intent being to use that to insert the image array into a DNG or other raw format file.

Others seem to have the chops to help with the DNG insertion; I’ve played with it a bit with no luck.

Why? I am following the instructions given here.

What happens when you do what I do in the video and when you add your command before creating the DNG with exiftool? Why doesn’t RT detect this mosaic?

Don’t know! But if the demosaic methods in rt are not available, it’s a clear indicator that the data is already demosaiced.

Actually it is there when I zoom the file generated through Glenn’s method but I suppose it is not treated as mosaiced for some other reason. Is it not necessary to somehow include in DNG (metadata or otherwise, I have no idea) that the data is mosaiced? Perhaps that would tell the raw converter how to approach it properly.