Selected pixel count - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: Selected pixel count (/Thread-Selected-pixel-count) |
Selected pixel count - steven Brazzale - 03-10-2023 Hi, Is there anyway to get the selected pixel count (as displayed in the histogram) into the clipboard, so I can use Autokeypad to put it into a spreadsheet? Cheers RE: Selected pixel count - Ofnuts - 03-10-2023 Open the python console and enter this: Code: image=image=[x for x in gimp.image_list() if image.ID==5][0] [attachment=9515]
Then to get your pixel count: Code: pdb.gimp_drawable_histogram(image.active_layer,0,0.,1.)[3] If you want to redo this for another selection, just repeat that last line after changing the selection, since the image will be the same. To be a bot more complete, in the histogram call, the args are:
It is of course also easy to format this output differently, and writing a script to write the values to file wouldn't be difficult. Here is how the API and the GUI relate: [attachment=9516]
RE: Selected pixel count - steven Brazzale - 03-12-2023 (03-10-2023, 08:04 AM)Ofnuts Wrote: Open the python console and enter this:Thanks For That Ofnuts. I've got it to work, but not with Code: image=image=[x for x in gimp.image_list() if image.ID==5][0] Traceback (most recent call last): File "<input>", line 1, in <module> NameError: name 'image' is not defined But I am only using one image, so I can just use Code: theImage = gimp.image_list()[0] Cheers Steven RE: Selected pixel count - Ofnuts - 03-12-2023 (03-12-2023, 12:13 AM)steven Brazzale Wrote: Thanks For That Ofnuts. 1) Sorry, typo, only one image=: Code: image=[x for x in gimp.image_list() if image.ID==5][0] 2) Yes, you can hardcode gimp.image_list()[0] but you'll get burned sooner or later. Of course if you do a true plugin instead of pasting code in the Python console you get the image passed as a plugin parameter. 3) Possibly, but this is heavily system dependent. On Linux, there is a CLI utility to stuff things in the clipboard and it can be called from Python. I don't know if it is as simple in Windows (or even possible). But IMHO you could skip the clipboard and write directly in a file. RE: Selected pixel count - steven Brazzale - 03-14-2023 [quote pid='33676' dateline='1678629780'] Thanks Ofnuts [/quote] |