It is currently 27 May 2020, 03:23

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | 🡆 Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Cropping script - small changes needed

Post your Script Requests for GIMP here.
Forum rules
Request your Script(s) for GIMP here in this forum.
Provide details of steps performed in GIMP so that script can be written for the process and also give the request a name so that scripts can be named after.
wvanoeveren
Forum Member

Re: Cropping script - small changes needed

Post#11 by wvanoeveren » 06 May 2019, 14:26


tim wrote:
06 May 2019, 04:21
I am not too sure about background process... I would just scan a batch of say 100 and then run this per batch or so.
Thanks Tim ! I will be testing version 3 out very soon and let you know !
Much appreciated for all your help ! :)
GIMP Learn rocks...
1

wvanoeveren
Forum Member

Post#12 by wvanoeveren » 21 May 2019, 16:27


wvanoeveren wrote:
06 May 2019, 14:26
tim wrote:
06 May 2019, 04:21
I am not too sure about background process... I would just scan a batch of say 100 and then run this per batch or so.
Thanks Tim ! I will be testing version 3 out very soon and let you know !
Much appreciated for all your help ! :)
Hey Tim,

just wanted to get back to you with some results (after a bit too long delay but been doing some in depth testing and some changes left & right on the script).
we (my colleague and me) have been setting up a system where we run the script per file that needs to be processed. Below you can find everything what we did on the script. Everything is working fine but the only thing is performance: we notice that the adding of the extra offset/padding of 250 pixels takes a very long time.
Maybe you have an idea on how we can solve this ?
Thanks again !

Cmd:
E:\gimppy>"c:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -idf --batch-interpreter python-fu-eval -b "import crop_border;crop_border.execute('E:/gimppy/0002.tif','E:/gimppy/0002_processed.tif',250)" -b "pdb.gimp_quit(1)"


Script: crop_border.py

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

from gimpfu import *
import datetime


def execute(sourcePath, targetPath, extraBorder):

dtStart = datetime.datetime.now()
gimpImage = pdb.file_tiff_load(sourcePath,sourcePath)
pdb.gimp_message("file_tiff_load: " + str(datetime.datetime.now()-dtStart))

pdb.gimp_image_undo_disable(gimpImage) #disable for better performance

activeLayer = pdb.gimp_image_get_active_layer(gimpImage)

dtStart = datetime.datetime.now()
pdb.gimp_fuzzy_select(activeLayer,5,5,85,CHANNEL_OP_REPLACE,TRUE,FALSE,0,TRUE) #fuzzy select in the corner (5,5), threshold was 42, but dirt on background gives issues so 85
pdb.gimp_message("gimp_fuzzy_select: " + str(datetime.datetime.now()-dtStart))

dtStart = datetime.datetime.now()
pdb.gimp_selection_grow(gimpImage,10) #grow selection 10 -> if I comment this, it doesnt work
pdb.gimp_message("gimp_selection_grow 10: " + str(datetime.datetime.now()-dtStart))

dtStart = datetime.datetime.now()
pdb.gimp_selection_invert(gimpImage) # invert it to have scanned page selected
pdb.gimp_message("gimp_selection_invert: " + str(datetime.datetime.now()-dtStart))

dtStart = datetime.datetime.now()
pdb.gimp_selection_grow(gimpImage,10) #grow selection 10
pdb.gimp_message("gimp_selection_grow 10: " + str(datetime.datetime.now()-dtStart))

dtStart = datetime.datetime.now()
pdb.gimp_selection_grow(gimpImage, extraBorder) #grow selection by parameter value
pdb.gimp_message("gimp_selection_grow extraBorder: " + str(datetime.datetime.now()-dtStart))

non_empty,x1,y1,x2,y2 = pdb.gimp_selection_bounds(gimpImage)

dtStart = datetime.datetime.now()
pdb.gimp_image_crop(gimpImage,x2-x1,y2-y1,x1,y1)
pdb.gimp_message("gimp_image_crop: " + str(datetime.datetime.now()-dtStart))

pdb.file_tiff_save(gimpImage,activeLayer,targetPath,targetPath,0)
pdb.gimp_image_delete(gimpImage)

Below is a screenshot of the command output with timing of every action.
image001.png
image001.png (132.84 KiB) Viewed 2923 times
GIMP Learn rocks...
0

tim
GL Blogger

Post#13 by tim » 21 May 2019, 17:06


the grow 10 is to get rid of artifacts on the scan. It isn't part of the adding extra border.
the adding extra border logic is in the below

Code: Select all

#add border padding before exporting it
pdb.gimp_image_resize(image,image.width+padding_width*2,image.height+padding_width*2,padding_width,padding_width)
		background = pdb.gimp_layer_new(image,image.width,image.height,GRAYA_IMAGE,"background to create border",100,LAYER_MODE_NORMAL)
		pdb.gimp_image_insert_layer(image,background,None,1)
		pdb.gimp_selection_none(image)
		pdb.gimp_edit_fill(background,FILL_FOREGROUND)
		layer = pdb.gimp_image_merge_down(image,layer,EXPAND_AS_NECESSARY)
or instead of grow 250... you can grab the image's selection bounds by using

Code: Select all

non_empty,x1,y1,x2,y2 = pdb.gimp_selection_bounds(image)
then select rectangle using

Code: Select all

pdb.gimp_image_select_rectangle(image,CHANNEL_OP_REPLACE,x1-250,y1-250,x2-x1+500,y2-y1+500)
it'd be faster than growing selection by 250pixels.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0


GIMP/GL:  Tutorials | Tips | Questions | Interests | 🡆 Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 7 guests