It is currently Mon Apr 15, 2024 7:24 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 2:45 pm  (#1) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6947
Location: Somewhere in GIMP
Path to script: http://flashingtwelve.brickfilms.com/GIMP/Scripts/sg-mean-fill.scm

I'm having trouble with this script. I don't remember if I had used it in gimp 2.4 or 2.6 the first time.

I am trying to apply it to a selection.

Perhaps I'm using it wrong.

ImageImage

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


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: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 3:15 pm  (#2) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
maybe change value (Something less then 256 ) or add a alpha channel will help

Not sure i didn't use the script yet, i just suppose it includes a step to convert to index and back to rgb, ..and then the max should be 255 (+1 ...but this last one reserved to transparency )

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 3:18 pm  (#3) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6947
Location: Somewhere in GIMP
We were using it in lylejk's mosaic images. I was trying another turtle. I think you were in on it too, PC.

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 4:58 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Sometime in the last month or two, they changed the upper limit of the upper limit argument of the Histogram procedure to 255.

I have updated the original script.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 5:51 pm  (#5) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6947
Location: Somewhere in GIMP
Thank you. I'll send Lyle a link to this thread so he can get it too.

That's an interesting report about the histogram. They got it fixed though.

Seems like stuff changes when you least expect it. :hehe

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 7:53 pm  (#6) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6947
Location: Somewhere in GIMP
I'm still getting an error message (same as previous) when I try to use it. I did download the one in the link, deleted the old one and put the new one in my scripts folder. I also closed and re-opened gimp.

Looked at the date in the script and it says 4/21/2010. Perhaps the update didn't get uploaded?

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 8:48 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Oregonian wrote:
Looked at the date in the script and it says 4/21/2010. Perhaps the update didn't get uploaded?


Hmmm, strange. The upload worked (I could download the new version using FTP) but it did not update the modified date. This means that your webbrowser used the version it had cached (since the online version wasn't seen as being newer) and didn't bother downloading the new version.

I have manually updated the date on the file so a download should work. If it does not, you could clear your browser's cache and try again (on Firefox cache clearing is under "Edit->Preferences->Advanced->Network"). There are only three instances of "256" in the script which need to be changed to "255", so editing the script manually is also an option.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 8:58 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Thats what i was going to suggest to just update the script manually, much easier. =)

Image

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 9:31 pm  (#9) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6947
Location: Somewhere in GIMP
I cleared my cache twice and no joy. Tried a different browser, no joy.

Closed all tabs in Firefox except one and made it a blank white page. Cleared cache, cleared cookies. Closed and re-opened Firefox.

Finally, I got the right one. Thanks.

I honestly don't know how it could have been stored in cache since last April though. I know I've cleared my cache a few times since then.

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Tue Jul 27, 2010 10:43 pm  (#10) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
FireFox is weird that way, every time it updates it seems something goes haywire, and it updates daily it seems ... lol =)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Thu Sep 10, 2020 9:36 pm  (#11) 
Offline
New Member

Joined: Sep 10, 2020
Posts: 2
Can't believe this thread is 10 years old. I have updated this script to work with GIMP 2.10.20 ( I wasted far too much time hunting an error while in 2.10.14, which disappeared after updating ).
This largely involved replacing deprecated calls with their replacements, figuring out what had to be changed in the call, as well as dealing with the changes to the inputs of the histogram / threshold commands (0..1 instead of 0..255 range)

I have also added an option to use the median, rather than the mean, presented through the UI, though results may be unexpected depending on selected content.

Right now the option to check for this option is in one of the inner loops. The original code is very efficient, meaning that inner loop doesn't run as often as one would think. Nevertheless, if performance is a concern, this check could be moved outside and the inner code duplicated (with appropriate adjustment) instead.

Note: I didn't have much knowledge of script-fu when I began this, so if there's egregious mistakes, please do aid in making it better.

As apparently one can't upload scripts here, and off-site URLs are too spammy for new users, please accepted the following code block:
; 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.

; This script creates a new layer on which contiguous regions of the
; selection are filled with the mean (average) value of that region.
;
; Special thanks to Rob Antonishen for providing optimizations and
; making the operation UNDO-able

(define (script-fu-sg-meanmedian-fill orig-image drawable meanmedian)
  (let* (
      (width (car (gimp-image-width orig-image)))
      (height (car (gimp-image-height orig-image)))
      (orig-selection 0)
      (layer 0)
      (raw-selection 0)
      (selection 0)
      (x 0)
      (y 0)
      (bounds '())     
      (orig-drawable drawable)
      (image (car (gimp-image-duplicate orig-image)))
      (drawable (car (gimp-image-get-active-layer image)))
      (buffer "sgmfbuffer")
      (selection-drawable 0)
      )
    (gimp-image-undo-group-start orig-image)
    (gimp-image-undo-disable image)
    (gimp-context-push)
    (set! raw-selection (car (gimp-selection-save image)))
    (set! orig-selection (car (gimp-selection-save orig-image)))
    (set! selection (car (gimp-channel-copy raw-selection)))
    (gimp-image-insert-channel image selection 0 -1)

    (gimp-selection-none image)
    (gimp-drawable-threshold selection 0 0.5 1)
    (gimp-image-set-active-layer image drawable)
    (set! layer (car (gimp-layer-new-from-drawable drawable image)))

    (gimp-image-insert-layer image layer 0 -1)
    (gimp-layer-add-alpha layer)
    (gimp-drawable-fill layer FILL-TRANSPARENT)


    (gimp-image-select-item image CHANNEL-OP-REPLACE raw-selection)

    (set! selection-drawable (car (gimp-image-get-selection image)))


    (while (< y height)
      (while (< x width)
        (if (> (car (gimp-selection-value image x y)) 127)
          (begin

            (gimp-fuzzy-select selection x y 127 CHANNEL-OP-INTERSECT FALSE FALSE 0 FALSE)
            (if (= meanmedian 0)
              (begin
                (gimp-context-set-foreground
                  (list (car (gimp-drawable-histogram drawable HISTOGRAM-RED 0 1))
                        (car (gimp-drawable-histogram drawable HISTOGRAM-GREEN 0 1))
                        (car (gimp-drawable-histogram drawable HISTOGRAM-BLUE 0 1)))))
              (begin
                (gimp-context-set-foreground
                  (list (caddr (gimp-drawable-histogram drawable HISTOGRAM-RED 0 1))
                        (caddr (gimp-drawable-histogram drawable HISTOGRAM-GREEN 0 1))
                        (caddr (gimp-drawable-histogram drawable HISTOGRAM-BLUE 0 1)))))
            )
            (gimp-edit-fill layer FILL-FOREGROUND)
            (gimp-channel-combine-masks selection selection-drawable CHANNEL-OP-SUBTRACT 0 0)
            (gimp-image-select-item image CHANNEL-OP-REPLACE selection)
            (gimp-image-select-rectangle image CHANNEL-OP-INTERSECT x y width 1)
            (if (= (car (set! bounds (gimp-selection-bounds image))) TRUE)
              (set! x (cadr bounds))
              (set! x width))
            (gimp-image-select-item image CHANNEL-OP-REPLACE selection)
            (if (= (car (set! bounds (gimp-selection-bounds image))) TRUE)
              (begin
                (set! width (cadddr bounds))
                (set! y (max y (caddr bounds)))
                (set! height (cadr (cdddr bounds))))
              (begin
                (set! x width))))
          (begin
            (set! x 0)
            (gimp-image-select-rectangle image CHANNEL-OP-INTERSECT x y width 1)
            (if (= (car (set! bounds (gimp-selection-bounds image))) TRUE)
              (set! x (cadr bounds))
              (set! x width))
            (gimp-image-select-item image CHANNEL-OP-REPLACE selection))
         )
        (gimp-progress-pulse))
      (if (= (car (set! bounds (gimp-selection-bounds image))) TRUE)
        (begin
          (set! x (cadr bounds))
          (set! width (cadddr bounds))
          (set! y (max (+ y 1) (caddr bounds)))
          (set! height (cadr (cdddr bounds))))
        (begin
          (set! x width)
          (set! y height)))
    )
    (gimp-image-select-item image CHANNEL-OP-REPLACE raw-selection)
    (gimp-image-remove-channel image selection)
    (gimp-image-remove-channel image raw-selection)
   
    (set! buffer (car (gimp-edit-named-copy layer buffer)))
    (set! layer (car (gimp-layer-new-from-drawable orig-drawable orig-image)))
    (gimp-image-insert-layer orig-image layer 0 -1)

    (gimp-layer-add-alpha layer)
    (gimp-drawable-fill layer FILL-TRANSPARENT)
    (gimp-floating-sel-anchor (car (gimp-edit-named-paste layer buffer FALSE)))
   
    (gimp-displays-flush)
    (gimp-context-push)
    (gimp-progress-end)

    (gimp-image-select-item orig-image CHANNEL-OP-REPLACE orig-selection)
    (gimp-image-remove-channel orig-image orig-selection)
    (gimp-image-undo-enable image)
    (gimp-image-undo-group-end orig-image)
    (gimp-image-delete image)
   
    (gimp-image-set-active-layer orig-image layer)))

(script-fu-register "script-fu-sg-meanmedian-fill"
  "Mean/Median Fill"
  "Fill selections with the mean or median of the selected regions"
  "Saul Goode, Rob Antonishen, pw"
  "Saul Goode"
  "4/21/2010 / 09/10/2020"
  "RGB*"
  SF-IMAGE "Image" 0
  SF-DRAWABLE "Drawable" 0
  SF-OPTION "Fill with" '("Mean" "Median")
  )
(script-fu-menu-register "script-fu-sg-meanmedian-fill"
  "<Image>/Filters/Misc"
  )


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Fri Sep 11, 2020 12:38 am  (#12) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
(gimp-histogram drawable HISTOGRAM-RED 0 255) is preferable to (gimp-drawable-histogram drawable HISTOGRAM-RED 0 1) because the later does not exist in Gimp 2.8

Link for sg-mean-fill↓

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Saulgoode - sg-mean-fill.scm
PostPosted: Fri Sep 11, 2020 7:15 am  (#13) 
Offline
New Member

Joined: Sep 10, 2020
Posts: 2
Yes, though that command is deprecated in 2.10.x , thus the change-over.

After a good night's rest and some coffee, and re-reading my statement about 2.10.20 fixing a bug I was chasing, I retried the original script in 2.10.20... and lo and behold, it works just fine in that version.. so I ported it over needlessly :hoh

At least I learned some script-fu along the way, I suppose! :hehe


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Saulgoode...

15

No new posts PhotoComix and SaulGoode

13

No new posts Attachment(s) Fill with pattern seamless

13

No new posts Attachment(s) Stripes when doing a bucket fill with pattern

0

No new posts Bucket fill white comes out as grey

4



* Login  



Powered by phpBB3 © phpBB Group