Page 1 of 1

match colours from two images

Posted: 2015-11-22T11:33:58-07:00
by Magda_Ch
Hi,
I would like to match colours from two images, both represent the same object (geology outcrop) but they are taken from different angles and on first look they are totally different. Do you know if ImageMagick can fix it?

I don’t want to change size or image format I just want to received images with similar colours in the end (I would like to use them to texturing in 3d model without colour discrepancies in results).

Here is two sample images.
https://drive.google.com/folderview?id= ... sp=sharing

I am working on windows 10, and I have installed ImageMagick-6.9.2-6-Q16-x64-static.exe

Any help is much appreciate.
Magda

Re: match colours from two images

Posted: 2015-11-22T12:02:56-07:00
by snibgo
I can see by eye that the right side of a.jpg matches with the central part of b.jpg. What result do you want? What do you mean by "fix it"?

Re: match colours from two images

Posted: 2015-11-22T12:18:39-07:00
by fmw42
I think the OP wants something like my histmatch script or -remap. My histmatch does not do a good job because the histogram is limited to 256 colors. I suspect that remap may be the same at 256 colors and so might need more than 256 colors also. One would have to limit the number of colors in a.jpg (-colors), get the colormap, create a new colormap image, then use that with -remap. See http://www.imagemagick.org/Usage/quantize/#remap.

Since the OP is on Windows, see snibgo's web site, perhaps he as something similar, but with a longer histogram.

Re: match colours from two images

Posted: 2015-11-22T13:40:41-07:00
by Magda_Ch
snibgo, you have right, between images I try to keep some overlaps (about 20%). By saying 'fix it' I mean create two images with correspondence colour (i.e. grass/rock on image 'a' have same colour like grass/rock on image 'b').

fmw42 I already try to use histmatch script, resault you can see at https://drive.google.com/drive/folders/ ... jNoamVpSkE 'ab_histmatch.jpg'. They are not perfect, images have very intensive colours.
my command: $ histmatch -c RGB -L a.jpg b.jpg ab_histmach.jpg

Can you describe a bit more your idea? I should limit number of colours to 256 on image 'a' and 'b' and then use -remap? What will be the final quality of image, same as original or less?

Re: match colours from two images

Posted: 2015-11-22T14:08:57-07:00
by fmw42
Magda_Ch wrote:
Can you describe a bit more your idea? I should limit number of colours to 256 on image 'a' and 'b' and then use -remap? What will be the final quality of image, same as original or less?
It is not a very easy thing to do. You can use something like the following in Unix (sorry I do not know how to do it in windows)

Code: Select all

# get list of 2048 hex colors and put into an array
colorArr=(`convert a.jpg +dither -colors 2048 -unique-colors -depth 8 txt:- |\
tail -n +2 | sed -n 's/^.*\(#.*\) .*$/\1/p'`)
numcolors=${#colorArr[*]}

# make 1D color image (lut) of all the hex colors
str=""
for ((i=0; i<numcolors; i++)); do
color=${colorArr[$i]}
pixel="xc:'$color'"
str="$str $pixel"
done
eval 'convert '$str' +append lut.png'

# apply the lut to b.jpg to make it look more like a.jpg
convert b.jpg -remap lut.png b2.jpg
However, I am surprised to see little or no change. I think this might be due the fact that all the colors in b are only some of the colors in a. So every color in b finds a close match in a and ignores the other colors. The issue is that there is no spatial correlation being used.

I think my histmatch script might work much better if the histogram allowed more colors. But right now it is limited to 256 colors.

Re: match colours from two images

Posted: 2015-11-22T14:10:18-07:00
by snibgo
With my Windows BAT script, which uses process modules:

Code: Select all

%PICTBAT%matchHisto b.jpg a.jpg rocks_ba.jpg
The result resized down is:
Image
The magenta etc will be from colours in b that are outside the gamut of a. Something could probably be done about that.

I have load of scripts that might find features that align.

Re: match colours from two images

Posted: 2015-11-22T14:21:20-07:00
by fmw42
snibgo: Is your script processing each channel separately or using intensity like channels to process all channels together? If the former, does your script allow you to do the latter?

Re: match colours from two images

Posted: 2015-11-22T14:48:50-07:00
by snibgo
My script converts each input to Lab, runs the process module which processes each channel independently, and converts back to sRGB. It runs this command:

Code: Select all

%IMDEV%convert ^
  %INFILE% ^
  -colorspace Lab ^
  ( -clone 0 ^
    -process 'mkhisto cumul norm' ^
  ) ^
  ( %2 ^
    -colorspace Lab ^
    -process 'mkhisto cumul norm' ^
    -process 'mkhisto cumul norm' ^
  ) ^
  ( -clone 1-2 -clut ) ^
  -delete 1-2 ^
  -clut ^
  -colorspace sRGB ^
  %OUTFILE%