All pastes #2003673 Raw Edit

Untitled

public text v1 · immutable
#2003673 ·published 2010-11-27 14:12 UTC
rendered paste body
#@gmic transfer_colors : _transfer_brightness={ 0 | 1 }
#@gmic : Transfer colors of the first selected image to the other ones.
transfer_colors : -skip ${1=0}
  -e[^-1] "Transfer colors of image [0] to image$?."
  -if {@#<2} -return -endif
  -v - -to_rgb[0] -to_colormode[1--1] {max(3,@{"-max_s"})} -c 0,255  # Convert all images to RGB[A]
  -repeat @# --sh[~>] 0,2 -rgb2ycbcr[-1] -rm[-1] -done               # Perform RGB[A] to YCbCr[A] conversion.
  -l[0] -s c -histogram_cumul 256,1,0,255 -a c -* 255 -endl          # Compute channel-by-channel cumulative histogram of target image.
  -repeat {@#-1} -l[0,-1]
    -if $1 -repeat 3 --sh[0,1] ~>,~> -equalize[-1] 256,0,255 -index[-1] [-2],0,0 -rm[-2,-1] -done         # Transfer brightness + colors.
    -else -repeat 2 --sh[0,1] {~>+1},{~>+1} -equalize[-1] 256,0,255 -index[-1] [-2],0,0 -rm[-2,-1] -done  # Transfer colors only.
    -endif
  -endl -mv[-1] 1 -done -rm[0]
  -repeat @# --sh[~>] 0,2 -ycbcr2rgb[-1] -rm[-1] -done               # Perform YCbCr[A] to RGB[A] conversion.
  -v +

_transfer_colors :  # Check transfer_colors performance.
  -repeat @# -l[~>] -rgb2ycbcr -s c -histogram 256,0,255 -a c -dg 300,200 -endl -done