It is currently Fri Apr 26, 2024 1:03 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Need a special script: show min/max values of pix in selection
PostPosted: Sun Nov 01, 2015 8:19 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Apr 20, 2011
Posts: 287
Location: Dane-ish Co., West Gonsin
I admit it.

I yam a GIMP oddista. I use the GIMP to create black-and-white heightmaps/depthmaps which ultimately end up as models to be cut out in 3D on a CNC machine.

Wacky stuff.

Don't disagree.

But--wow--what a tool GIMP is for me! Even if from sophisticates's point-of-view all I do is grab it on its wrong end and whack-whack-whack. You maybe can't tell by looking at my posts, but I use GIMP in tres mucho sofisticated ways too.

"So I was wondering" [here it comes...] "how hard it would be" (that is, if someone could coach me through it) "to create a script or plug-in that could update the display of the min and max values of the pixels enclosed by an arbitrary selection, as it (the selection) was changed dynamically."

It may be that this is already known to aficianadoes in these parts as a Wicked Problem. If so, I will be glad to know it, because I just came here to let you, my friends, know that, if you do not help me, I am going to set off into the Land of Scripts and Plug-ins--without a decent flashlight--and you may never hear from me ever again, ever, and well, I just wanted to thank you for all your help you have gaven me and tell you how much you all have meant to me over the years and well, I hope somebody can think of an easy way to do it here because well, I really don't want to go back in There!

So long.

ur freind.

_________________
--
GraMP
"Once you sit on your glasses, the rest of getting old seems obvious."


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: Need a special script: show min/max values of pix in selection
PostPosted: Sun Nov 01, 2015 8:24 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
You can't really do that with a script. That would be an extension of the current selection tools (rectangle/ellipse/freehand) but even then these currently only compute the true selection when you tell them you are finished...

_________________
Image


Last edited by ofnuts on Sun Nov 01, 2015 8:30 pm, edited 1 time in total.

Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Sun Nov 01, 2015 8:29 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Apr 20, 2011
Posts: 287
Location: Dane-ish Co., West Gonsin
(Whoops, I replied to a reply that morphed! ;^) )

I followed up on the new information (for me) that Histogram supplied that info already--and it altmost does.

I open the Color->Info->Histogram window and draw a selection, and the histogram is updated every time I stop adjusting the selection.

I see that it gives me the Mean, Std. dev., Median, #Pixels, Count, and Percentile.

However, it only shows min and max as "positions" along a line (which has bothered me before). I have to adjust the sliders Left-Right and keep my eye on the percentile change to see, exactly, where the min and max are. Histogram knows what they are--it draws lines at those locations: I wish it would write them out too.

(Maybe I could calcalate it from the Mean, Median, and Std. dev... [Checks calendar] Nope. Not enough decades left.)

Thanks, ofnuts!

_________________
--
GraMP
"Once you sit on your glasses, the rest of getting old seems obvious."


Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Sun Nov 01, 2015 10:29 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
gramp, have a look at, ImageJ or GNU Octave.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Mon Nov 02, 2015 2:53 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
gramp wrote:
(Whoops, I replied to a reply that morphed! ;^) )

I followed up on the new information (for me) that Histogram supplied that info already--and it altmost does.

I open the Color->Info->Histogram window and draw a selection, and the histogram is updated every time I stop adjusting the selection.

I see that it gives me the Mean, Std. dev., Median, #Pixels, Count, and Percentile.

However, it only shows min and max as "positions" along a line (which has bothered me before). I have to adjust the sliders Left-Right and keep my eye on the percentile change to see, exactly, where the min and max are. Histogram knows what they are--it draws lines at those locations: I wish it would write them out too.

(Maybe I could calcalate it from the Mean, Median, and Std. dev... [Checks calendar] Nope. Not enough decades left.)

Thanks, ofnuts!

There is a gimp-histogram function in the PDB that returns this information.
# This will get you the size of the selection in 'pixels', 'count' is the count of those between min and max)
mean, std_dev, median, pixels, count, percentile = pdb.gimp_histogram(drawable,HISTOGRAM_VALUE, min,max)

So you can use a dichotomic search in min and max to find those values that make count<>pixels.

Edit: quick hack, see attachment. Values can be off by one but I have to deal with other code right now.


Attachments:
ofn-minmax.zip [1.12 KiB]
Downloaded 110 times

_________________
Image
Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Mon Nov 02, 2015 5:14 am  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
If you decide to visit the land of scripting, the following two functions might be of use. The channel passed to the function is the same as used by the 'gimp-histogram' procedure (i.e., HISTOGRAM-VALUE, HISTOGRAM-RED, HISTOGRAM-GREEN, HISTOGRAM-BLUE, HISTOGRAM-ALPHA, or HISTOGRAM-RGB).


;; Perform a binary search for the smallest value for a particular channel
;
(define (darkest drawable channel)
  (define (avg a b)
    (inexact->exact (truncate (/ (+ a b) 2))) )
  (let ((lower (let loop ((lower 1))
                 (if (zero? (car (cddddr (gimp-histogram drawable channel 0 (pred lower)))))
                   (loop (* 2 lower))
                   (inexact->exact (truncate (/ lower 2))) ))))
    ; binary search for largest zero count
    (let loop ((lower (max 1 lower))
               (upper (* 2 lower))
               (value (avg lower (* 2 lower)))
               (last 0) )
      (if (= last value)
        value
        (if (zero? (car (cddddr (gimp-histogram drawable channel 0 (pred value)))))
          (loop value
                upper
                (avg value upper)
                value )
          (loop lower
                value
                (avg lower value)
                value ))))))
;; Perform a binary search for the largest value for a particular channel
;
(define (brightest drawable channel)
  (define (avg a b)
    (inexact->exact (truncate (/ (+ a b) 2))) )
  (let ((upper (let loop ((upper 256))
                 (if (zero? (car (cddddr (gimp-histogram drawable channel (pred upper) 255))))
                   (loop (/ upper 2))
                   (* upper 2)  ))))
    ; binary search for largest non-zero count
    (if (> upper 256)
      255
      (let loop ((lower (max 1 (/ upper 2)))
                 (upper upper)
                 (value (avg (/ upper 2) upper))
                 (last 256) )
        (if (= last value)
          (pred value)
          (if (zero? (car (cddddr (gimp-histogram drawable channel (pred value) 255))))
            (loop lower
                  value
                  (avg lower value)
                  value )
            (loop value
                  upper
                  (avg value upper)
                  value )))))))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Mon Nov 02, 2015 10:13 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Apr 20, 2011
Posts: 287
Location: Dane-ish Co., West Gonsin
Thank you friends for rallying round.

@Odinbc "Right tool for the job." I fired up imagej (strangely, I didn't have it on this my main machine, but use it somewhat regularly on the others). Analyze->Histogram brings up the window with a promising-looking "Live" button.

I can draw a selection of my desired size and aspect, and drag it around with the "Live" button activated, ImageJ shows me a real-time histogram and identifies the min and max at the same time. (Just like in my dream.) Thank you.

Edit: BTW, I discovered that holding the Shift key will maintain the aspect ratio as the selection is resized with the mouse: important feature for me.

@Ofnuts Bringing it to GIMP. [For the sake of archive-ness] I installed the script (after making it executable and looking into it to see its registered location) in plug-ins/, ran Filters->Script-fu->RefreshScripts, but didn't see it (because I think I didn't scroll down far enough), but found it right away after restarting GIMP: Filters->Find min and max in drawable...

I create a selection initially, or move it, and then select the minmax filter, and the min/max values display for me on the bottom-most (sorry, don't know the name) line of the image window, but with a "Danger" sign (red/white triangle with '!').
Incidentally, the high value reported is off by -1 (e.g., 254 instead of 255), and the low value is off by +1 (1 instead of 0).

This is a huge improvement over the nothing that I had before, and is plenty useful as it is, but does require repeating the filter after each move instead of updating the min/max continuously during movement. [Again, just recording this for archival purposes. As you said, "quick hack", which for me demonstrates the feasibility, for which thank you.]

@SaulGoode
:shock: :shock: :shock:
Whene'er I have ventured into ScriptLand, I have so far, always, headed perpendicularly away from the Great Gray Mist. ;^)

Thank you. Again, if you'll leave them here, one of my future selves is sure to come hunting them (after we get over our irrational fears).

_________________
--
GraMP
"Once you sit on your glasses, the rest of getting old seems obvious."


Last edited by gramp on Mon Nov 02, 2015 3:33 pm, edited 1 time in total.

Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Mon Nov 02, 2015 10:46 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
gramp wrote:
I create a selection initially, or move it, and then select the minmax filter, and the min/max values display for me on the bottom-most (sorry, don't know the name) line of the image window, but with a "Danger" sign (red/white triangle with '!').


Gimp considers all messages from plugins/scripts as "Warnings".

_________________
Image


Top
 Post subject: Re: Need a special script: show min/max values of pix in selection
PostPosted: Mon Nov 02, 2015 12:19 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Apr 20, 2011
Posts: 287
Location: Dane-ish Co., West Gonsin
I think the better part of valor here is to follow Odinbc's advice and use ImageJ.

Not to push for Emacs-like expectations from GIMP, but if anyone does add ImageJ-like live-histogram capability to GIMP, please let me know.

Again, I'm thanking you, like Mrs. Nussbaum from Allen's Alley, for answering my plea already.

_________________
--
GraMP
"Once you sit on your glasses, the rest of getting old seems obvious."


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Can't get marching ants to show (selection boundary display)

2

No new posts Attachment(s) Is there a script for doing Stroke outside selection?

4

No new posts Attachment(s) Script for selecting, cropping the selection and saving the file

8

No new posts Still no show

2

No new posts CAN NOT GET GMIC TO SHOW OR WORK

2



* Login  



Powered by phpBB3 © phpBB Group