GimpTalk Announcement :
Try your digital-art skills against your fellow gimpers in GIMPtalk's Biweekly Art competition !


Board index » GIMP Art Galleries and Resources » GIMP Plugins, Filters, and Scripts Web Development Services . Convert FLV to Cell Phone Format
Featured Tutorial : Learn how to create characters by Griatch
Search for :  


Post new topic Reply to topic   [ 33 posts ]   Go to page 1, 2  Next


Author Message
Offline
 Post subject: Divide OR Crop Multiple Images from Single Scan
PostPosted: Sat Dec 20, 2008 4:49 pm 

Joined:
Sat Dec 20, 2008 4:23 pm

Topics:
Posts: 1

Find User's Topics

Quote:
In Adobe Photoshop Elements there is a function called "Divide scanned images" which i assume uses the whitespace between multiple images from a flatbed scan and separates each photo into a new image. does anyone know of a script that will do something similar in GIMP? I am getting my father a scanner for Xmas and wanted to find a relatively straightforward solution like Elements but the 130 for the software is out of my budget.

Here is the Elements process...
Image




_________________
affordable and convenient Computer Repair Done Right - Flat Rate Pricing - Remote Assistance, Pickup/Delivery, On Site

http://www.phillyhelpdesk.com

ImageImage


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Dec 22, 2008 8:26 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
Try this script I threw together. However, it doesn't rotate the images if they are misaligned...

Code:
   See below for the improved script...


-Rob A>


Last edited by RobA on Tue Dec 23, 2008 4:50 pm, edited 1 time in total.

Top
 Profile  
 
Online
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Tue Dec 23, 2008 11:24 am 
GT Manager

User avatar

Joined:
Mon Jun 13, 2005 11:15 am

Topics:
Posts: 10800

Find User's Topics
cool :)

_________________
Image

http://www.flickr.com/photos/97844002@N00/


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Tue Dec 23, 2008 4:48 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
OK -

Bit of an update. I tried this on a real scanner and the noise created a whole bunch of little images. I've now added a size threshold slider, and the script will call the deskew plugin http://www.cubewano.org/gimp-deskew-plugin/ if it is installed.

See below for the latest version

Here is a scan I made with three photos on the platen:
Image

and the three resulting images it extracted and straightened:
Image
Image
Image

As a final note, the script used the colour at 0,0 as the background reference, so if your scanner has a shadow there it might be off.... I don't know a way to have a user specify a pick point in a script-fu :(

Feedback always appreciated!

-Rob A>


Last edited by RobA on Thu Jan 29, 2009 1:23 pm, edited 1 time in total.

Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 01, 2009 1:00 am 

Joined:
Thu Jan 01, 2009 12:54 am

Topics:
Posts: 4

Find User's Topics
Thanks, RobA.

I have successfully installed the plugin and the script.

The script seems to run, but is unable to extract multiple images. [In one instance, it seemed to enter an infinite loop.]

Do I need to set the initial sliders to something other than 10 and 100 ? Appreciate if you can provide an intro to the two parameters.

This will truly save me a ton of time if I can somehow get it to work in my envt.


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 01, 2009 8:51 am 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
The 10 is the tolerance. You can test it by using the magic wand tool set to 10 and clicking at 0,0 to see what gets selected (Hopefully it is the whole background) but it will depend on the noise of the bg from your scanner.

If there are lots of speckles/noise it will iterate through all of them, so setting this higher is best.

The other parameter is the minimum size for an image. and smaller items will be ignored. Set it as large as posible, just smaller than your largest image.

I'm working on a better version, so hopefully this will help for now...

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Tue Jan 13, 2009 5:54 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
One more update...

This now uses rectangular selections rather than the selection from the path (I could make this a toggle, I guess)...

Also, there is a new "Abort Limit" parameter to keep the plugin from going into a nasty loop if the parameters don't make a lot of sense.

See below for the latest version


Last edited by RobA on Thu Jan 29, 2009 1:24 pm, edited 1 time in total.

Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 15, 2009 1:27 am 

Joined:
Thu Jan 01, 2009 12:54 am

Topics:
Posts: 4

Find User's Topics
Rob,

I copied and pasted this in the script file, and re-started GIMP. I get the following error.

ERROR: NOT ENOUGH ARGUMENTS

Possibly, coz at the end of the script you have the Abort Limit parameter, but no input on the dialog box.

Rajnish


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 15, 2009 2:44 am 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
mishra wrote:
Possibly, coz at the end of the script you have the Abort Limit parameter, but no input on the dialog box.

Rajnish


It is the last line!

Did you copy all of it?

Did you insert linefeeds because of the text editor you used?

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 15, 2009 2:57 am 

Joined:
Thu Jan 01, 2009 12:54 am

Topics:
Posts: 4

Find User's Topics
My bad.

I simply re-copied and pasted and it is now working correctly.

Beginning to test it out. Will update you soon.


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Jan 26, 2009 8:23 pm 

Joined:
Thu Jan 01, 2009 12:54 am

Topics:
Posts: 4

Find User's Topics
Rob,

Sorry, it took me longer than expected. But, I wanted to experiment exhaustively before commenting. I have now tested the script with (1) the photos on your post and (2) my own photos.

The photos from your post work perfectly. It seems like this could be the solution and we would want all the photos to work like that, including de-skew.

In case of my own photos, it is unable to extract two photos from a single collage. I have tried various settings on size [between 0 and 20] and selection [10 to 200] thresholds without success.

I started troubleshooting and noticed that with the fuzzy tool selection tool set to background [in my case, it is white or something close to it], and selection threshold set to zero, it is able to find the two picture on my scanned image. Albeit with some jagged edges, but I am assuming your script takes care of that.

Could you help me in understanding how best to accomplish it ?

Thanks,

Rajnish


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Jan 26, 2009 10:21 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
Could you post a full page scan sample somewhere? You can pm me with the details if you don't wish to post publicly.

There are a few factors that could mess it up, primarilly a shadow arounf the scanner frame, so that is what I would need to see and correct for.

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Thu Jan 29, 2009 1:30 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
Here is an updated version that I have had an oportunity to test with a few moew scanned images (thanks Rajnish)

This simplifies the selection at the beginning to speed up the process and denoise the image more.

It also stops incorrect returns of the entire image due to bad paths.

Lastly, it provides X and Y offsets to allow compensate for scanner beds that introduce a shadow along the edges of a full page scan.

Code:
; DivideScannedImages.scm
; by Rob Antonishen
; http://ffaat.pointclark.net

; Version 1.3 (20090128)

; Description
;
; Locates each separate element and creates a new image from each.
; will call the deskew plugin http://www.cubewano.org/gimp-deskew-plugin/
; if it is installed on each image
;
; Changes:
; v1.1 - Added a size threshold slider, and it will call the deskew plugin if installed
; v1.2 - takes a rectangular selection bounding the path rather than a selection from the path itself, added an abort threshold incase the parameters are wonky
; v1.3 - simplifies the selection via feather/sharpen first to speed up the image analysis.
;        - fixed exporting the whole image as one.
;        - added sliders to pick a background offset.  This is useful if your scanner has a "shadow" around the edge of full scans,
;
; License:
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html

(define (script_fu_DivideScannedImages img inLayer inThreshold inSize inLimit inX inY)

  (let*
    (
     (width (car (gimp-image-width img)))
     (height (car (gimp-image-height img)))
     (newpath 0)
     (strokes 0)
     (tempVector 0)
     (tempImage 0)
     (tempLayer 0)
     (bounds 0)
     (count 0)
     (numextracted 0)
   )
    ;  it begins here
    (gimp-context-push)
    (gimp-image-undo-disable img)
   
   ;logging
   ;(gimp-message-set-handler ERROR-CONSOLE)
    ;(gimp-message-set-handler CONSOLE)
    ;(gimp-message-set-handler MESSAGE-BOX)
   ;or start GIMP wwith "gimp --console-messages" to spawn a console box
   ;then use this:
   ;(gimp-message "foobar")

   ;testing for functions defined
   ;(if (defined? 'plug-in-shift) (gimp-message "It Exists") (gimp-message "Doesnt Exist"))

   ;use 0,0 as the background colour
   (gimp-context-set-background (car (gimp-image-pick-color img inLayer inX inY FALSE FALSE 0)))
   
   ; convert in inverted copy of the background selection to a path
   (gimp-fuzzy-select inLayer inX inY inThreshold CHANNEL-OP-REPLACE TRUE FALSE 0 TRUE)
    (gimp-selection-feather img (/ (min width height) 100))
   (gimp-selection-sharpen img)
   (gimp-selection-invert img)
   (plug-in-sel2path RUN-NONINTERACTIVE img inLayer)
   
   ;break up the vectors
    (set! newpath (vector-ref (cadr (gimp-image-get-vectors img)) 0))
   
   (set! strokes (gimp-vectors-get-strokes newpath))
    (while (and (< count (car strokes)) (< numextracted inLimit))
     (set! tempVector (gimp-vectors-new img "Temp"))
     (gimp-image-add-vectors img (car tempVector) -1)
     (gimp-vectors-stroke-new-from-points (car tempVector)
       (list-ref (gimp-vectors-stroke-get-points newpath (vector-ref (cadr strokes) count)) 0)
       (list-ref (gimp-vectors-stroke-get-points newpath (vector-ref (cadr strokes) count)) 1)
       (list-ref (gimp-vectors-stroke-get-points newpath (vector-ref (cadr strokes) count)) 2)
       (list-ref (gimp-vectors-stroke-get-points newpath (vector-ref (cadr strokes) count)) 3)
     )
     (gimp-vectors-to-selection (car tempVector) CHANNEL-OP-REPLACE TRUE FALSE 0 0)
    
     ;check for minimum size
     (set! bounds (gimp-selection-bounds img))
     (if (and (> (- (list-ref bounds 3) (list-ref bounds 1)) inSize) (> (- (list-ref bounds 4) (list-ref bounds 2)) inSize) ;min size slider
              (< (- (list-ref bounds 3) (list-ref bounds 1)) width) (< (- (list-ref bounds 4) (list-ref bounds 2)) height)) ;max size image
       (begin
        (gimp-rect-select img (list-ref bounds 1) (list-ref bounds 2)
                        (- (list-ref bounds 3) (list-ref bounds 1)) (- (list-ref bounds 4) (list-ref bounds 2))
                        CHANNEL-OP-REPLACE FALSE 0 )
         (gimp-edit-copy inLayer)
         (set! tempImage (car (gimp-edit-paste-as-new)))
          (gimp-image-undo-disable tempImage)
         (gimp-display-new tempImage)
    
         ;run deskew if it is installed
         (if (defined? 'gimp-deskew-plugin)
           (begin
            (set! tempLayer (car (gimp-image-get-active-layer tempImage)))
            (gimp-layer-flatten tempLayer)
            (gimp-deskew-plugin 0 tempImage tempLayer 0 0 0 0 0)
            (gimp-image-resize-to-layers tempImage)
            (gimp-layer-flatten tempLayer)
            (plug-in-autocrop RUN-NONINTERACTIVE tempImage tempLayer)
          )
         )
        (gimp-image-undo-enable tempImage)
        (set! numextracted (+ numextracted 1))
       )
      )      
     (gimp-image-remove-vectors img (car tempVector))
     (set! count (+ count 1))
   )

   ;delete temp path
   (gimp-image-remove-vectors img newpath)
   (gimp-selection-none img)
   
   ;done
   (gimp-image-undo-enable img)
   (gimp-progress-end)
   (gimp-displays-flush)
   (gimp-context-pop)
  )
)

(script-fu-register "script_fu_DivideScannedImages"
                  "<Image>/Filters/Divide Scanned Images..."
                    "Attempts to isolate each part of the image from the background and creates a new image from it"
                    "Rob Antonishen"
                    "Rob Antonishen"
                    "Dec 2008"
                    "RGB* GRAY*"
                    SF-IMAGE      "image"      0
                    SF-DRAWABLE   "drawable"   0
               SF-ADJUSTMENT "Selection Threshold"    (list 10 0 255 1 10 1 SF-SLIDER)
               SF-ADJUSTMENT "Size Threshold"         (list 100 0 2000 10 100 1 SF-SLIDER)      
               SF-ADJUSTMENT "Abort Limit"            (list 5 1 100 1 10 1 SF-SLIDER)                     
               SF-ADJUSTMENT "Background Sample X Offset"    (list 5 1 100 1 10 1 SF-SLIDER)                     
               SF-ADJUSTMENT "Background Sample Y Offset"    (list 5 1 100 1 10 1 SF-SLIDER)                     
)


-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Sun Apr 05, 2009 6:32 pm 

Joined:
Sun Apr 05, 2009 6:29 pm

Topics:
Posts: 4

Find User's Topics
I am using the plugin "Divide Scanned Images" and is working well. My thanks to the author as it saved me some time, but now I am still wasting time doing the following:

If I place 4 photos on my fb scanner, scan them, then run the plugin, it correctly separates the scan into four images.

The problem is I now have to file, save as on each of the four images, enter a filename and extension, answer the jpg prompt and finally get the image to save.

Is there a script/plugin/a default value or another method I can use to quickly save all 4 images as jpg with a filename that increments from the last filename, such as image0001.jpg, image 0002.jpg, etc.

Thanks in advance.


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Sun Apr 05, 2009 11:08 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
Well.... are you on windows or linux?

I have extended the script to allow this, using something called parasites, and discovered a bug in tiny-fu using parasites that can cause the script to fail ungracefully, or cause gimp to crash completely. It happens a lot on windows, and occasionally under linux.

I have posted the bug report, but suspect it won't get fixed for a while.

The only option I can think of to get it working is to port the whole thing over to python.... which I am working on, learning python as I go :)

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Apr 20, 2009 12:52 am 

Joined:
Sun Apr 05, 2009 6:29 pm

Topics:
Posts: 4

Find User's Topics
Sorry for the long wait.

Running it on Vista.

Also, I have another issue. A number of my photos and business cards that have a lot of white background and the plugin is not picking up the photo separation properly. I was thinking about using an off-color such as Flourescent Green paper on the scanner's lid so when the white items are scanned, the plugin can pick up the separation easier. But by using the plugin, it assumes the green paper is part of the image and therefore no images are separated. Is there a way to tell the plugin to use a different color, etc. as the background separation.


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Apr 20, 2009 1:40 am 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
madthad-

The script samples the image using the background X and Y offsets to determine the "background" colour. So long as you set these offsets to get past any shadow it should work....

I have an updated version here: http://ffaat.pointclark.net/incoming/sc ... Images.scm

This one allows you to specify the corner to sample for the background colour, which is handy if your scanner has a larger shadow on a couple of edges, or if you want to align an image in the upper right hand corner.

It also will allow you to save the extracted files by specifying a directory and a file prefix and start number, then incrementing them for each image scanned. I haven;t played with the auto-saving much, but it seems to work OK.

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Apr 20, 2009 2:34 am 

Joined:
Sun Apr 05, 2009 6:29 pm

Topics:
Posts: 4

Find User's Topics
Rob, thanks a bunch. I downloaded the new version and it is exactly what I was looking for. But... The issue with the business cards scanning comes down to this:
- Cards are 3.5" x 2" or 252px x 144px
- If Scanned at 75dpi, and then run through gimp and DivideScannedImages, the output size is smaller than 252x144. And that includes a minor background border that is attached to each separated image.
- If Scanned at 100dpi, and then run through gimp and DivideScannedImages, the output size is larger than 252x144. And that includes a minor background border that is attached to each separated image.
- It may be my scanner or the driver. not sure. But unfortunately for business card scanning I will not be able to use this. I have not tried photos yet. But that should be less of an issue than the cards as the cards need to be exact for the application I want to apply it to.

Again, Love the program and the concept. I will be testing with photos over the next week or two. Right now I need to focus on the business cards.

Thanks again,
Ted (madthad)


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Apr 20, 2009 5:04 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
madthad wrote:
Rob, thanks a bunch. I downloaded the new version and it is exactly what I was looking for. But... The issue with the business cards scanning comes down to this:
- Cards are 3.5" x 2" or 252px x 144px
- If Scanned at 75dpi, and then run through gimp and DivideScannedImages, the output size is smaller than 252x144. And that includes a minor background border that is attached to each separated image.
- If Scanned at 100dpi, and then run through gimp and DivideScannedImages, the output size is larger than 252x144. And that includes a minor background border that is attached to each separated image.
- It may be my scanner or the driver. not sure. But unfortunately for business card scanning I will not be able to use this. I have not tried photos yet. But that should be less of an issue than the cards as the cards need to be exact for the application I want to apply it to.

Again, Love the program and the concept. I will be testing with photos over the next week or two. Right now I need to focus on the business cards.

Thanks again,
Ted (madthad)


Ted - Something doesn't make sense there...the numbers you provide indicate 72 DPI (252/3.5 or 144/2).

Scanning at 75 DPI should give you 262 or 263 x 150 px and at 100 DPI should give you 350 x 200 px.

Do you have the deskew plugin installed? That could be changing the scale when it rotates...

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Mon Apr 20, 2009 5:41 pm 

Joined:
Sun Apr 05, 2009 6:29 pm

Topics:
Posts: 4

Find User's Topics
Rob, you're right! Oops!

Early on I was using a program that does 72dpi by default (forgot which program). I must have jotted those numberz down somewhere and ran with it. I have been testing a bunch of other programs recently including gimp. I guess I did some assuming, not paying attention along the way, etc. Lukily I have not gone that far with my application, and it would not have mattered a few pixels off anyway.

Thanks for bringing that to my attention.

- OK, so assume 75dpi with 263/150.
- I place either 8 or 10 biz cards (testing purposes) on the scanner with about 3/8"-1/2" space around all edges.
- When I run DivideScannedImages, most will separate. I need to play with the brightness and other color options which may help in the separation.
- Take the dpi issue away, the main thing now is there is an 1/8" or so border around the images in the color of the underneath of the lid which is an grayish/white color. I could put a sheet of off-color paper over the cards and I will still get a 1/8" border after dividing but with the color of that paper. I presume the border is normal? Or is the issue with the border my scanner or the driver?

Please, don't take a lot of time with this. I have an alternate method. I have a Neat Receipts biz card scanner but it is a royal pain in the arse. By the time I scan 10 cards with it, I could have scanned 10 on the flatbad and edit it manually. So either way it takes a bunch of time.


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Tue Apr 21, 2009 2:07 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
madthad wrote:
Take the dpi issue away, the main thing now is there is an 1/8" or so border around the images in the color of the underneath of the lid which is an grayish/white color. I could put a sheet of off-color paper over the cards and I will still get a 1/8" border after dividing but with the color of that paper. I presume the border is normal? Or is the issue with the border my scanner or the driver?


The border is because of a shadow around the card edge(s) caused by the scanner itself. Playing with the background threshold should be able to eliminate most of it.

If it is always consistent, (and I assume it would be for most scanners, from scan to scan of the same things, but thicker stock will change it...) I could add top, bottom, left & right cropping parameters to the script, or allow specifying a width and height, and cropping to that centered in the isolated image. The second option might be best but would only work if the border is consistent all the way around....

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Fri May 01, 2009 9:24 pm 

Joined:
Fri May 01, 2009 9:08 pm

Topics:
Posts: 1

Find User's Topics
Brilliant stuff!

Just a quick thought - when running on linux the section that saves the split images crashes because it is looking for /my/path\filename.jpg

Basically, the double backslash (\\) in the script needs to be replaced by a forward slash / - then it works a treat.

Cheers

Ian


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Sat May 30, 2009 2:39 am 

Joined:
Tue May 26, 2009 2:56 am

Topics:
Posts: 7

Find User's Topics
Just in case anyone is watching this thread, I've just downloaded ver 1.8 of DivideSannedImages and you won't believe it, but it's even better now. The "\\" or "/" issue is now being auto detected and there is a batch processing part that will do a dir of images with one click.

I got it here: http://ffaat.pointclark.net/incoming/sc ... Images.scm

I'm running Debian Lenny and it works perfectly.

Gary


Top
 Profile E-mail  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Wed Oct 07, 2009 8:15 pm 
User avatar

Joined:
Mon Nov 05, 2007 3:16 pm

Topics:
Posts: 597

Find User's Topics
Just an update -

Version 1.9 is now available at the same place: http://ffaat.pointclark.net/incoming/sc ... Images.scm

Gary D. Huffman, II pointed out that the images weren't being processed in alphabetical order in batch mode under Ubuntu. This just adds a sort algorithm that is applied first.

-Rob A>


Top
 Profile  
 
Offline
 Post subject: Re: Divide OR Crop Multiple Images from Single Scan
PostPosted: Sun Nov 22, 2009 6:56 am 

Joined:
Tue May 26, 2009 2:56 am

Topics:
Posts: 7

Find User's Topics
Just in case someone is wanting to do what I wanted to do and needs a little
assistance in getting it all working ...

I recently used the Gimp and BatchDivideScannedImages to process 68 directories containing
310 scans into 872 photos.

I did this via the command line running Debian GNU/Linux 5.0 (it should
work the same on any system that is capable of running the Gimp). The final result after
more than 2 days of processing time (on an apple G4) gave me 868 photos. I got the
missed 4 photos by hand clipping three images that had not been completely divided.

I used a python script to 'walk' the directory structure that contained the scanned
images, creating a duplicate structure to store the photos in. For each directory of
scans I executed the following command:

gimp -ibdf '(script_fu_BatchDivideScannedImagesCL "/scanned-images-dir" 0 20 1500 5 3 100 100 "/directory-for-photos" 0 "photo-prefix_" 1)' -b '(gimp-quit 0)'

*** explanation of parameters
image- name of the dir where scanned images are located
inLayer- don't know why, just left this at zero
inThreshold- tried lots of values here (from 10-80), 20 gave me the best results
inSize- I scanned at 600px/in so I set this to 1500 to filter out unwanted selections
inLimit- don't know why, just left this at five
inCorner- the least used corner of the scanner bed (lower right for me).
inX- I used 100 to make sure I was away from the scanner edge effects
inY- I used 100 to make sure I was away from the scanner edge effects
inSaveFiles- not used for batch mode
inDir- name of the dir where the photos should be saved
inSaveType- type of image file, zero is for jpg
inFileName- add this text to the front of the filename
inFileNumber- the filename is indexed by a number (i.e. "00001"), this is the start number to use



*** other considerations and changes I made to DivideScannedImages.scm

I made some changes to the script and saved my own version as DivideScannedImagesCL.scm:

1) I commented out all references to 'display' in the script so that it wouldn't try to open
the gimp ui when processing the images. It was going to run on a headless server anyway
and it won't run at all if you use the "-i" gimp parameter with the gui enabled.

2) I added a 20 pixel radius to the background color selection code. As written the script
picks the background color from a single pixel located at X,Y. I found, that with my
scanner, picking out one pixel for the background color never gave me an accurate color.
A 20 pixel radius may be more than necessary, I had lots of room so it worked good for me.

3) I added a few lines near the start of the script that put a background border (50 pixels) around
the scanned image (using a 20 pixel radius for color selection). My scanner produces a brownish
border around the scan which will interfere with selecting any photos that are near to or pushed
up against the edge of the glass (the easiest way to align them). This border is an 'inside' border
and as such will mask the brown edge, creating a uniform background from edge to edge. It will
also clip a small edge off the photo (most photos are going to be 2500+ pixels wide anyway).
Here's the code, note the last line gives you the location where I inserted this into the script
(very near the top):
Code:
          ; start add inside border
          (gimp-selection-all img)
          (gimp-selection-shrink img 50)
          (gimp-selection-invert img)
          (set! drawable (car (gimp-image-get-active-drawable img)))
          (gimp-context-set-background (car (gimp-image-pick-color img inLayer (- width inX) (- height inY) FALSE TRUE 20)))
          (gimp-edit-bucket-fill-full drawable BG-BUCKET-FILL NORMAL-MODE 100 5 TRUE TRUE SELECT-CRITERION-COMPOSITE 100 100)
          (gimp-selection-none img)
          ; end add inside  border
         
          ;set up saving


4) This represents near flawless accuracy in dividing scanned photos. It saved me many hours of time
I would have had to spend individually processing the scans (using the very awkward gui software that
comes with most scanners). Spend some time testing the threshold and size filters on your most
difficult scans to make sure they are effective. Really look at your scanned image background and
border before you commit to scanning large numbers of photos. You want a uniform background
color - in my opinion as white as you can get it - from edge to edge. You can adjust the scanning
software to produce the best possible background color.

5) Thank you Rob Antonishen for a wonderfully effective Gimp script.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  

Post new topic Reply to topic
 [ 33 posts ]  Go to page 1, 2  Next



Who is online

Users browsing this forum: SAbboushi and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Related Website
Gimp tutorials database
All rights reserved © GimpTalk 2008
forum software by
phpBB