convert makes images too red

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
TigerPaws
Posts: 4
Joined: 2017-11-24T09:49:33-07:00
Authentication code: 1152

convert makes images too red

Post by TigerPaws » 2017-11-24T16:37:51-07:00

I am a ImageMagick newbie, so excuse me if this is a dumb question!
I am converting .NEF files (.RAW files taken with a Nikon camera) to JPGs, eg: convert xyx.NEF xyz.JPG The convert process gives the images a reddish cast. See examples here:
https://www.dropbox.com/sh/gfg6ok6wfptv ... QtSpa?dl=0

Do I need to use the -channel parameter? How do I know what values to use? More basically, why is this happening?
Thanks!

User avatar
fmw42
Posts: 23855
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert makes images too red

Post by fmw42 » 2017-11-24T16:53:36-07:00

Please always provide your ImageMagick version and platform

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 23855
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert makes images too red

Post by fmw42 » 2017-11-24T17:04:50-07:00

Your file has numerous brightness and color tags set in the DNG and EXIF arguments that ImageMagick may not be using to color correct your image. Sorry, I do not do a lot of NEF or other raw image processing. So one of the photographers on this forum might help you more.

You can see those tags using

Code: Select all

identify -verbose yourimage.nef

Code: Select all

Image: /tmp/magick-8170k7WkP6T9Nno.png
  Base filename: SouthBend0070.NEF
  Format: NEF (Nikon Digital SLR Camera Raw Image File)
  Class: DirectClass
  Geometry: 6015x4022+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: 24192330
    Red:
      min: 0  (0)
      max: 48346 (0.737713)
      mean: 20396.2 (0.311226)
      standard deviation: 11337.7 (0.173002)
      kurtosis: -1.19023
      skewness: -0.133089
      entropy: 0.969986
    Green:
      min: 0  (0)
      max: 52924 (0.807568)
      mean: 16318.5 (0.249004)
      standard deviation: 10107.3 (0.154228)
      kurtosis: -0.468984
      skewness: 0.612818
      entropy: 0.942386
    Blue:
      min: 0  (0)
      max: 65535 (1)
      mean: 10209.1 (0.155781)
      standard deviation: 10049.3 (0.153342)
      kurtosis: 2.19185
      skewness: 1.55413
      entropy: 0.878006
  Image statistics:
    Overall:
      min: 65535  (1)
      max: 0 (0)
      mean: 49893.7 (0.76133)
      standard deviation: 11317.6 (0.172696)
      kurtosis: -0.765091
      skewness: 0.542425
      entropy: 0.930126
  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: 6015x4022+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: TopLeft
  Properties:
    date:create: 2017-11-24T15:57:28-08:00
    date:modify: 2017-11-24T15:57:28-08:00
    dng:Aperture: F4.2
    dng:AspectRatio: 1.495525
    dng:ChannelMultipliers: 1.566406 1.000000 1.867188 1.000000
    dng:CreateID: 1
    dng:Crop: 0 0 6015 4022
    dng:EXIFSource: exiv2 0.26
    dng:FocalLength: 66.0 mm
    dng:FocalLength35: 99.0 mm
    dng:Green: 1.132
    dng:ISOSpeed: 1000
    dng:Lens: Nikon AF-S DX VR Zoom-Nikkor 55-200mm f/4-5.6G IF-ED
    dng:Make: Nikon
    dng:MatrixInputProfile: Color matrix
    dng:Model: D3300
    dng:Orientation: 0
    dng:Rotation: 0.000000
    dng:Shutter: 1/60 s
    dng:sRGBOutputProfile: sRGB
    dng:Temperature: 3647
    dng:Timestamp: Sat Oct 10 10:41:59 2015
    dng:WB: Camera WB
    dng:WBFineTuning: 0
    exif:CFAPattern: 2, 0, 2, 0, 0, 1, 1, 2
    exif:ColorSpace: 1
    exif:Contrast: 0
    exif:CustomRendered: 0
    exif:DateTime: 2015:10:10 10:41:59
    exif:DateTimeDigitized: 2015:10:10 10:41:59
    exif:DateTimeOriginal: 2015:10:10 10:41:59
    exif:DigitalZoomRatio: 1/1
    exif:ExifOffset: 298
    exif:ExposureBiasValue: 0/6
    exif:ExposureMode: 0
    exif:ExposureProgram: 0
    exif:ExposureTime: 10/600
    exif:FileSource: 3
    exif:Flash: 16
    exif:FNumber: 42/10
    exif:FocalLength: 660/10
    exif:FocalLengthIn35mmFilm: 99
    exif:GainControl: 2
    exif:GPSInfo: 5902
    exif:GPSVersionID: 2, 3, 0, 0
    exif:ISOSpeedRatings: 1000
    exif:LightSource: 0
    exif:Make: NIKON CORPORATION
    exif:MakerNote: 78, 105, 107, 111, 110, 0, 2, 16, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 62, 0, 1, 0, 7, 0, 4, 0, 0, 0, 48, 50, 49, 49, 2, 0, 3, 0, 2, 0, 0, 0, 0, 0, 232, 3, 4, 0, 2, 0, 8, 0, 0, 0, 246, 2, 0, 0, 5, 0, 2, 0, 13, 0, 0, 0, 254, 2, 0, 0, 7, 0, 2, 0, 7, 0, 0, 0, 12, 3, 0, 0, 8, 0, 2, 0, 13, 0, 0, 0, 20, 3, 0, 0, 9, 0, 2, 0, 20, 0, 0, 0, 34, 3, 0, 0, 11, 0, 8, 0, 2, 0, 0, 0, 0, 0, 0, 0, 12, 0, 5, 0, 4, 0, 0, 0, 54, 3, 0, 0, 13, 0, 7, 0, 4, 0, 0, 0, 0, 1, 6, 0, 14, 0, 7, 0, 4, 0, 0, 0, 0, 1, 12, 0, 18, 0, 7, 0, 4, 0, 0, 0, 0, 1, 6, 0, 19,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0, 0, 176, 8, 0, 0, 147, 0, 3, 0, 1, 0, 0, 0, 4, 0, 0, 0, 149, 0, 2, 0, 5, 0, 0, 0, 42, 11, 0, 0, 150, 0, 7, 0, 112, 2, 0, 0, 48, 11, 0, 0, 151, 0, 7, 0, 166, 4, 0, 0, 160, 13, 0, 0, 152, 0, 7, 0, 33, 0, 0, 0, 70, 18, 0, 0, 153, 0, 3, 0, 2, 0, 0, 0, 192, 11, 216, 7, 157, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 158, 0, 3, 0, 10, 0, 0, 0, 104, 18, 0, 0, 163, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 164, 0, 7, 0, 4, 0, 0, 0, 48, 51, 48, 48, 167, 0, 4, 0, 1, 0, 0, 0, 114, 11, 0, 0, 168, 0, 7, 0, 49, 0, 0, 0, 124, 18, 0, 0, 171, 0, 2, 0, 16, 0, 0, 0, 174, 18, 0, 0, 176, 0, 7, 0, 16, 0, 0, 0, 190, 18, 0, 0, 177, 0, 3, 0, 1, 0, 0, 0, 4, 0, 0, 0, 182, 0, 7, 0, 8, 0, 0, 0, 206, 18, 0, 0, 183, 0, 7, 0, 30, 0, 0, 0, 214, 18, 0, 0, 184, 0, 7, 0, 172, 0, 0, 0, 244, 18, 0, 0, 187, 0, 7, 0, 8, 0, 0, 0, 160, 19, 0, 0, 191, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 192, 0, 7, 0, 8, 0, 0, 0, 168, 19, 0, 0, 0, 0, 0, 0, 82, 65, 87, 32, 32, 32, 32, 0, 65, 85, 84, 79, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, 65, 70, 45, 83, 32, 32, 0, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 145, 1, 0, 0, 0, 1, 0, 0, 222, 1, 0, 0, 0, 1, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    exif:MaxApertureValue: 41/10
    exif:MeteringMode: 5
    exif:Model: NIKON D3300
    exif:Orientation: 1
    exif:ReferenceBlackWhite: 0/1, 255/1, 0/1, 255/1, 0/1, 255/1
    exif:Saturation: 0
    exif:SceneCaptureType: 0
    exif:SceneType: 1
    exif:SensingMethod: 2
    exif:Sharpness: 0
    exif:Software: Ver.1.00 
    exif:SubjectDistanceRange: 0
    exif:SubSecTime: 50
    exif:SubSecTimeDigitized: 50
    exif:SubSecTimeOriginal: 50
    exif:TIFF-EPStandardID: 1, 0, 0, 0
    exif:UserComment: 65, 83, 67, 73, 73, 0, 0, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
    exif:WhiteBalance: 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: 6015, 4022
    png:sRGB: intent=0 (Perceptual Intent)
    png:text: 3 tEXt/zTXt/iTXt chunks were found
    png:text-encoded profiles: 1 were found
    signature: 2c77afb8c2db6f1a3c1897b3a080ade594a83abb201c4e7ab955781f32f9a8b7
    Software: UFRaw
    Source: NikonD3300
    unknown: UFRaw 0.22
  Profiles:
    Profile-exif: 5926 bytes
  Artifacts:
    filename: SouthBend0070.NEF
    verbose: true
  Tainted: False
  Filesize: 113.178MiB
  Number pixels: 24.1923M
  Pixels per second: 17.1577MB
  User time: 1.410u
  Elapsed time: 0:02.410
  Version: ImageMagick 6.9.9-23 Q16 x86_64 2017-11-12 http://www.imagemagick.org
When I run the convert, I do not get such obvious color shifts, but the image is much darker.

Code: Select all

convert NEF:SouthBend0070.NEF SouthBend0070_fred.jpg
To brighten it, you can use a log or gamma functions. Try the following (also include the NEF: suffix).

Code: Select all

convert NEF:SouthBend0070.NEF -evaluate log 5 SouthBend0070_fred3.jpg
This looks better than yours using IM 6.9.9.23 Q16 Mac OSX Sierra.

snibgo
Posts: 10709
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert makes images too red

Post by snibgo » 2017-11-25T02:10:48-07:00

The conversion seems to be using the default white balance, but you want the white balance as recorded by the camera. If dcraw is the delegate, this means adding "-w" to the dcraw command.

What version of IM, on what platform?

What delegate is reading the raw file? "-verbose" will probably say. Please show the text output from the raw command.

When you've done that, you may need to edit a line in delegates.xml.
snibgo's IM pages: im.snibgo.com

TigerPaws
Posts: 4
Joined: 2017-11-24T09:49:33-07:00
Authentication code: 1152

Re: convert makes images too red

Post by TigerPaws » 2017-11-25T13:19:01-07:00

Whoops--I am using IM 7.0.7-11 on a PC running Windows 7.
I am not sure what you mean by the "raw command" Running "convert -verbose" produces:
SouthBend0111.nef NEF 6016x4016 6016x4016+0+0 16-bit sRGB 8.53889MiB 0.749u 0:01.062
SouthBend0111.nef=>SouthBend0111b.jpg NEF 6016x4016 6016x4016+0+0 16-bit sRGB 8.53889MiB 0.764u 0:01.357

In reading through earlier posts on the forum it seems that DCRAW is something that has to be downloaded and installed, along with cjpeg. Sounds like that is no longer necessary.
Delegates.xml has the line:
<delegate decode="dng:decode" stealth="True" command="dcraw.exe -6 -W -O &quot;%u.ppm&quot; &quot;%i&quot;"/>
but I am using .NEF (which I believe is just another name for RAW)--not DNG.

User avatar
fmw42
Posts: 23855
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert makes images too red

Post by fmw42 » 2017-11-25T13:50:50-07:00

You will need to have dcraw installed. IM will call dcraw to process your deg file. Snigbo was say to use dcraw and its own arguments to do the color corrections rather than ImageMagick. Then if you find the arguments you need, then you can modify the delegates.xml file for NEF/DNG to include those arguments with the call to dcraw. DCRAW is used to process most all raw formats including DNG and NEF.

TigerPaws
Posts: 4
Joined: 2017-11-24T09:49:33-07:00
Authentication code: 1152

Re: convert makes images too red

Post by TigerPaws » 2017-11-25T14:16:34-07:00

Actually it looks like DCRaw.exe is on my machine. I just tried it, with the -v and -w parameters, but it hung, then crashed on "converting to sRGB colorspace". Maybe I need a better machine!!
I also fiddled with my delegates.xml file (changing -W to -w, adding -d) but it made no difference.
All I really want to do at this point is create a set of JPG thumbnails (Win 7 doesn't understand NEF) and I can live with the color imbalance. But I was hoping to learn IM and gain some confidence in using it.

User avatar
fmw42
Posts: 23855
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert makes images too red

Post by fmw42 » 2017-11-25T15:05:24-07:00

What was your exact IM command? What version of dcraw?

In which directory did you change the delegates.xml file? It must be in the installed file and not the file in the download directory.

Did you try my command from above?

Code: Select all

magick.exe NEF:SouthBend0070.NEF -evaluate log 7 SouthBend0070_fred3.jpg
I am using IM 7.0.7.11 Q16 Mac OSX with dcraw @9.27.0_2. It does not show any color shift as far as I can see.

TigerPaws
Posts: 4
Joined: 2017-11-24T09:49:33-07:00
Authentication code: 1152

Re: convert makes images too red

Post by TigerPaws » 2017-11-25T16:01:11-07:00

Well, I am taking the easy way out! In poking around I learned that IrfanView uses DCRaw. I have been using IrfanVIew for many years--so long that I never noticed that somewhere along the way Irfan Skiljan added batch processing. I just used it to convert ten NEF files to 10%-sized JPGs and it worked perfectly (exact color match).
I am still curious about IM and will continue to play with it, but for now I can rely on IrfanView for what I need. Thanks for your help!

Post Reply