It is currently Thu Apr 25, 2024 2:46 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Errors when running script from Terminal (stroke selection)
PostPosted: Tue Jul 07, 2015 9:04 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
I'm modifying an existing (and working) Gimp script. As is, it takes in a TIFF, applies brightness-contrast, and thresholds the image. I'm adding code to also select the black parts of the thresholded image and stroke the selection. Something is going wrong in the stroking part when I run the edited script from the Terminal. I get these errors:

(GIMP-bin:93172): Gimp-Core-CRITICAL **: gimp_object_get_name: assertion 'GIMP_IS_OBJECT (object_typed)' failed

(GIMP-bin:93172): LibGimpConfig-CRITICAL **: gimp_config_duplicate: assertion 'GIMP_IS_CONFIG (config)' failed

(GIMP-bin:93172): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed


However when I run the same script (hardcoded with the appropriate image and drawable values) from the Script-Fu console it works perfectly.

Any help would be most appreciated!

This is the script (note that inputfile and thresholdfile come from elsewhere in the Python script in which this is embedded):

(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE inputfile inputfile)))
      (drawable (car (gimp-image-get-active-layer image))))
      (gimp-selection-none image)
      (gimp-brightness-contrast drawable -50 95)
      (gimp-threshold drawable 145 255)
      (gimp-image-select-color image 0 drawable "#000000")
      (gimp-context-set-brush "1. Pixel")
      (gimp-context-set-brush-size 4)
      (gimp-edit-stroke drawable)
      (gimp-selection-none image)
      (gimp-file-save RUN-NONINTERACTIVE image drawable thresholdfile thresholdfile)
      (gimp-image-delete image)))


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: Errors when running script from Terminal (stroke selection)
PostPosted: Tue Jul 07, 2015 11:16 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
I suspect the problem lies with how your Python code is declaring and invoking the Scheme code. More details on these aspects of your script would be helpful. Perhaps you could post TWDT.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 12:08 am  (#3) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
TWDT is pretty long, but only the highlighted lines were altered. Had to put the [dot] because I'm a new user and not yet allowed to post actual links.

https://github [dot] com/emanuelfeld/map-vectorizer/blob/master/vectorize_map.py#L70-L74


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 3:08 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
friedland wrote:
TWDT is pretty long, but only the highlighted lines were altered. Had to put the [dot] because I'm a new user and not yet allowed to post actual links.

https://github [dot] com/emanuelfeld/map-vectorizer/blob/master/vectorize_map.py#L70-L74


Hmmm. Do you know that you can script Gimp in Python too? Then instead of calling Gimp, you script runs as a Gimp plugin...

Otherwise can you post the exact full command line that calls Gimp?

_________________
Image


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 3:52 am  (#5) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
friedland wrote:
However when I run the same script (hardcoded with the appropriate image and drawable values) from the Script-Fu console it works perfectly.

If you start Gimp from a Linux terminal or Windows Command Window, I think you will find that the same error messages are output when the script is run from the Script-Fu Console.

The question is: does the script actually do what you want/expect it to do when invoked from Python? If so, you can probably just ignore these error messages (even though it does say "CRITICAL" !).


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 4:43 am  (#6) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
I notice that you are not setting the foreground color before stroking the selection, so Gimp will use black by default.
In other words, you're selecting the black part of the thresholded image and then stroking with a 4px black brush. So you won't actually see a lot of difference.
Is that really what you intended to do? Just to smoothen the outline, presumably.
As far as I can see the script does actually work, and the GLib-CRITICAL error message is just a red herring.
Please check whether you are actually getting the output you expected.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 9:53 am  (#7) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
jontait2, you're right, it was outputting essentially what I intended and those were red herrings. The reason I'd like to add the stroking commands is that I'm dealing with scans of hand drawn maps. Some of the area boundary lines develop small gaps in the thresholding process and I'm thinking this may improve the output.

The issue seems to be that the TIFF is multi-page and the wrong layer is being selected for the drawable. I had switched the selection from:

(drawable (car (gimp-image-get-layer-by-name image "Background")))

to:

(drawable (car (gimp-image-get-active-layer image)))

The correct layer *should* be "Background". Oddly, switching back to the original drawable selection command results in a set of new (and actual) failures:

(GIMP-bin:2317): Gimp-Core-CRITICAL **: gimp_object_get_name: assertion 'GIMP_IS_OBJECT (object_typed)' failed

(GIMP-bin:2317): LibGimpConfig-CRITICAL **: gimp_config_duplicate: assertion 'GIMP_IS_CONFIG (config)' failed

(GIMP-bin:2317): Gimp-Paint-CRITICAL **: gimp_paint_core_stroke_boundary: assertion 'bound_segs != NULL && n_bound_segs > 0' failed

(GIMP-bin:2317): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
batch command experienced an execution error:
Error: ( : 2) Procedure execution of gimp-edit-stroke failed


Should I just try some way of splitting the TIFF pages in advance? Many thanks!


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 10:15 am  (#8) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Hmmm...
I think there is something a bit funny going on here. Perhaps you have trodden on a bug after all.
Bear in mind that you may be breaking new ground here. The vast majority of batch commands just use Gimp to process whole images (eg. re-sizing, cropping, etc). It may very well be that nobody has actually tried stroking a selection in batch mode before!
I will have another look later.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 10:32 am  (#9) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
The batch mode selection stroking does actually work with the test.tif file provided in the repo. And it works with either drawable selection command.

That file is only one page. The new TIFF I'm trying to use is multi-page for some reason (though each page is just a different size of the same image and I only need the biggest). It was produced by the georeferencing tool at mapwarper [dot] net.

I'll upload that TIFF to the repo as new.tif.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 3:22 pm  (#10) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
I was able to remove the extra pages from the geotiff and avoid the error by applying gdalwarp to the image, i.e.:

gdalwarp -t_srs "EPSG:4326" input.tif output.tif


The README in the repo I forked from had this as a step, but was intended to get the file in the right coordinate reference system for the later steps of turning the image into a vector map. This step wasn't necessary to produce the correct output if the stroking step was not applied. Further, I could put any coordinate reference system there—not just EPSG:4326.

So, it seems, gdalwarp's only role in this case was to remove the extra TIFF pages that produced the error in Gimp.

Still not sure why I couldn't apply the stroke in a multi-page setting…


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 4:03 pm  (#11) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Hmm..
I'm not sure how this worked before, but if you're going to use the form:
(drawable (car (gimp-image-get-layer-by-name image "Background")))
you then need to do:
(gimp-image-set-active-layer image drawable)
to actually select that layer as the active layer.

I've tried it successfully with your new.tif image from the Script-Fu Console using this code:
(define inputfile "/home/jjt/Pictures/tiff/new.tif")
(define thresholdfile "/home/jjt/Pictures/tiff/new-out.tif")
(let*
  (
    (image (car (file-tiff-load RUN-NONINTERACTIVE inputfile inputfile)))
     (drawable (car (gimp-image-get-layer-by-name image "Background")))
  )
  (gimp-image-set-active-layer image drawable)         ;*JT*
  (plug-in-autocrop-layer RUN-NONINTERACTIVE image drawable)   ;*JT*
  (gimp-brightness-contrast drawable -50 95)
  (gimp-threshold drawable 145 255)
  (gimp-image-select-color image CHANNEL-OP-REPLACE drawable "#000000")
  (gimp-context-set-brush "1. Pixel")
  (gimp-context-set-brush-size 4)
  (gimp-edit-stroke drawable)
  (gimp-selection-none image)
  (gimp-file-save RUN-NONINTERACTIVE image drawable thresholdfile thresholdfile)
  (gimp-image-delete image)
)

Note that I've also auto-cropped the Background layer since the actual pic is only about 800x1300px on a layer of about 8500x4700px. If that is typical of the input files, perhaps it would be better to include the autocrop.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 5:04 pm  (#12) 
Offline
GimpChat Member

Joined: Jul 07, 2015
Posts: 6
Awesome, thanks for your help! I'll give that a go. That cropping won't be typical of input files—it's subset from a larger map image for testing.


Top
 Post subject: Re: Errors when running script from Terminal (stroke selection)
PostPosted: Wed Jul 08, 2015 5:36 pm  (#13) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Okay, I have now run it from iPython using this code:
import os
brightness=-50
contrast=95
thresholdblack=145
thresholdwhite=255
inputfile="/home/jjt/Pictures/tiff/new.tif"
thresholdfile="/home/jjt/Pictures/tiff/new-out.tif"
gimp_path="/usr/bin/gimp"
contraststring = '(gimp-brightness-contrast drawable ' + str(brightness) + ' ' + str(contrast) + ')'
thresholdstring = '(gimp-threshold drawable ' + str(thresholdblack) + ' ' + str(thresholdwhite) + ')'
colorselectstring = '(gimp-image-select-color image CHANNEL-OP-REPLACE drawable "#000000")'
brushstring = '(gimp-context-set-brush "1. Pixel")'
brushsizestring = '(gimp-context-set-brush-size 4)'
strokestring = '(gimp-edit-stroke drawable)'
gimpcommand = '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE "' + inputfile + '" "' + inputfile + '"))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-image-set-active-layer image drawable) (plug-in-autocrop-layer RUN-NONINTERACTIVE image drawable) ' + contraststring + ' ' + thresholdstring + ' ' + colorselectstring + ' ' + brushstring + ' ' + brushsizestring + ' ' + strokestring + ' (gimp-selection-none image) (gimp-file-save RUN-NONINTERACTIVE image drawable "' + thresholdfile + '" "' + thresholdfile + '") (gimp-image-delete image))'
command = gimp_path + ' -i -b \'' + gimpcommand + '\' -b \'(gimp-quit 0)\''
os.system(command)

and it seems to do the job, though strangely there is a slight difference in contrast between the output .tif produced when I run it from Script-Fu Console and when I run it from iPython. (Go figure!)


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


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

4

No new posts Attachment(s) stroke selection/stroke path

2

No new posts Can a python script use gimpfu, run from terminal, and create new img?

2

No new posts Attachment(s) Board Game Design - Stroke Selection and Pattern Fill Questions

3

No new posts Attachment(s) Error when running Set Colormap script

1



* Login  



Powered by phpBB3 © phpBB Group