I had a mind to write a script to perform this... and actually did so (code is in spoiler below), however, it would seem that the Palette Map plug-in does not properly handle palettes with more than 256 colors; so my script does not work. I am only including it as an example of how
not to do it (the generation of the palette is correct, though, and should be more accurate than obtained through the gradient method).
I guess one would have to generate a temporary image with the pseudo-gray palette and then use Sample Colorize (I may do this in the future, but have other things occupying my time at the moment). Note that it was not too long ago that Sample Colorize
could not effectively be called non-interactively so if script or plug-in is written using this approach, be aware that it will only work with GIMP 2.6.11 or later.
Code:
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
(define (script-fu-sg-pseudo-gray image layer)
(define (make-pseudo-gray-palette)
(gimp-progress-set-text "Creating palette...")
(gimp-palette-new "Pseudo Grays")
(let loop ((color 0))
(if (= color 255)
(begin
(gimp-palette-add-entry "Pseudo Grays" "white" '(255 255 255))
(gimp-progress-end) )
(begin
(map (lambda (x)
(gimp-progress-pulse)
(gimp-palette-add-entry "Pseudo Grays"
""
x ))
(let ((grays (make-list 7 (make-list 3 color)))
(nears '((0 0 0) (0 0 1) (1 0 0) (1 0 1)
(0 1 0) (0 1 1) (1 1 0) )) )
(map (lambda (a b)
(map + a b) ) grays nears) ))
(loop (+ color 1)) ))))
(gimp-image-undo-group-start image)
(gimp-context-push)
(cond
((zero? (car (gimp-palettes-get-list "Pseudo Grays")))
(make-pseudo-gray-palette) )
((<> (car (gimp-palette-get-info "Pseudo Grays")) 1786)
(gimp-palette-delete "Pseudo Grays")
(make-pseudo-gray-palette) ))
(gimp-context-set-palette "Pseudo Grays")
(plug-in-palettemap RUN-NONINTERACTIVE image layer)
(gimp-displays-flush)
(gimp-context-pop)
(gimp-image-undo-group-end image)
)
(script-fu-register "script-fu-sg-pseudo-gray"
"Pseudo-gray"
"Desaturate image to 1786 levels of \"near\" grays"
"Saul Goode"
"saulgoode"
"May 2012"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)
(script-fu-menu-register "script-fu-sg-pseudo-gray"
"<Image>/Colors/"
)