#!/usr/bin/env python # -*- coding: utf-8 -*- from gimpfu import * import ctypes def napln(image, drawable): # Merging operation pdb.gimp_image_undo_group_start(image) # Image size recognition and layer creation sirka = drawable.width vyska = drawable.height vrstva1 = pdb.gimp_layer_new_from_drawable(drawable, image) # Edge detection using Sobel operator pdb.plug_in_edge(image, drawable, 1, 0, 0) # Converting to gryscale according to the value parameter monochrome = TRUE rr_gain = 0.299 rg_gain = 0.299 rb_gain = 0.299 gr_gain = 0.587 gg_gain = 0.587 gb_gain = 0.587 br_gain = 0.114 bg_gain = 0.114 bb_gain = 0.114 pdb.plug_in_colors_channel_mixer(image, drawable, monochrome, rr_gain, rg_gain, rb_gain, gr_gain, gg_gain, gb_gain, br_gain, bg_gain, bb_gain) # Converting to monochrome pdb.gimp_image_convert_grayscale(image) # Bit depth recognition hloubka = drawable.bpp if pdb.gimp_drawable_has_alpha(drawable): hloubka = (256 ** (hloubka / 2)) - 1 else: hloubka = (256 ** hloubka) - 1 rozliseni = ((int(pdb.gimp_image_get_resolution(image)[0]) + int(pdb.gimp_image_get_resolution(image)[0])) / 2) # Average pixel value recognition histogram = pdb.gimp_drawable_histogram(drawable, 0, 0, 1) jdh = histogram[0] / hloubka jdh = jdh * 100 # Visualization of the map load distribution # pdb.gimp_drawable_invert(drawable, True) # pdb.gimp_drawable_brightness_contrast(drawable, -0.5, 0.5) sirka = int(sirka / 10) vyska = int(vyska / 10) if sirka > vyska: pdb.plug_in_pixelize2(image, drawable, vyska, vyska) else: pdb.plug_in_pixelize2(image, drawable, sirka, sirka) pdb.gimp_image_convert_rgb(image) vrstva2 = pdb.gimp_layer_new_from_drawable(drawable, image) pdb.gimp_layer_set_opacity(vrstva2, 85) pdb.gimp_image_insert_layer(image, vrstva1, None, -1) pdb.gimp_image_insert_layer(image, vrstva2, None, -1) # Value notification hlaska = "" if rozliseni != 100: hlaska = " Warning: Image resolution is " + str(rozliseni) + " DPI while 100 DPI is recommended\n\n" hlaska = hlaska + " Map load value: " + str(round(jdh, 1)) + " %" ctypes.windll.user32.MessageBoxW(0, unicode(hlaska, "utf-8"), u"MEASUREMENT RESULTS", 0x40) # Finishing operations pdb.gimp_image_undo_group_end(image) register( "MAPLOAD_1-1", "Experimental tool for graphic map load measurement based on edge detection", "Experimental tool for graphic map load measurement based on edge detection using Sobel operator, developed at the Department of Geoinformatics, Palacký University Olomouc within the research project Graphic map load evaluation using metrics based od raster format (resolution 100 DPI prefered)", "Radek Barvíř", "CC BY-SA", "v 1.1, build 201125, 2020", "GMLMT 1.1 (map load)", "RGB*", [ (PF_IMAGE, "image", "takes current image", None), (PF_DRAWABLE, "drawable", "Input layer", None) ], [], napln, menu="/Filters/Edge-Detect") main()