It is currently Sat Jul 06, 2024 7:16 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: I need an automation script to separate left and right pages
PostPosted: Mon Apr 03, 2017 11:06 pm  (#1) 
Offline
GimpChat Member

Joined: Apr 03, 2017
Posts: 7
I have just joined.
I initially posted my query to the gimp user list gnome org with the subject,
Quote:
Does GIMP have automated macro / batch processing?
.
I was told that gimp did not have such utilities, but could be done with scripts, such as script-fu or python.
I wrote there:
Quote:
What I need is a script as follows:
I have a book that I have scanned. It has both the left page and the right page.
When the script is run, it will open a copy of the file in a new
window and first select the right page, wait for minor alterations in
selection, when done, will delete the selected area and autocrop the
image to have the left page. Rename the page as "file name"_left.jpg
and close the new file.
Then it will open another copy of the file, select the left page, ait
for minor alterations in selection, when done, will delete the
selected area and autocrop the image to have the right page. Rename
the page as "file name"_right.jpg and close the new file.
Regards

I have some rudimentary ideas about programming in c language, but I don't have memorised sample complete codes, as I don't do programming. I don't need to program as I find all I need from the internet and Open Source Software. I am an end-user. I don't have what could be phrased as coding even without motivation, where coding for the sake of coding is in itself a motivation. I am not that specially gifted to learn and then code like magic.
How could I be helped in this regard?
I found this forum when I searched my need in Google. When I asked about this forum to the gimp user list I was advised that I post my requirement in this forum, as there is an opportunity for me to be helped, here.
Thank you for reading my post.
Regards


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: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 3:24 am  (#2) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2439
Maybe one of the clever guys will come up with a bespoke script.
However (always a however) Using what is already available...

Why not split the process into separate stages rather than complicate matters.

There are scripts that will close and save an image after editing then open the next image in an ordered list, such as you get from a scanner. Edit both left & right pages before moving on to the next image.

Look for ofn-file-next.py https://sourceforge.net/projects/gimp-t ... s/scripts/ down halfway of the page.

As a totally separate operation, split the edited images into two using an ImageMagick (IM) batch file. You could ask on the IM users forum where they are very helpful. https://www.imagemagick.org/discourse-server.

It would need to be wrapped in a bash/bat file to split a folder full of images into left/right parts. A bit messy, but in linux it could be something like
#!/bin/bash
  find . -name "*.png" | while read fname ; do
     echo "Doing:  $fname"
     convert -crop 50%x100% +repage $fname "$fname"%d.jpg
     mv "$fname"0.jpg "$fname"_left.jpg
     mv "$fname"1.jpg "$fname"_right.jpg
  done


best of luck.

edit: must get left and right the correct way round ;)

_________________
Image


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 5:43 am  (#3) 
Offline
GimpChat Member

Joined: Apr 03, 2017
Posts: 7
rich2005 wrote:
Why not split the process into separate stages rather than complicate matters.

There are scripts that will close and save an image after editing then open the next image in an ordered list, such as you get from a scanner. Edit both left & right pages before moving on to the next image.

Thanks for your reply.
I have read your reply. I could not visualise the above part.
I am a little slow up there.
I have 20 images of a book (left & right in one image) in ordered list from scanner.
Now considering the scenario, could you please elaborately illustrate?
Thanks once again and regards


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 7:06 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
So you want to take a folder of images split each image in exact equal halves into 2 layers. Then work on each layer (per selections) and save both layers as separate images?
What do you mean by selections? Will these be made by the user BEFORE running the script or will the selections be made by the script itself?

It would be easier to know if you have done these steps in GIMP already and have a workflow.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 7:46 am  (#5) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2439
@ bkpsusmitaa

Still do not know what OS you are using, but here is a video demo in linux using Ofnuts plug-in and a bash script as mentioned earlier.

https://youtu.be/i-FLVBhf7dI duration 4 min 30 sec

_________________
Image


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 9:07 am  (#6) 
Offline
GimpChat Member

Joined: Apr 03, 2017
Posts: 7
Rod wrote:
So you want to take a folder of images

No, this part is easy. I have the folder. Copy the entire folder. Rename earlier folder as "folder_name"_lt and the latter as "folder_name"_rt, lt for left and rt for right. Now I can concentrate of left and right portions separately.
Rod wrote:
split each image in exact equal halves into 2 layers.

No layers, just open the image.
Rod wrote:
What do you mean by selections?

I select the right part. Assume that the image size is 3500X2400. The two pages are along the longer side. Select the right page, i.e., selection range 1750X2400. The selection could be automated. I could do minor alterations, like changing the selection to cover the area to be deleted.
Rod wrote:
It would be easier to know if you have done these steps in GIMP already and have a workflow.

Yes, I have the work-flow. This is how I am doing it presently, manually.
First, to work on the left folder.
Open a file. Copy the image/'File>Create From ClpBrd'/Select right half/Copy & let the selection be in the memory. Let the copied file remain open, and don't disturb it any further. Store this file as xcf including the selection.
Open the next file. What I am doing to open a file and alter it:
Alt+F/O/ 2-layers (1 thumbnail + image) / Ctl+A (select all)/ Alt+I (import)/ Ctl+V (then adjust the layer and block right half. Then click outside to paste the layer on the rt side of image) / Alt+I E (autocrop) / Alt+F W (overwrite file) / Ctl+W (close without saving option)/Alt+W(close without saving, as the file is already overwritten)
The file is modified as only having the left page and saved.

rich2005 wrote:
Still do not know what OS you are using

Knoppix 7.2.0
rich2005 wrote:
here is a video demo in linux using Ofnuts plug-in and a bash script

What does the demo teach? My broadband bandwidth is limited unlike the west's speed and higher limits.
Thanks for asking.


Last edited by bkpsusmitaa on Tue Apr 04, 2017 10:23 am, edited 1 time in total.

Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 10:06 am  (#7) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2439
Quote:
What does the demo teach? My broadband bandwidth is limited unlike the west's speed and higher limits.
Thanks for asking.


Well, that was a waste of time then

What does it show?
Ofnuts plugin, (unzip it first) installed in ~/.gimp-2.8/plug-ins & check that it is still executable.
Open first image, edit
use the plugin which gives File -> Next Image to progress (to next numbered image)
Repeat process after each edit

When complete in Gimp
Open terminal, in the folder with the edited images, execute the bash script which uses ImageMagick - Install this using your package manager.
Original files are split in the center and saved as left/right jpegs.


Also pointed out that Gimp has a built-in splitter: Image -> Transform -> Guillotine which divides the open image along a guide(s) see:
https://docs.gimp.org/en/gimp-concepts- ... uides.html
and
https://docs.gimp.org/en/plug-in-guillotine.html

and for 20 pages this might be a better bet than wasting your time trying to save a few seconds using a script.

_________________
Image


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Tue Apr 04, 2017 11:30 am  (#8) 
Offline
GimpChat Member

Joined: Apr 03, 2017
Posts: 7
rich2005 wrote:
Also pointed out that Gimp has a built-in splitter: Image -> Transform -> Guillotine which divides the open image along a guide(s) see:
docs gimp org/en/gimp-concepts-image-guides.html
and
docs gimp org/en/plug-in-guillotine.html

Why did you use the sentence with "Also pointed out..."? Where is it pointed out? Within the script? Or are you instead using the passive form, "It is also pointed out...." meaning that you are also pointing out ...?
I wanted to thank you at the very beginning of my present post but then I thought you might skip the query above.
This guillotine is a wonderful tool, unlike the ones used during the French Revolutions :-) I didn't know about the tool at all!
But the trouble is that the option "overwrite..." with my work-flow is no longer available. And I have already made two folders, left and right. And have already proceeded with the work.
It's true that for 20 pages, it is better done manually. But I wanted the script for future projects.
Let me think and find out something quick and less monotonous to be implemented.
Thank you for introducing me to a wonderful tool!


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Mon Nov 20, 2017 11:05 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jul 04, 2010
Posts: 2253
Location: Retired Moderator Slowly Returning to the Living.
I wrote a script that switches the two sides of an image. (used for 3D image creation)
Here is a modified version of the script that does the switch, without merging the switched halves.
This would give you each page half as a separate layer. I hope this helps.

(define (script-fu-switch-sides img baselayer)

    (let* (
          (ImageW (car (gimp-image-width img)))                                     ; Image width
         (ImageH (car (gimp-image-height img)))                                    ; Image height
          (HalfW (* ImageW 0.5))
          (baseline (car (gimp-layer-new img ImageW ImageH 1 "Switch" 100 0)))
          (Switch (car (gimp-layer-new img ImageW ImageH 1 "Switch" 100 0)))        ; Layer for Switch
        )
       (gimp-image-undo-group-start img)
        (gimp-layer-add-alpha baselayer)
        (gimp-selection-all img)
      (gimp-edit-copy baselayer)
      (gimp-selection-none img)
        (gimp-image-add-layer img Switch -1)
      (gimp-floating-sel-anchor (car(gimp-edit-paste Switch 1)))
      (gimp-rect-select img 0 0 HalfW ImageH 0 0 0)
      (gimp-edit-cut Switch)
      (gimp-selection-invert img)
      (gimp-edit-cut baselayer)
      (gimp-selection-none img)
        (gimp-drawable-offset Switch 1 1 HalfW 0)
        (gimp-drawable-offset baselayer 1 1 HalfW 0)
;        (gimp-image-flatten   img)   
;      (gimp-image-merge-down img Switch 0)
    (gimp-image-undo-group-end img)
    (gimp-displays-flush)))

(script-fu-register "script-fu-switch-sides"
          "<Image>/Filters/Distorts/Switch Sides"
          "Switch Image Halfs Horizontally For Cross View 3D"
          "Gregory M. Ross"
          "Gregory M. Ross"
          "April 2010"
          ""
          SF-IMAGE    "Image" 0
          SF-DRAWABLE "Drawable" 0)
         
   

_________________
Artists aren't crazy! We're eccentric! ~G.M. Ross

Image

My Sigs = My Photos
Check out my work at http://www.flickr.com/photos/photomastergreg.


Top
 Post subject: Re: I need an automation script to separate left and right pages
PostPosted: Mon Nov 20, 2017 11:29 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Jul 04, 2010
Posts: 2253
Location: Retired Moderator Slowly Returning to the Living.
Here you'll see the result of the script:
Original Un-switched image
Attachment:
Screenshot_991.jpg
Screenshot_991.jpg [ 190.77 KiB | Viewed 4629 times ]

Switched image. Note the two layers in the layers list.


Attachments:
Screenshot_992.jpg
Screenshot_992.jpg [ 191.27 KiB | Viewed 4629 times ]

_________________
Artists aren't crazy! We're eccentric! ~G.M. Ross

Image

My Sigs = My Photos
Check out my work at http://www.flickr.com/photos/photomastergreg.
Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How much you'd save with automation

0

No new posts Automation / Layer Manipulation

0

No new posts Italians over 80 'will be left to die' as country overwhelmed by coron

8

No new posts Attachment(s) When Digital Image Files are Left in a Shoebox for Too Long

8



* Login  



Powered by phpBB3 © phpBB Group