[SOLVED]:Is it possible to replace all colors at once?

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
batjka911
Posts: 8
Joined: 2019-02-03T11:12:43-07:00
Authentication code: 1152
Location: Kaliningrad,Russia

[SOLVED]:Is it possible to replace all colors at once?

Post by batjka911 » 2019-02-10T16:53:07-07:00

I'm use Linux.

Code: Select all

magick -version    
Version: ImageMagick 7.0.8-26 Q16 x86_64 2019-02-05 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP 
Delegates (built-in): bzlib cairo fontconfig freetype gslib heic jbig jng jp2 jpeg\
lcms lqr ltdl lzma openexr pangocairo png ps raw rsvg tiff webp wmf x xml zlib
I am trying to help my wife with such a question. It is required to replace all colors with others.
Watched this post-https://www.imagemagick.org/discourse-s ... or#p160403
but that's not my question.
Here is the picture-4.jpg

Code: Select all

identify -verbose 4.jpg
Image: 4.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 360x360+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: Palette
  Base type: Undefined
  Endianess: Undefined
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 129600
    Red:
      min: 0  (0)
      max: 255 (1)
      mean: 122.892 (0.481928)
      standard deviation: 126.946 (0.497828)
      kurtosis: -1.99531
      skewness: 0.0668521
      entropy: 0.684036
    Green:
      min: 0  (0)
      max: 217 (0.85098)
      mean: 104.608 (0.410229)
      standard deviation: 87.7199 (0.344)
      kurtosis: -1.54773
      skewness: -0.0665942
      entropy: 0.767054
    Blue:
      min: 0  (0)
      max: 255 (1)
      mean: 89.4583 (0.350817)
      standard deviation: 120.538 (0.472696)
      kurtosis: -1.60423
      skewness: 0.628771
      entropy: 0.706888
  Image statistics:
    Overall:
      min: 0  (0)
      max: 255 (1)
      mean: 105.653 (0.414325)
      standard deviation: 111.735 (0.438175)
      kurtosis: -1.74771
      skewness: 0.292876
      entropy: 0.719326
  Colors: 45
  Histogram:
      1080: (  0,  0,250) #0000FA srgb(0,0,250)
      2160: (  0,  0,253) #0000FD srgb(0,0,253)
      9720: (  0,  0,254) #0000FE srgb(0,0,254)
      2160: (  0,  1,252) #0001FC srgb(0,1,252)
      3240: (  0,  1,254) #0001FE srgb(0,1,254)
      2160: (  0,126,  0) #007E00 srgb(0,126,0)
      1080: (  0,126,  3) #007E03 srgb(0,126,3)
      1080: (  0,127,  4) #007F04 srgb(0,127,4)
      1080: (  0,128,  0) #008000 green
     35640: (  0,128,  1) #008001 srgb(0,128,1)
      1080: (  0,129,  3) #008103 srgb(0,129,3)
      1080: (  0,131,  0) #008300 srgb(0,131,0)
      1080: (  1,  0,252) #0100FC srgb(1,0,252)
      1080: (  1,  0,254) #0100FE srgb(1,0,254)
      1080: (  1,  1,255) #0101FF srgb(1,1,255)
      1080: (  2,  1,253) #0201FD srgb(2,1,253)
      1080: (  2,129,  0) #028100 srgb(2,129,0)
      1080: (250,215,  0) #FAD700 srgb(250,215,0)
      2160: (250,215,  1) #FAD701 srgb(250,215,1)
      1080: (252,  1,254) #FC01FE srgb(252,1,254)
      2160: (252,215,  2) #FCD702 srgb(252,215,2)
      3240: (252,216,  0) #FCD800 srgb(252,216,0)
      1080: (253,213,  3) #FDD503 srgb(253,213,3)
      1080: (253,214,  0) #FDD600 srgb(253,214,0)
      1080: (254,  0,  0) #FE0000 srgb(254,0,0)
      1080: (254,  0,255) #FE00FF srgb(254,0,255)
      1080: (254,  1,  0) #FE0100 srgb(254,1,0)
      1080: (254,  1,252) #FE01FC srgb(254,1,252)
      1080: (254,  2,  1) #FE0201 srgb(254,2,1)
      1080: (254,213,  0) #FED500 srgb(254,213,0)
      1080: (254,213,  1) #FED501 srgb(254,213,1)
      1080: (254,213,  7) #FED507 srgb(254,213,7)
      1080: (254,214,  2) #FED602 srgb(254,214,2)
      4320: (254,215,  0) #FED700 srgb(254,215,0)
     18360: (255,  0,254) #FF00FE srgb(255,0,254)
      1080: (255,  0,255) #FF00FF magenta
      2160: (255,213,  0) #FFD500 srgb(255,213,0)
      5400: (255,214,  0) #FFD600 srgb(255,214,0)
      2160: (255,214,  2) #FFD602 srgb(255,214,2)
      1080: (255,214,  3) #FFD603 srgb(255,214,3)
      1080: (255,214,  8) #FFD608 srgb(255,214,8)
      1080: (255,215,  0) #FFD700 gold
      2160: (255,216,  0) #FFD800 srgb(255,216,0)
      1080: (255,216,  1) #FFD801 srgb(255,216,1)
      1080: (255,217,  0) #FFD900 srgb(255,217,0)
  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)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 360x360+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 92
  Orientation: Undefined
  Properties:
    date:create: 2019-02-03T02:07:09+02:00
    date:modify: 2019-02-03T02:07:09+02:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: 8097028eaba83f2b3d903250138368e0a07b83e31ab397a27efaca56f63dcd42
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 25979B
  Number pixels: 129600
  User time: 0.020u
  Elapsed time: 0:01.000
  Version: ImageMagick 7.0.8-26 Q16 x86_64 2019-02-05 https://imagemagick.org
Is it possible to replace all colors at once?   For example with this palette.
gold on # ffbf66-this is background
green on # 08c5d1
red on # 00353f
blue on # 430c05
magenta on # d46f4d.

Although color and order is not important. I want to understand the principle itself.
And I would like the options for both versions IM.
Last edited by batjka911 on 2019-02-10T17:47:11-07:00, edited 1 time in total.

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

Re: Is it possible to replace all colors at once?

Post by snibgo » 2019-02-10T17:09:53-07:00

You can use this general pattern:

Code: Select all

magick \
  in.png \
  -fill "#012345" -opaque "#234567" \
  -fill "#543210" -opaque "#654321" \
  out.png
This replaces all pixels of "#234567" with "#012345", and so on.

Never use JPG for this type of work unless you really have to, because JPG is lossy, and "solid colours" are not solid. If you must use JPG inputs, you will also need something like "-fuzz 5%".
snibgo's IM pages: im.snibgo.com

batjka911
Posts: 8
Joined: 2019-02-03T11:12:43-07:00
Authentication code: 1152
Location: Kaliningrad,Russia

Re: Is it possible to replace all colors at once?

Post by batjka911 » 2019-02-10T17:38:03-07:00

snibgo wrote:
2019-02-10T17:09:53-07:00
You can use this general pattern:

Code: Select all

magick \
  in.png \
  -fill "#012345" -opaque "#234567" \
  -fill "#543210" -opaque "#654321" \
  out.png
This replaces all pixels of "#234567" with "#012345", and so on.

Never use JPG for this type of work unless you really have to, because JPG is lossy, and "solid colours" are not solid. If you must use JPG inputs, you will also need something like "-fuzz 5%".
I converted jpg in png. And only with the option "-fuzz 5%" everything worked fine.
Thank you very much.

Post Reply