It is currently Thu Mar 28, 2024 8:08 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 77 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 1:04 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Many years ago, I ran across this site and was intriqued with this concept. I was using Sample Colorize but I would inevitably get way too many tones. Only recently (like an hour ago; lol) found out why (you will have to see the tut for the settings). Anyway, Click the link to the tut and you too will be Pseudo Greying (see tut for a cool test that you can try yourself as well and you too will be a believer). :)

Link to Tutorial: http://justpaste.it/pseudog_gimp

ref: http://www.fontplay.com/freephotos/thir ... 108-19.jpg

Image

_________________
Lyle

Psalm 109:8

Image


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 1:09 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
OK; manage to create a gradient with exactly 1786 tones. Count them yourself using Color Cube analysis. I was trying to do a diagonal gradient and never thought to just do a vertical. :)


Attachments:
gradient_1786.png
gradient_1786.png [ 39.16 KiB | Viewed 22415 times ]

_________________
Lyle

Psalm 109:8

Image
Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 5:26 am  (#3) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
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.

; 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/"
  )

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Fri May 11, 2012 3:17 pm, edited 1 time in total.

Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 7:56 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
When you do a black and white gradient map (dragged) properly, it will be a Pseudogrey image as I showed in my followup link; that's what's cool. Once you have a good target (a pseudogrey gradient or the pyrimid that I actually used in the tut) it's child's play for Sample Colorize. I have since noticed that sometimes I have to still run Sample Colorize twice to get 1786 colors (not for the target in the tut though). Still, no real big deal.

Wish I could have the desire to learn how to program Saul, but lost my appetite since I got out of Engineering (and really since college; didn't really have to do much coding as an Analog EE). I'm an idea's guy anyway. I wonder if this could be done in G'MIC? :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 10:19 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Feb 14, 2012
Posts: 426
If you were to make a layer above your greyscale image fill it with white and then run the RGB noise filter with all the color sliders set all the way up to 1.0 and then reduce the opacity of the layer to 2.0 and merge down you can achieve even more shades as shown in the colorcube analysis. But while it looks greyscale it is RGB.

I find this colorcube and sample colorize to be very useful to me in creating smooth raster patterns for 3D height map images. What I do is all the steps above but I also blur the merged image by a setting of 5. Then I do the Sample Colorize as shown in the tutorial and it comes out even smoother.

It actually changes the numbe of colors again, (reducing it) but this seems to result in a smoother image than just doing the blur at a setting of 5.

Thanks for the info Lyle.

Alan


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 12:04 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
lylejk wrote:
When you do a black and white gradient map (dragged) properly, it will be a Pseudogrey image as I showed in my followup link; that's what's cool.


In blend Dialog there are two check-boxes, Dither and Adaptive Super-sampling.

If neither is checked you will get 256 colours.
If both are checked you will get between 1745 and 1754 depending of them supersampling sliders, possibly out of that range, even.
With just Dither Checked I've seen as little as 1660 and as much as 1786

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 12:44 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Good things to know Rob; never really played with those settings. :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Fri May 11, 2012 3:28 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
I have corrected an error in the script in my previous post. I originally had the green and magenta "near gray" values transposed (as exhibited in the following graphic, green has a higher luminosity than magenta.)

Attachment:
pgray.png
pgray.png [ 556 Bytes | Viewed 22262 times ]

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Sun May 13, 2012 3:07 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Just curious Saul; have you made any progress in getting your script to output true Pseudo-grey? :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Sun May 13, 2012 4:41 pm  (#10) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
lylejk wrote:
Just curious Saul; have you made any progress in getting your script to output true Pseudo-grey? :)

No, I haven't; however, it appears to be possible to create a gradient with thousands of segments. So perhaps it would be feasible to modify my script to create a pseudo-gray gradient (with 1785 segments) which can then be applied using 'plug-in-gradmap', with the caveat being whether gradmap retains more than 8-bit precision when it calculates luminosity.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Sun May 13, 2012 5:08 pm  (#11) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Thanks for the followup Saul. Might be a minor inconvenience, but using Sample Colorize interactive doesn't take much effort and it's quick too. Still, it requires a good target image; if the target has any posterization or noise, then there's little benifit to convert that result into a Pseudogrey anyway. Still, I'm quite pleased at some results that I've already shared (other forums) using the flow as I outlined in the tut. :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 11:48 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 12, 2012
Posts: 178
Location: Mobile, AL USA
Well, I'm a little late to the game, but you've managed to suck away 2 hours of my morning...

; Pseudogrey v1
; Created by Patrick David <patdavid@gmail.com>
; http://blog.patdavid.net
;
; Script to convert a color image to a larger number of gray values than 256
; based on a tutorial originally posted to
; http://gimpchat.com/viewtopic.php?f=10&t=4245
; by gimpchat member lylejk
;
; 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-patdavid-pseudogrey Image Drawable)

   (let*
        (
         (PG (car (gimp-layer-new Image 2048 10 RGB "PG" 100 NORMAL)))
        )
      (gimp-image-undo-group-start Image)
           ;set up gradient definition
         (gimp-gradient-new "pg-patdavid-tmp")
         (gimp-gradient-segment-set-left-color "pg-patdavid-tmp" 0 '(0 0 0) 100)
         (gimp-gradient-segment-set-right-color "pg-patdavid-tmp" 0 '(255 255 255) 100)

         ;set active gradient
         (gimp-context-set-gradient "pg-patdavid-tmp")

         (gimp-image-add-layer Image PG -1)

         ;create gradient filled layer
         (gimp-edit-blend PG CUSTOM NORMAL LINEAR 100 0 REPEAT-NONE FALSE TRUE 1 0 TRUE 0 0 1800 0)

         ; sample colorize
         (plug-in-sample-colorize RUN-NONINTERACTIVE Image Drawable PG FALSE FALSE TRUE TRUE 0 255 1.0 0 255)

         ; clean up
         (gimp-gradient-delete "pg-patdavid-tmp")
         (gimp-image-remove-layer Image PG)

         (gimp-displays-flush)

      (gimp-image-undo-group-end Image)
    )

)

; Finally register our script with script-fu
(script-fu-register "script-fu-patdavid-pseudogrey"
                    "Pseudogrey..."
                    "Pseudogrey mapping using Sample Colorize & gradient"
                    "Patrick David <patdavid@patdavid.net>"
                    "Patrick David"
                    "2012-06-19"
                    "RGB*"
         SF-IMAGE   "Image"      0
         SF-DRAWABLE   "Drawable"   0
)

(script-fu-menu-register "script-fu-patdavid-pseudogrey" "<Image>/Colors")


This will just define a black to white linear gradient, create a layer, apply the gradient across it, then sample colorize between the gradient layer and the active layer, with requisite options.

I've checked quickly and the indeed the result is 1700+ levels.

Thanks for this topic, it's been quite interesting! :)

_________________
patdavid.net
Image
PIXLS.US F/OSS Photography


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 12:24 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Magic number is 1786 patdavid; just tried out your Script-fu and got the magic 1786 result. Thanks a heap; will update my tut thread with your Script-fu link which, I hope you don't mind, saved as a .scm file that's attached. :)


Attachments:
Pseudogrey.scm [2.37 KiB]
Downloaded 248 times

_________________
Lyle

Psalm 109:8

Image
Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 12:31 pm  (#14) 
Offline
GimpChat Member
User avatar

Joined: Jan 12, 2012
Posts: 178
Location: Mobile, AL USA
Excellent!
Don't mind at all - that's what I attached it here for. I think I may go put it up on the plugin registry as well.

_________________
patdavid.net
Image
PIXLS.US F/OSS Photography


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 12:46 pm  (#15) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Definitely good news patdavid. I'm a big advocate for pseudogrey (and, though not here, got hit for being over zealous; lol). :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 4:00 pm  (#16) 
Offline
GimpChat Member
User avatar

Joined: Jan 12, 2012
Posts: 178
Location: Mobile, AL USA
I've gone ahead and done a quickie writeup on your method (with attribution and links):

True PseudoGrey in GIMP

_________________
patdavid.net
Image
PIXLS.US F/OSS Photography


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 4:53 pm  (#17) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
Going to PM you some additional things Pat and again, thanks for the Script-fu. :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 5:15 pm  (#18) 
Offline
GimpChat Member
User avatar

Joined: May 26, 2012
Posts: 342
Location: France
...You reminded me something with this grey mode attempts, but beware, my question is related to color profiles so there's always a chance that what I see on my screen does not match what you see, because of discrepancies between monitors, browsers, embed color profiles in png and all that jazz that usually annoys me when I think about it.

Briefly, I want to know if your pseudo grey method aims at converting hues to grey while _keeping_ the value of colors, because in your output greyed image, I can see that colors are translated to grey but without matching the value of the original image (eg: the trunks I see became darker in the grey output).

And my question is not purely theoretical, if someone created a script that can achieve a grey translation without value loss, I want it badly ! :)


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 5:22 pm  (#19) 
Offline
GimpChat Member
User avatar

Joined: Sep 24, 2010
Posts: 12513
It does use Hue transistions to achieve the 1786 tones anarkhya. Unfortunatly, 8-bit images can only have 256 values if you will so when you monotone an image, you only will get 256 unique values. What Pseudogrey does is blend the transitions between values giving you a cleaner transistion. As a test, create a 1000X1000 image and run the gradient tool (default forground/background setting that is black to white) diagonally then count the number of unique tones using color cube analysis and if done right, you will have 1786 unique tones despite created a black to white gradient (run Max colors and you will see the colors show). That's what convinced me that Pseudogrey is the way to convert b/ws. The only way to get a higher number of values is to increase bit of image to 16 bits for example. One other thing though; if you save the result as a jpeg (lossy) you will loose tones; you need to save in a lossless format such as PNG to benifit from pseudogrey. :)

_________________
Lyle

Psalm 109:8

Image


Top
 Post subject: Re: True Pseudogrey in GIMP.
PostPosted: Tue Jun 19, 2012 6:06 pm  (#20) 
Offline
GimpChat Member
User avatar

Joined: May 26, 2012
Posts: 342
Location: France
I'm a bit confused by...
lylejk wrote:
It does use Hue transistions to achieve the 1786 tones anarkhya. Unfortunatly, 8-bit images can only have 256 values if you will so when you monotone an image, you only will get 256 unique values.

Yes but.. Why talking about indexed image ? The photo shown is 32bit (or 24, I'm not sure, jpg is capable of 32 or 24 ?). As desaturating does not imply that you index the image (well it may do if you use mode grey, that's what you meant?) with the desaturate filter you obtain a non-8bit image.

lylejk wrote:
One other thing though; if you save the result as a jpeg (lossy) you will loose tones; you need to save in a lossless format such as PNG to benifit from pseudogrey.

Are you sure? I've used max quality jpgs (like 99% quality and all quality checkboxes ticked) a few times and, while it's technically still lossy, my eyes seem to be totally fooled.


Top
Post new topic Reply to topic  [ 77 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group