You are here

Count tiles for a mosaic

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!

# Author: Chris Mohler
# Copyright 2009 Chris Mohler
# License: GPL v3
# GIMP plugin to count the number of tiles of the FG color

This plugin breaks the layer into tiles and counts the number of tiles containing a percentage of the FG color, and optionally draws a grid in the bg color. The plug-in also reports the total percentage of the FG color in the layer. For best results, use a flattened copy of your layered image.

Parameters:
Tile size: Enter the tile size in pixels
Minimum Percent: Ignore tiles with lower than this percent of the fg color. EG, enter 5 to skip tiles with less than 5% of the FG color
Draw Grid: toggle this to add the grid layer

CAVEATS:
This thing is SLOW - it examines every pixel.
It does not seem to find some colors - for best results, use solid colors like (255,0,0) - solid Red, etc. You will know when this happens - the plug-in will report 0 tiles and 0.0%.

AttachmentSize
count_mosaic_tiles.py2.54 KB
count_mosaic_tiles_02.py2.54 KB
GIMP Version: 
Code License: 

Comments

where are results shown? Using Gimp 2.6.6 on Windows XP I created an image all Blue 0000ff and set that as background color. Then I painted some Red ff0000 randomly (with that as foreground color) covering about 25% of the image 736x736 pixels. Ran the plugin with parameters TileSize=50 pixels, Min percent=6, DrawGrid=NO I see the progress bar progressing but when it reaches end the script dialog disappears without displaying results. From your description I thought the dialog would remain displayed and show the results. What am I missing? Regards ... Alec (buralex@gmail.com) (Not sure if your response if any will automatically trigger a notification)

Hmm - I'm using pdb.gimp_message() to pop up a status report - I thought that was cross-platform? I did put a newline character in there - so I've uploaded a new script with a comma separating the info instead - let me know if that works...

Hi Chris: I replace old version with new version, first deleting the old version then ran gimp-2.6.exe -c from console. As you predicted (I just have checked this myself with the first version :-( ) the line: pdb.gimp_message( "Number of tiles: " + str(numtiles) + ", Total Percent: " + str(total_percent) + "%") writes to the console: === wget: glob: Please specify on or off. wget: illegal option -- u Usage: wget [OPTION]... [URL]... Try `wget --help' for more options. Count Mosaic Tiles-Warning: Number of tiles: 177, Total Percent: 41.7992063492% === Above is all the output in the "Gimp output" console window. (Not sure what the "wget" stuff is about, I've seen it before and presume it has nothing to do with your plugin). So on your (linux(?)) system the above is supposed to raise a pop-dialog box that can be [OK]'d after user acknowledges? I googled "pdb.gimp_message" and found http://www.iti.cs.tu-bs.de/soft/www.goof.com/pcg/marc/pdb/gimp_message.html AFAICT it *should* work. Would you like me to raise a bug or might it be some kind of configuration problem at my end? I haven't tried it on any version other that GIMP 2.6.6 - maybe a regression? I changed back to the "old version" by replacing the "," with "\n" using a text editor and then reran the plugin. As with first attempt, no popup dialog but the output in GIMP console is two lines. Would you like me to raise a GIMP-bug? Regards ... Alec

You just can't expect gimp_message to raise a popup message window. The error console dockable dialog is there to get rid of these.

If you want control over dialogs, then you have to derive a python plugin from gimpplugin and not gimp-fu.

According to the PDB:

gimp-message
    Internal GIMP Procedure
   Displays a dialog box with a message.

Parameters
    message STRING Message to display in the dialog

Additional Information
    Displays a dialog box with a message. Useful for status or error reporting. The message must be in UTF-8 encoding.

So, the documentation for this function is wrong?  Is there another function I should be looking for?

It depends. gimp-message should go wherever the handler is set using gimp-message-set-handler BUT (at least onwindows) starting GIMP with --console-messages will cause all messages to go to the console box, even with the handler set to MESSAGE-BOX. -Rob A>
Subscribe to Comments for "Count tiles for a mosaic"