GT Portal . Forums . Official Tutorials . Art Galleries . FAQs . Search . New Posts . Contact Us Login  .  Register


Board index » GIMP News and Help forums » GIMP General Help Make Money Online . Free Image Hosting
Featured Tutorial : Learn how to create characters by Griatch
Search for :  


Post new topic Reply to topic   [ 11 posts ]  


Author Message
 Post subject:
PostPosted: Mon Apr 07, 2008 4:25 pm 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics

Anyone know if there is an existing script-fu (or something) to take a "density map" (feathered selection or greyscale layer) and from that generate random brush strokes based on that value?

For example with this mask (made from a selection feathered 100 px):
Image

I'd like to have it paint the red dots (I did this manually as an example) something like this:
Image

Ideally, I could specify the final "density" by a slider,

Alternately, suggestions to the best approach in writing a plugin (I've done a few so know the basics) would be appreciated.

Thanks,

-Rob A>




Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 5:56 am 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics
I found this post and realized that it was almost what I needed.

I quickly hacked it to:
1) Use the currently selected drawing tool.
2) Allow the specification of a density mask.

Code:
;; random_masked.scm -*-scheme-*-
;; Use a brush to paint to paint random pixels a nominated number
;; of times to produce a "random" pattern/.
;; based on:
;; More info at http://members.optusnet.com.au/~charles57/GIMP
;; Version 1.0
;;
;; Copyright (C) 2008 by Charles Cave <charlesweb@optusnet.com.au>
;;
;; 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.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(define (script-fu-random-masked    img drw
                                    mask
                                    iterations)

  (let* (
        (x1 0)
        (y1 0)
        (ctr 0)
        (x2 (car (gimp-image-width img)))
        (y2 (car (gimp-image-height img)))
        (x 0)
        (y 0)
        (mask-type 0)
        (get-val 0)
        (test 0)
        (thresh 0)
        (*randompoint* (cons-array 2 'double))
        (drw-width 0)
        (drw-height 0)
        )

; define drawable area for the algorithm
  (set! drw-width  (- x2 x1))
  (set! drw-height (- y2 y1))
  ; make sure not indexed
  (set! mask-type (car (gimp-drawable-type mask)))
  (if (or (= mask-type INDEXED-IMAGE) (= mask-type INDEXEDA-IMAGE))
    (gimp-message "Mask can not be indexed")
   (begin
     
     (gimp-context-push)
     (gimp-image-undo-group-start img)

     (gimp-progress-set-text _"Rendering Random Masked Image")
     (while (< ctr iterations)
      (set! x (+ x1 (random drw-width )))
       (set! y (+ y1 (random drw-height)))

       (set! get-val (cadr (gimp-drawable-get-pixel mask x y)))
       (set! thresh (random 255))

       (if (or (= mask-type GRAY-IMAGE) (= mask-type GRAYA-IMAGE))
         (set! test (aref get-val 0))
         (if (or (= mask-type RGB-IMAGE) (= mask-type RGBA-IMAGE))
           (set! test (/ (+ (aref get-val 0) (aref get-val 1) (aref get-val 2)) 3))
         (set! test 255)
         )
       ) 

       (if (< thresh test)
        (begin
          (set! ctr (+ ctr 1))
           (aset *randompoint* 0 x)
           (aset *randompoint* 1 y)
           (gimp-paintbrush-default drw 2 *randompoint*)
         (gimp-progress-update (/ ctr iterations))
         )
       )
     )
     (gimp-image-undo-group-end img)
     (gimp-displays-flush)
     (gimp-progress-end)
     (gimp-context-pop)
    )
  )
  ) 
)

(script-fu-register "script-fu-random-masked"
                    _"Random Masked"
                    _"Draws a specified number of random points using the currently selected brush, with a mask."
                    "Charles Cave <charlesweb@optusnet.com.au>"
                    "Charles Cave"
                    "February 2008"
                    "RGB*, INDEXED*, GRAY*"
                    SF-IMAGE       "Image"         0
                    SF-DRAWABLE    "Drawable"      0
                    SF-DRAWABLE    "Mask"          -1

                    SF-ADJUSTMENT _"Iterations"     '(10 1 10000 10 100 0 0)
                    )

(script-fu-menu-register "script-fu-random-masked"
                         "<Image>/Filters")


It still needs some clean up, but works pretty well.

Here is a basic example, showing the mask and three results of the filter (I have tiled them onto one image):

Image

and another, where I ran the filter twice with two different brushes:

Image

Hope someone finds it helpful!

-Rob A>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 6:06 am 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics
Oh yeah -

Here is the filter run on the sample mask (inverted) with 1000 iterations:

Image

Pretty close to my mock up, eh?

-Rob A>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 8:59 am 
Offline
User avatar

Joined:
Mon Nov 27, 2006 4:48 pm

Topics: 138
Posts: 2261
Location: Sweden

Find User's Topics
Not much more help to add to this topic, you handled it just fine on your own. :-)

It looks like a useful function. For completeness, you should consider making a thread in the resource board with this (just give proper credit to the original author of the script, as you have done here).
.
Griatch


_________________
Image
~~ My online art Gallery ~~ My GIMP Tutorials ~~


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 11:24 am 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics
I just want to do a bit more cleanup, first.

I still want to:

1) add an "invert density map" checkbox option
2) add a border zone based on the with of the brush to prevent brush clipping (also a checkbox option)
3) add some logic to check/limit the density map to the same size as the applied map.

Then I'll post it in the resource thread, and probably over at the new gimp plugin registry, as I already have an account there.

-Rob A>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 3:24 pm 
Offline
User avatar

Joined:
Mon Jun 13, 2005 11:15 am

Topics: 549
Posts: 6572

Find User's Topics
once finished you may also present in the plugin and script board, since most look in resource board for brush ,render and alike

so a double post in case of script may be useful
(in Italy we say " exception confirm the rules.. :w:": forum do not like double post but in few cases as this they may be useful )


_________________
Image

http://www.flickr.com/photos/97844002@N00/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 4:44 am 
Offline
User avatar

Joined:
Wed Oct 26, 2005 9:21 am

Topics: 55
Posts: 1413

Find User's Topics
KISS (acronym)
No offense, but if you take the original and change its layer mode to " Dissolve " then apply a blur, wouldn't that get the same effect or there about?

Image


_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 5:05 am 
Offline
User avatar

Joined:
Wed Apr 02, 2008 6:14 pm

Topics: 1
Posts: 22

Find User's Topics
Quote:
KISS (acronym)
No offense, but if you take the original and change its layer mode to " Dissolve " then apply a blur, wouldn't that get the same effect or there about?

On a very small scale this is true, but RobA's script can use large, or oddly shaped, brushes to create a broader range of effects.



Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:47 am 
Offline
User avatar

Joined:
Wed Oct 26, 2005 9:21 am

Topics: 55
Posts: 1413

Find User's Topics
Quote:
On a very small scale this is true, but RobA's script can use large, or oddly shaped, brushes to create a broader range of effects.

True, if you want something other than a pixel, a little caution tho- a large brush with many "iterations" could become a major cpu hog.
Also it goes into an endless loop on a transparent layer, and places stokes outside of the layer.
I do see a use for it, but yeah it needs some clean up work.


_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:54 am 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics
Quote:
On a very small scale this is true, but RobA's script can use large, or oddly shaped, brushes to create a broader range of effects.


My initial version was intended for using animated coloured brushes. I wanted to be able to draw trees symbols on a map. Rather than drawing them in manually with a high jitter (what I was doing) with this script I can now create a density map and just fill it. white areas get the higest density, 50% grey get half that, and so on.

Also, I have additionally been "improving" the script, so now in addition to a greyscale map you can tell it to use the alpha for density and copy the source colour from the map. And I'm still adding the error handling...

Here is an example of that. The map layer first, then the filter run on a black layer. I also used a 3 pointed brush to demonstrate how the detail of the brush can be maintained:
Image
Image

-Rob A>



Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 4:37 pm 
Offline

Joined:
Mon Nov 05, 2007 3:16 pm

Topics: 8
Posts: 38

Find User's Topics
Thanks for the feedback. I cleaned up the script and posted it in this thread in the other forum.

-Rob A>



Top
 Profile  
 
Display posts from previous:  Sort by  

Post new topic Reply to topic
 [ 11 posts ] 



Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Related Website
Gimp tutorials database
All rights reserved © GimpTalk 2008
forum software by
phpBB