timothybrooks / hdr-plus

HDR+ Implementation
MIT License
587 stars 201 forks source link

Use RAW library to achieve automatic image property detection #35

Closed brotherofken closed 5 years ago

brotherofken commented 5 years ago

Hi!

Regarding the following question in readme.md

³ I am looking into the program automaticly finding the width and height of the input photos. If you have any pointers please contact me.

I found several alternatives, that may help:

  1. Adobe DNG SDK, e.g.: https://github.com/aizvorski/dng_sdk
    1. + supports writing DNG
    2. + supports reading DNG OpCodes (e.g. GainMap for lens shading correction, WarpRectilinear for lens aberration correction, etc)
    3. - DNG only, but there are a lot of RAW2DNG converters
    4. - Has no official support for linux, but there are CMakeLists builds available on github
  2. LibRaw: https://www.libraw.org/
    1. Haven't tried, but supports a lot of proprietary RAW formats
  3. RawSpeed: https://github.com/darktable-org/rawspeed
    1. Haven't tried, but supports a lot of proprietary RAW formats

I have some experience with DNG SDK and can say that it does work well.

Also, there are LibExiv2 which allows to read metadata from DNG image format (which essentialy is TIFF), such as:

  1. image dimensions
  2. bits per sample
  3. kind of color filter array pattern
  4. camera color matrix
  5. camera white balance
  6. black, white level
  7. orientation that algorithm need for postprocessing aka finish.cpp. You could add libexiv2 in CMakeLists using the following command:
    find_package(Exiv2 REQUIRED)

But anyway, if you want to do lens shading correction, then you have to read GainMap from DNG or other raw format somehow

P.S. please feel free to edit header or issue text.

Titaniumtown commented 5 years ago

Thanks! I will look into this!

brotherofken commented 5 years ago

Actually, if input file has DNG format, then the following should be enough:

  1. Obtain libexiv2:

    apt install libexiv2-dev
  2. Somewhere in CMakeLists.txt add:

    find_package(Exiv2 REQUIRED)
  3. Then read image dimensions as follows:

    const Exiv2::Image exiv_image = Exiv2::ImageFactory::open(path);
    exiv_image->readMetadata();
    const Exiv2::ExifData exiv_data = image->exifData();
    // Now read dimensions of Exif.Image
    // Also there are chance that you have to choose another IFD, like "Exif.SubImage1.ImageWidth". 
    // That may happen if DNG contains a JPEG thumbnail
    const int width = exiv_data["Exif.Image.ImageWidth"].toLong(); 
    const int height = exiv_data["Exif.Image.ImageHeight"].toLong();
    // Also you have to read and use and consider during processing:
    // * WhiteLevel and BlackLevel
    // * CFAPattern
    // * AsShotNeutral, ColorIlluminant1/ColorIlluminant2
    // * Exif.Image.Orientation
    // * and many more

Thus topic of this issue is wider than just reading of image dimensions.

Thank you!

Titaniumtown commented 5 years ago

I am creating a prototype! Thanks for the info, very useful!

brotherofken commented 5 years ago

Hi! Any progress on this? Can I help you somehow?

brotherofken commented 5 years ago

Also, if you are looking for more bursts, I would recommend to use HDR+ dataset: https://hdrplusdata.org/

Images there have different bayer patterns, so you have to support them in demosaicing. White balance differs too.

Titaniumtown commented 5 years ago

Sorry I have been really busy lately; I am sorry I have not provided updates as I have not had time to work on it. I might possibly be able to work on it later this week!

Titaniumtown commented 5 years ago

I have been trying to implement it; no success though. Sorry for the lack of response. Any help would be appreciated!

brotherofken commented 5 years ago

Could you please publish a branch with your current progress? Any progress and even if the code not clean. Unfortunately I'm very limited in time :-( but hopefully will find time to look at the code on weekend.

Titaniumtown commented 5 years ago

It fails to build currently; but I will post it later today!

Titaniumtown commented 5 years ago

Sorry for not posting the code I think I know what is wrong with it!!

Titaniumtown commented 5 years ago

Ok I uploaded the code at: https://github.com/Titaniumtown/hdr-plus

brotherofken commented 5 years ago

Ok I uploaded the code at: https://github.com/Titaniumtown/hdr-plus

https://github.com/timothybrooks/hdr-plus/pull/36

brotherofken commented 5 years ago

Thank you for fast merge, @Titaniumtown !

Also, there are imperfection in my implementation. I do not crop 'masked pixels' from RAW, and now they appear in the output. :-(

The problem is located here: https://github.com/timothybrooks/hdr-plus/blob/master/src/InputSource.cpp#L34

I'll fix that and make another PR shortly.

Titaniumtown commented 5 years ago

Bump! Are you going to make a pull request?

brotherofken commented 5 years ago

Oh, sorry for that. :-( I'll try to look at this on a weekend. The thing is to copy pixels according to ActiveArea Raw tag.