Modifying raw image data for experiments

Started Apr 5, 2021 | Discussions thread
OP Horshack Veteran Member • Posts: 9,769
Re: Matlab Hack
1

Jack Hogan wrote:

Good one Horshack. It's not as elegant as your approach but for reference I've been using the following hack in Matlab via Adobe DNG Converter to achieve the same objective (don't know about Octave).

1) Convert the original raw file to DNG with Adobe's DNG Converter, Uncompressed option ticked, and place it in the working directory. Then read the raw data directly into Matlab

t = Tiff(fileName,'r');
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
cfa = read(t);
close(t);

2) Modify the raw data in array cfa as desired while ensuring that at the end it is still the same size and in its native uint16 format. Then write it back to the DNG file above

t = Tiff(fileName,'r+');
setSubDirectory(t,offsets(1));
t.write(cfa)
close(t);

3) Now open the modified DNG file in the raw converter of choice. The simple code above does not update checksums etc. so for instance PS ACR complains that the file appears to be damaged but opens it fine anyways.

Jack

Thanks Jack. My next step described in the OP was to find a way to do in-place replacement of data in the DNG and your examples set me on the right track. Octave doesn't have that TIFF library but all the info I need to find the raw data inside the DNG is contained in the EXIF so I'll be invoking exiftool to extract the offsets/lengths and then doing a straight binary read inside Octave/Matlab script to pull the data in. I should be able to fixup the DNG checksum as well - that is available via the NewRawImageDigest EXIF tag and is an MD5 hash of the raw data. Or it might just be easier to just remove that EXIF tag entirely so the MD5 doesn't have to be recalculated. I'll post the resulting code when I have it done, probably within a few days as time permits.

Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark MMy threads
Color scheme? Blue / Yellow