Menu

Canon CR2 > ASTAP > FITS conversion – FITS Header errors

2021-10-21
2021-10-22
  • Tom Oskar Ortleb

    Hi Han,

    when having trouble stacking my data with ASTAP and getting unexpected (bad) results, I usually look into my data – because often enough the error sits in front of the screen ...

    Yesterday I discovered some wrong FITS header data after ASTAP's conversion from Canon CR2 raw to FITS:

    FOCALLEN = "000...2159" >>> should be "135"
    CAMERA = "000...135" >>> should probably be "Canon"
    BAYERPAT = "GRBG" >>> should be "RGGB"

    These are important values and I fear wrong setting irritate ASTAP when processing!?

    Best regards,
    too

     
  • han.k

    han.k - 2021-10-21

    Hello Tom,

    The keyword FILT-PAT comes from the included RAW conversion program unprocessed_raw. It is a modified version of the original Libraw unprocessed_raw. The modified version can create directly a FITS file.

    BAYERPAT is not written by ASTAP if I remember well. But it is the same as FILT-PAT and wrong for Cannon.

    To check what wrong I would need one of your .CR2 files. Can you attach one? Then I can trace what went wrong and if it is in the Libraw code or in my unprocessed_raw modification.

    I have tested a .CR2 file here. And Bayer pattern looks okay. See attached.

    Regards, Han

     
    • Tom Oskar Ortleb

      Sorry for the confusion concerning CFA pattern – actually the Canon EOS 7D used for this image set has a GBRG CFA. Obviously, I never looked it up for this body an my two other Canon DLSRs have what I had in mind: an RGGB CFA.

      But what about the false FOCALLEN setting – it is correct in the RAWs (135mm f/2.0)? Seems that FOCALLEN's true value is stored as CAMERA value (000...135).

       

      Last edit: Tom Oskar Ortleb 2021-10-21
  • han.k

    han.k - 2021-10-21

    The focallen is just coming out of the Libraw routine. I have no idea how the DSLR knows it but I assume it only works with smart Cannon lens.

    Best is to check one of your raws with a utility raw-identify of Libraw and check if it reports the same. If this utility is reporting correctly, I assume I can correct it in the modified conversion program

    Usage:
    raw-identify -v 1.cr2

    Then you get a lot of data like:

    ISO speed: 1600
    Shutter: 120.0 sec
    Aperture: f/0.0
    Focal length: 50.0 mm
    Camera temperature: 17.00┬░ C
    Flash exposure compensation: 0.00 EV
    Embedded ICC profile: no
    Number of raw images: 1
    Thumb size: 5616 x 3744
    Full size: 5792 x 3804
    Raw inset, width x height: 5616 x 3744 left: 168 top: 56
    Aspect: 3:2
    Image size: 5634 x 3752
    Output size: 5634 x 3752
    Image flip: 0
    Canon record mode: 7, CR2+JPEG
    SensorWidth = 5792
    SensorHeight = 3804
    SensorLeftBorder = 168
    SensorTopBorder = 56
    SensorRightBorder = 5783
    SensorBottomBorder = 3799
    Raw colors: 3
    Filter pattern: GBRGGBRGGBRGGBRG
    Canon makernotes, ChannelBlackLevel: 1022 1022 1021 1020
    Highlight linearity limits: 16383 16383 16383 16383

    https://www.libraw.org/download

    Or just give me a raw and I will check it here with the Windows version of Libraw

    Regards, Han

     
    • Tom Oskar Ortleb

      Didn't know I had raw-identify already on board – thanks Linux! – and thus learned something new today. Here is the output of one of the Canon 7D RAWs in question:

      Filename: IMG_7151.CR2
      Timestamp: Sun Oct 17 04:09:26 2021
      Camera: Canon EOS 7D ID: 0x80000250
      Normalized Make/Model: =Canon/EOS 7D= CamMaker ID: 8, Canon
      Body#: 0680509900 Lens#: DJP16122 Owner: Frank Stefani
      
      EXIF:
          MinFocal: 135.0 mm
          MaxFocal: 135.0 mm
          MaxAp @MinFocal: f/2.0
          MaxAp @MaxFocal: f/2.0
          CurFocal: 135.0 mm
          MaxAperture @CurFocal: f/0.0
          FocalLengthIn35mmFormat: 0 mm
          LensMake: 
          Lens: Samyang 135mm f/2 ED UMC
      
      
      Makernotes:
          DriveMode: 0
          FocusMode: 3
          MeteringMode: 3
          AFPoint: 0
          ExposureMode: 7
          ExposureProgram: -1
          ImageStabilization: -1
          CameraFormat: 1, APS-C
          CameraMount: 5, Canon EF
          LensID: 0 0x0
          Lens: Samyang 135mm f/2 ED UMC
          LensFormat: 0, Unknown
          LensMount: 5, Canon EF
          FocalType: 0, Undefined
          LensFeatures_pre: 
          LensFeatures_suf: 
          MinFocal: 0.0 mm
          MaxFocal: 0.0 mm
          MaxAp @MinFocal: f/0.0
          MaxAp @MaxFocal: f/0.0
          MinAp @MinFocal: f/0.0
          MinAp @MaxFocal: f/0.0
          MaxAp: f/0.0
          MinAp: f/0.0
          CurFocal: 135.0 mm
          CurAp: f/2.0
          MaxAp @CurFocal: f/0.0
          MinAp @CurFocal: f/0.0
          TeleconverterID: 0
          Teleconverter: 
          AdapterID: 0
          Adapter: 
          AttachmentID: 0
          Attachment: 
      
      ISO speed: 800
      Shutter: 60.0 sec
      Aperture: f/2.0
      Focal length: 135.0 mm
      Camera temperature:  16.00° C
      Flash exposure compensation: 0.00 EV
      Embedded ICC profile: no
      Number of raw images: 1
      Thumb size:  5184 x 3456
      Full size:   5360 x 3516
      Raw inset, width x height: 5184 x 3456 left: 168 top: 56
      Aspect: Other
      Image size:  5202 x 3464
      Output size: 5202 x 3464
      Image flip: 0
      Canon record mode: 6, CR2
      SensorWidth          = 5360
      SensorHeight         = 3516
      SensorLeftBorder     = 168
      SensorTopBorder      = 56
      SensorRightBorder    = 5351
      SensorBottomBorder   = 3511
      Raw colors: 3
      Filter pattern: GBRGGBRGGBRGGBRG
      Canon makernotes, ChannelBlackLevel: 2047 2047 2048 2048
      Highlight linearity limits: 15094 15094 15094 15094
      Makernotes WB data:               coeffs                  EVs
        As shot                   2140 1024 1165 1024    1.06  0.00  0.19  0.00
        Daylight                  2180 1024 1502 1024    1.09  0.00  0.55  0.00
        Tungsten (Incandescent)   1547 1024 2265 1024    0.60  0.00  1.15  0.00
        Flash                     2399 1024 1371 1024    1.23  0.00  0.42  0.00
        Cloudy                    2346 1024 1378 1024    1.20  0.00  0.43  0.00
        Shade                     2527 1024 1271 1024    1.30  0.00  0.31  0.00
        Cool White Fluorescent    1931 1024 2131 1024    0.92  0.00  1.06  0.00
        Illuminant A              1547 1024 2265 1024    0.60  0.00  1.15  0.00
        Camera Measured           1571 1023 1004 1023    0.62  0.00 -0.03  0.00
      Speicherzugriffsfehler (Speicherabzug geschrieben)
      

      Strangely raw-identify core dumped (last line) ....

      Regards,
      Tom

      **EDIT: ** Sent you Download link to this exact same RAW (IMG_7151.CR2)

       

      Last edit: Tom Oskar Ortleb 2021-10-21
  • han.k

    han.k - 2021-10-21

    Hello Tom,

    Okay Libraw works :)
    Now is the question why the modified unprocessed_raw conversion is making 2159 from 135 mm.
    Maybe I have to update it to the latest Libraw code. Can you attach one raw here or upload it somewhere like
    https://ufile.io/
    and give me the link? Then I can use it for testing.

    Han

     
  • han.k

    han.k - 2021-10-21

    Ok have received the link to the CR2. Thanks.

     

    Last edit: han.k 2021-10-21
  • Tom Oskar Ortleb

    Hello Han,

    thanks for your great and fast support once more!

    I installed the updated the ASTAP deb package and put unprocessed_raw-astap in /usr/local/bin. First I tried 4 of the Canon 7D RAW files, one of which you got from me yesterday. After "Analyze and organise images" the image dimensions differ from the true dimensions:

    exiftool -imagesize IMG_7031.CR2 
    Image Size                      : 5184x3456
    

    In ASTAP the Width and Height columns report: 5202x3464 ... which is a bit more.

    Don't know if this might have side effects but I would feel safer when these values were identical.

    Best regards,
    Tom

     
  • han.k

    han.k - 2021-10-22

    Yes the dimensions reported are pretty weird. In the Windows photo-viewer I get also 5184x3456, but comparing with the ASTAP result their about 9 pixels missing on both sides. But these pixels are fully functional and contain imaged stars. So it would be a waste not to use them. :) You can even extract more pixels but they are black and used for black level reporting but they confuse ASTAP background detection.

    You can extract all sensor pixels as follows:

    unprocessed_raw-astap ./IMG_7151.CR2
    or
    unprocessed_raw ./IMG_7151.CR2

    This creates a .pgm file you can open in ASTAP. See attached. A assume/guess the bright pixels on the top contain some secret magic binary code.

    Only the unprocessed_raw-astap modified can generate fits files. That avoids the intermediate .pgm conversion step.

    Regards, Han

    Thumb size: 5184 x 3456
    Full size: 5360 x 3516
    Raw inset, width x height: 5184 x 3456 left: 168 top: 56
    Aspect: Other
    Image size: 5202 x 3464
    Output size: 5202 x 3464
    Image flip: 0
    Canon record mode: 6, CR2
    SensorWidth = 5360
    SensorHeight = 3516
    SensorLeftBorder = 168
    SensorTopBorder = 56
    SensorRightBorder = 5351
    SensorBottomBorder = 3511

     
    • Tom Oskar Ortleb

      Seems raw-identify interpretation is irritating or accessing the imaging dimensions via an unsuitable tag:

      % raw-identify -v IMG_7031.CR2 
      
      Filename: IMG_7031.CR2
      Timestamp: Sun Oct 17 02:59:11 2021
      Camera: Canon EOS 7D ID: 0x80000250
      ...
      Thumb size:  5184 x 3456     
      Full size:   5360 x 3516
      Raw inset, width x height: 5184 x 3456 left: 168 top: 56
      Aspect: Other
      Image size:  5202 x 3464
      Output size: 5202 x 3464
      ...
      Canon record mode: 6, CR2
      SensorWidth          = 5360
      SensorHeight         = 3516
      SensorLeftBorder     = 168
      SensorTopBorder      = 56
      SensorRightBorder    = 5351
      SensorBottomBorder   = 3511
      Raw colors: 3
      Filter pattern: GBRGGBRGGBRGGBRG
      

      I believe the tag Raw inset describes the imaging area best: 5184 x 3456. This is the reported dimension all image processing software (darktable, Gimp, XnView, EOM, gwenview, ...) show as well as exiftool and others. This is also Canon's official technical information for the Canon EOS 7D.

      The tag Thumb size irritates as a thumb[nail] image is usually the small JPEG preview image embedded in the RAWs. raw-identify reports it the same size as the full imaging dimension.

      So, the cleanest (and clearest) access would probably be via the Raw inset tag – which already and correctly implies what it is referring to.

      Hope this helps,
      Tom

       

      Last edit: Tom Oskar Ortleb 2021-10-22
  • han.k

    han.k - 2021-10-22

    I updated the LibRaw library to the master. It was a little struggle with GitHub. It doesn't change anything in unprocessed_raw for you.
    It was also a struggle to change the C language code. At the moment I don't want to change it. All the pixels in range 5202x3464 are working and functional and I hadn't any problem with unprocessed_raw program since March. So I want to keep it for the moment. Other things to do.

    Regards, Han

     
    • Tom Oskar Ortleb

      I certainly can live with the bigger pixel dimensions. Just wanted to make sure no side effects (or worse) could appear due to different dimensions.

      In ASTAP, the extended pixel dimension (seem to) produce transparent red and blue borders around the stacked final image. How can we get rid of it and use the pixels covered by these borders?

      Sidenote: Today I learned something new: raw-identify and unprocessed_raw-astap – thanks for your explanation.

      Regards,
      too

       
  • han.k

    han.k - 2021-10-22

    As a last action I will add this:

    Canon makernotes, ChannelBlackLevel: 2047 2047 2048 2048
    Highlight linearity limits: 15094 15094 15094 15094

    Good for SQM measurement and bitdepth=14

     
  • han.k

    han.k - 2021-10-22

    I believe the tag Raw inset describes the imaging area best: 5184 x 3456.

    I looked to the following formats:
    .CR3
    . ARW
    . NEF
    .PEF

    Pentax doesn't support Raw inset. This makes it more complicated.

     
  • han.k

    han.k - 2021-10-22

    In ASTAP, the extended pixel dimension (seem to) produce transparent red and blue borders around the stacked final image. How can we get rid of it and use the pixels covered by these borders?

    That should be due stacking and small difference in position and not due to the extra pixels. If not please tell me. To remove I normally use the popup menu option "remove borders".

    I have added to unprocessed_raw-astap the pedestal and maximum values so this exercise has a positive result. It will be released with next version Now I will focus on some other improvements.

    Regards, Han

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.