How to batch convert images to (s)RGB with profile?

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
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

How to batch convert images to (s)RGB with profile?

Post by mhulse »

Code: Select all

Version: ImageMagick 6.9.6-5 Q16 x86_64 2016-11-15 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
I have hundreds of images taken with various digital cameras and potentially some scanned images.

I would like to "normalize" their colorspaces and give them one profile.

I am not very concerned about minor color shifting. It's more important to me to have one consistent colorspace (RGB?) and assign a matching profile.

So far, I am converting images using:

Code: Select all

convert \
images/* \
-strip \
-colorspace RGB \
+profile "icm" \
output/
Can anyone show me how to properly add a color profile?

I have downloaded color profiles from Adobe, and I am not sure which one to pick:

AdobeRGB1998.icc
AppleRGB.icc
ColorMatchRGB.icc

Question: Which should I pick?

I am assuming that all I need to do is:

Code: Select all

convert \
images/* \
-strip \
-colorspace RGB \
+profile "icm" \
-profile /path/to/XXXXXXX.icc
output/
The docs say (http://www.imagemagick.org/Usage/formats/#color_profile):
The first "-profile" then given, is the input profile.
The second "-profile" given, is the output profile.
Question: Do I need to worry about providing an output profile? Should the output and input profiles be the same?
Last edited by mhulse on 2016-12-04T20:57:42-07:00, edited 1 time in total.
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Re: How to batch convert images to (s)RGB with profile?

Post by mhulse »

Code: Select all

convert \
images/* \
-strip \
-colorspace RGB \
+profile "icm" \
-profile /path/to/AdobeRGB1998.icc
output/
Gives me:

Code: Select all

$ identify -verbose crop/test.jpg
Image: crop/test.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 2622x2660+0+0
  Resolution: 304x304
  Print size: 8.625x8.75
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Pixels: 6974520
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 117.87 (0.462235)
      standard deviation: 84.8192 (0.332624)
      kurtosis: -1.38112
      skewness: 0.294373
      entropy: 0.945172
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 78.9055 (0.309433)
      standard deviation: 56.8595 (0.222978)
      kurtosis: -0.0066443
      skewness: 0.896965
      entropy: 0.936543
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 53.8117 (0.211026)
      standard deviation: 59.8428 (0.234678)
      kurtosis: 0.434729
      skewness: 1.17056
      entropy: 0.869765
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 83.529 (0.327565)
      standard deviation: 68.3337 (0.267975)
      kurtosis: 0.415243
      skewness: 1.03065
      entropy: 0.91716
  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: 2622x2660+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 100
  Orientation: Undefined
  Properties:
    date:create: 2016-12-04T19:52:42-08:00
    date:modify: 2016-12-04T19:52:42-08:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x1,1x1,1x1
    signature: e2848179e7eeeef1fef7b9fa486027896f3ed1ddad526858ceddc3faa8288be1
  Artifacts:
    filename: crop/test.jpg
    verbose: true
  Tainted: False
  Filesize: 4.088MB
  Number pixels: 6.975M
  Pixels per second: 43.59MB
  User time: 0.150u
  Elapsed time: 0:01.159
  Version: ImageMagick 6.9.6-5 Q16 x86_64 2016-11-15 http://www.imagemagick.org
I don't see an entry for "profile". Does that mean my profile assignment didn't work?
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to batch convert images to (s)RGB with profile?

Post by fmw42 »

What is your IM version and platform?

I do not recommend using -colorspace and a profile together. It does not give the best results. (Besides -colorspace RGB converts to linear color --- sRGB is correct).

You should only use profiles. You will need to test if you have a profile or not in the image (do not use -strip). Then if colorspace is RGB, then add -profile .../sRGB.icc. If RGB and already sRGB.icc, then nothing. If CMYK and no profile, then add a -profile .../USWebCoatedSWOP.icc and -profile .../sRGB.icc. If CMYK and it has a profile, then just add -profile .../sRGB.icc.

You can find out what profiles using -format "%[profiles]" and %[profile:icc] and %[profile:icm].

This takes a bit of coding to make conditional and depends upon your OS.

But this is the best way to do it. Each one has to be tested separately. So you need to write a script loop over all your images.


If you do not want to do it this way, then try

Code: Select all

convert \
images/* \
-colorspace sRGB \
-strip \
-profile /path/to/sRGB.icc \
output/someimage.suffix
Note that wild card input will not create the same name on output. There can be only one output name specified. So with someimage.suffix it will either be one image with multiple layers or multiple images named someimage-0.suffix someimage-1.suffix, etc.

sRGB.icc is the most common profile for viewing on different systems and devices

If you need to have the output the same name as the input, then use mogrify rather than convert. See http://www.imagemagick.org/Usage/basics/#mogrify

Create a new output directory to save your results, so you do not write over the originals. Then change directories to your input directory, then run

Code: Select all

mogrify -path path2newdirectory -colorspace sRGB -strip -profile /path/to/sRGB.icc *
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Re: How to batch convert images to (s)RGB with profile?

Post by mhulse »

Wow! Thanks so much for the help Fred, I really appreciate it!!!!

Excellent tips!

I will take a stab at writing a script to do this, like you suggested.

If I make anything worthy of sharing, I will post back here with the source.

Thanks a billion for all the details. I'm going to experiment and may return with more related questions.

Also, I updated my first question with my IM version information. I always forget to add that. I am going to see if I can put that in my signature. :)
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
Post Reply