CR2 RAW file conversion

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Post a URL to one of your CR2 images so we can download and reproduce the problem.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Try the following command:
  • convert cr2:IMG_9459.CR2 image.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

CR2 pretends to be a TIFF image buts its not. The image magic number overrides the image extension so ImageMagick thinks its a TIFF based on the magic number. By prepending cr2: you are telling ImageMagick to bypass the magic number and explicitly treat the image as CR2.

The image appears dark because the image pixels are linear. Use a color profile to adjust the colors.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

For color conversion you need two color profiles, a linear one and a sRGB one. The linear profile tells the profiler the original colorspace is linear and the second profile tells the profiler to convert the colorspace to sRGB. If you don't want to bother, use the dcraw program. It has a auto white balance option that will give you the results you're looking for (non-linear sRGB).
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: CR2 RAW file conversion

Post by magick »

Its always best to see if your command works with the latest ImageMagick release. Otherwise post a URL to one of your images and the command you used to convert it and a description of the problem. We will see if we can reproduce the problem and offer a fix if we can.
sandy.ps4
Posts: 8
Joined: 2015-10-22T12:55:30-07:00
Authentication code: 1151

Re:

Post by sandy.ps4 »

magick wrote:For color conversion you need two color profiles, a linear one and a sRGB one. The linear profile tells the profiler the original colorspace is linear and the second profile tells the profiler to convert the colorspace to sRGB. If you don't want to bother, use the dcraw program. It has a auto white balance option that will give you the results you're looking for (non-linear sRGB).
I bumped into this conversation looking for methods to improve RAW file conversion using URFraw. Currently I'm getting dark images when converting from CR2 and ORF formats to PNG. Could you you please explain your response with an example command? Here are you talking about -colorspace or -profile option in ImageMagick?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: CR2 RAW file conversion

Post by snibgo »

Instead of trying to explain one side of a ten-year-old conversation, let's start again.
sandy.ps4 wrote:Currently I'm getting dark images ...
Its's probably best to supply a CR2 file you are having problems with.
snibgo's IM pages: im.snibgo.com
sandy.ps4
Posts: 8
Joined: 2015-10-22T12:55:30-07:00
Authentication code: 1151

Re: CR2 RAW file conversion

Post by sandy.ps4 »

snibgo wrote:Instead of trying to explain one side of a ten-year-old conversation, let's start again
.

Yes, we can start afresh.

This is the command I'm using:

Code: Select all

convert E1DXINBI003200.CR2 -colorspace RGB -resize 800x600 -colorspace sRGB out.png
I'm getting similarly dark image as output with this command as well:

Code: Select all

convert E1DXINBI003200.CR2 out.png
The sample input CR2 file can be found here - http://www.imaging-resource.com/PRODS/c ... 00.CR2.HTM
Obtained output image is: Image

I'm using a MAC OS X (10.11.2) and ImageMagick Version is 6.9.2-4.

Result of

Code: Select all

identify -verbose E1DXINBI003200.CR2
is:

Code: Select all

Image: /var/tmp/magick-90560_Lk5Ye9ZlrYu.png
  Base filename: E1DXINBI003200.CR2
  Format: CR2 (Canon Digital Camera Raw Image Format)
  Class: DirectClass
  Geometry: 5218x3482+0+0
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 16-bit
  Channel depth:
    red: 16-bit
    green: 16-bit
    blue: 16-bit
  Channel statistics:
    Pixels: 18169076
    Red:
      min: 0 (0)
      max: 65535 (1)
      mean: 19171.6 (0.29254)
      standard deviation: 11323.9 (0.172791)
      kurtosis: -1.07912
      skewness: 0.0154432
      entropy: 0.939262
    Green:
      min: 0 (0)
      max: 65535 (1)
      mean: 18783.7 (0.286622)
      standard deviation: 10823.5 (0.165157)
      kurtosis: -1.08437
      skewness: -0.0199694
      entropy: 0.934749
    Blue:
      min: 0 (0)
      max: 65535 (1)
      mean: 15308 (0.233584)
      standard deviation: 10115.7 (0.154355)
      kurtosis: -0.61752
      skewness: 0.323215
      entropy: 0.913758
  Image statistics:
    Overall:
      min: 0 (0)
      max: 65535 (1)
      mean: 17754.4 (0.270915)
      standard deviation: 10765.8 (0.164275)
      kurtosis: -0.876524
      skewness: 0.127388
      entropy: 0.929256
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 5218x3482+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2016-01-28T09:59:15-06:00
    date:modify: 2016-01-28T09:59:15-06:00
    dng:Aperture: F/4.0
    dng:AspectRatio: 1.498564
    dng:ChannelMultipliers: 1.171875 1.000000 2.456055 1.000000
    dng:CreateID: 1
    dng:Crop: 0 0 5218 3482
    dng:EXIFSource: DCRaw
    dng:ExposureNorm: 37925
    dng:FocalLength: 70.0 mm
    dng:Green: 1.056
    dng:ISOSpeed: 3200
    dng:Make: Canon
    dng:MatrixInputProfile: Color matrix
    dng:Model: EOS-1D X
    dng:Orientation: 0
    dng:Rotation: 0.000000
    dng:Shutter: 1/98.7 s
    dng:sRGBOutputProfile: sRGB
    dng:Temperature: 2679
    dng:Timestamp: Thu Aug 30 14:32:49 2012
    dng:WB: Camera WB
    dng:WBFineTuning: 0
    png:IHDR.bit-depth-orig: 16
    png:IHDR.bit_depth: 16
    png:IHDR.color-type-orig: 2
    png:IHDR.color_type: 2 (Truecolor)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 5218, 3482
    png:sRGB: intent=0 (Perceptual Intent)
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    signature: 67510472971e6a8eee12420eb6d639bb8eb216f115a8f3d1959c00adb7dfcedf
    Software: UFRaw
    Source: CanonEOS-1D X
  Artifacts:
    filename: E1DXINBI003200.CR2
    verbose: true
  Tainted: False
  Filesize: 94.66MB
  Number pixels: 18.17M
  Pixels per second: 189.26GB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.2-4 Q16 x86_64 2015-10-11 http://www.imagemagick.org
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: CR2 RAW file conversion

Post by snibgo »

I don't know Ufraw and its options. I get a much lighter result from my usual converter, which is dcraw.

If I take your output and force it to an RGB->sRGB conversion, I get pretty much the same result as from dcraw.

Code: Select all

convert out.png -set colorspace RGB -colorspace sRGB s.png
So I conclude that Ufraw is giving you a linear RGB output, even though the file claims a gamma of 0.454545. I suggest you "-set colorspace RGB -colorspace sRGB" to correct it.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: CR2 RAW file conversion

Post by magick »

As snibgo recommends, use this command:
  • convert E1DXINBI003200.CR2 -set colorspace RGB -resize 800x600 -colorspace sRGB out.png
sandy.ps4
Posts: 8
Joined: 2015-10-22T12:55:30-07:00
Authentication code: 1151

Re: CR2 RAW file conversion

Post by sandy.ps4 »

Thanks snibgo and magick.

Code: Select all

convert E1DXINBI003200.CR2 -set colorspace RGB -resize 800x600 -colorspace sRGB out.png
is giving an output that is much lighter. It's better than the earlier dark image though. I'll try some of the options provided by UFRaw and update it here if I get any success. Thanks.
jose.sanpedro
Posts: 14
Joined: 2015-02-10T11:30:35-07:00
Authentication code: 6789

Re: CR2 RAW file conversion

Post by jose.sanpedro »

i have the same problem here, any update on this? thanks!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: CR2 RAW file conversion

Post by Bonzo »

Have you tried the code recommended?

I had the problem when IM used to use UFRAW and changed a setting in the delegates.xml file. The settings are not the same for dcraw.
You can create your own setting for use of CR2 in the delegates file - you will have to search for the post discussing it here on the forum.
jose.sanpedro
Posts: 14
Joined: 2015-02-10T11:30:35-07:00
Authentication code: 6789

Re: CR2 RAW file conversion

Post by jose.sanpedro »

i tried, but the result is not good. image is dark and colors do not match with the original image.

i got better results with this

Code: Select all

dcraw -v -6 -A 2000 2000 1000 1000 -T -O foto3.jpg foto.cr2
still darker but definitely better...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: CR2 RAW file conversion

Post by snibgo »

jose.sanpedro wrote:image is dark and colors do not match with the original image.
How do you know?
snibgo's IM pages: im.snibgo.com
Post Reply