1

I am trying to process multiple RAW DNG images by stacking them to produce 1 stacked RAW DNG image. First, I get the DNG pixel data into byte array, since DNG is digital negative, I then flipped the byte values using "~" and convert them into unsigned integer, now I calculate the average. With the average result, I flipped it back with "~" and save in "newData" byte array.

Below is the snippet on averaging 2 DNG images. The images are shot from OnePlus 3 in RAW (16MP DNG).

byte[] previousData //from previous DNG image

ByteBuffer rawByteBuffer = mImage.getPlanes()[0].getBuffer();
byte[] data = new byte[rawByteBuffer.remaining()];
rawByteBuffer.get(data); // from current DNG image
for(int i=0; i<data.length; i++){
    int currentInt = Byte.toUnsignedInt((byte) ~data[i]); 
    int previousInt = Byte.toUnsignedInt((byte) ~previousData[i]);
    int sumInt = currentInt + previousInt;
    int averageInt = sumInt/2;
    newData[i] = (byte) (~averageInt); // store average into newData
}
// save newData into storage in DNG format

However, the result image(link below) always show green tint on white color portion. Any ideas what went wrong in the process?

Here is the preview of the stacked DNG image

Here is the preview of original single DNG for reference

Wayne
  • 11
  • 1
  • This is not my strong area sorry, but a way to figure it out is: You could write a unit tests and see that the output ints are the expected values from your inputs? (to ensure you have the digital negative conversion correct). – Blundell Dec 09 '21 at 13:48
  • 1
    "Digital negative" is just metaphorical naming. DNG file contains a raw image data with additional information that allows you "developing" the image. The terms "negative" and "developing" are taken from the film era (but digital photography is much different). Flipping the byte values using "~" is not going to work. – Rotem Dec 09 '21 at 20:52
  • @Blundell Thanks, yes I tested conversion on single image and it works fine. – Wayne Dec 10 '21 at 15:06
  • @Rotem I initially tried without "~", it didn't work as expected too, it shows purple highlight on some overlapped colours. Do you mind to explain how it "develops" the image and what are the information? – Wayne Dec 10 '21 at 15:10
  • Check [Developing a RAW photo file 'by hand'](https://www.odelama.com/photo/Developing-a-RAW-Photo-by-hand/) part 1 and 2. Read the [DNG specification](https://www.adobe.com/content/dam/acom/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf). – Rotem Dec 10 '21 at 16:46

0 Answers0