Gimptalk - Premier Gimp Community: Divide OR Crop Multiple Images from Single Scan - Gimptalk - Premier Gimp Community

Jump to content

  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Divide OR Crop Multiple Images from Single Scan

#21 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 21 April 2009 - 02:07 PM

madthad said:

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>
Posted Image
Fantasy Cartography and Mapping by RobA
0

#22 User is offline   ianmelb 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 01-May 09

Posted 01 May 2009 - 09:24 PM

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
0

#23 User is offline   garywitscher 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 26-May 09

Posted 30 May 2009 - 02:39 AM

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
0

#24 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 07 October 2009 - 08:15 PM

Just an update -

Version 1.9 is now available at the same place: http://www.silent9.com/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>

This post has been edited by RobA: 24 April 2013 - 01:57 AM

Posted Image
Fantasy Cartography and Mapping by RobA
0

#25 User is offline   garywitscher 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 26-May 09

Posted 22 November 2009 - 06:56 AM

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):
		    ; 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.
1

#26 User is offline   bscott 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 31-January 10

Posted 31 January 2010 - 05:49 AM

Thanks Rob A. This script will save me a ton of time.
0

#27 User is offline   lloydejordan 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 21-February 10

Posted 21 February 2010 - 06:12 PM

I'm pretty new at using gimp. I'm trying to separate pictures in a year book. Would also like to grab the text name with it. This script seems like it would do it or least give me a start.

Could someone give me an example on how to run it. I assume that it must be run in batch mode. An command example would greatly help.

Thanks
0

#28 User is offline   nathan.f77 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 29-April 10

Posted 29 April 2010 - 11:48 PM

Hi,

http://www.cubewano....-deskew-plugin/ is down.

I have emailed the person who created the plugin, but am not sure if I will have any luck with that.

This script is such awesome work, and would save me a LOT of time. (I was planning to write a script to do exactly the same thing)

Would anyone be able to forward me a copy of their 'gimp-deskew-plugin', I would REALLY appreciate it!

Thanks,
Nathan B
0

#29 User is offline   nathan.f77 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 29-April 10

Posted 03 May 2010 - 04:04 AM

Anybody?

It would be really disapointing if this awesome script became useless to others, just because http://www.cubewano....-deskew-plugin/ isn't available anymore.
0

#30 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 03 May 2010 - 08:20 AM

here
http://web.archive.org/web/200805120628 ... ew-plugin/
0

#31 User is offline   nathan.f77 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 29-April 10

Posted 13 May 2010 - 09:57 AM

Thanks for the link, but it didnt seem to work for me. I managed to find the plugin just today, as someone had posted the source rpm in a comment on here: http://registry.gimp.org/node/2958

For anyone else struggling with finding the deskew plugin, you can extract it from the source rpm here:
http://ccux-linux.de...hp?pdetail=6271

Or the easier way is to download the 'deskew' plugin file from here: https://docs.google....wMmRlZGI0&hl=en
.. and copy it to /usr/lib/gimp/2.0/plug-ins

Hope that helps someone out.
0

#32 User is offline   username132 

  • Member
  • PipPip
  • Group: Members
  • Posts: 51
  • Joined: 05-May 07

Posted 19 June 2010 - 09:37 PM

Thanks, Nathan - helped me out.

RobA, perhaps you could adjust the Deskew link given in the comments at the top of the script? Thanks :)

Edit: Does the plug-in need to be compiled into an .exe file? I'm using Windows 7. I could have sworn I'd installed GIMP plug-ins before, without having to compile anything... why can't the GIMP accept the instructions as they're written? I tried using .scm as the extension, since this is implied in the first line of the plug-in, but I can't find the plug-in in any of my menus.
System 6 (Codename: Seantron2000 - Commissioned: Feb 2010 - Status: Malfunction):
OS: Win 7 64-bit - Mainboard: Gigabyte GA 790FXTA-UD5 - CPU: AMD Phenom II 965 X4 - RAM: OCZ Black Ed Ready Dual Channel 2x2GB DDR3-1600 - Graphics: Sapphire HD 5770 1GB GDDR5 - PSU: Thermaltake 705w 700W - Case: Fractal Define R2
0

#33 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 21 June 2010 - 04:19 PM

username132 said:

Thanks, Nathan - helped me out.

RobA, perhaps you could adjust the Deskew link given in the comments at the top of the script? Thanks :)

Edit: Does the plug-in need to be compiled into an .exe file? I'm using Windows 7. I could have sworn I'd installed GIMP plug-ins before, without having to compile anything... why can't the GIMP accept the instructions as they're written? I tried using .scm as the extension, since this is implied in the first line of the plug-in, but I can't find the plug-in in any of my menus.



The script is scheme and goes in the script-fu folder.

The original websire had a precompiled binary for windows.

I attached a zip of the windows binary I had to the scrip location http://registry.gimp.org/node/22177

-Rob A>
Posted Image
Fantasy Cartography and Mapping by RobA
0

#34 User is offline   liderbug 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 23-September 10

Posted 24 September 2010 - 03:08 PM

OK, I got script_fu-DivideScannedImages installed and have it working only if I create a img where the images are spaced far apart. I need a man page on setting the vars. I've scanned in 31 paged of my HS annual with 22 thumbnails per page.
Posted Image The sample background is not #FFFFFF but 91 to ef. And I can't figure out how to tell the script that images is separated by ~5px. I'll keep trying but a push in the right direction would be .... And I will read the manual :roll: if someone can tell me where to find it.

Thanks.
0

#35 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 24 September 2010 - 04:37 PM

Not sure how much the BG color is relevant for the plugin to work

you may try to use select by color to select the bg, and then the bucket tool(check that the option fill the whole selection is checked) to fill with white

Anyway looking your sample image i think could be if you don't mind your extract thumb surrounded by a border or less then 3 pixel a better solution:

create a grid of guides (see http://docs.gimp.org...age-guides.html ) to separate the thumbs and then run the guillotine filters that is in the Image menu (in Image/Transform)

then open next thumbs page AS Layer, delete the previous layer and repeat (this should allow you to use the same grid of guides instead then have to create a new identical for each page )

0

#36 User is offline   liderbug 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 23-September 10

Posted 24 September 2010 - 06:55 PM

Show you how much of Gimp I've "never used - so I "guide"d the whole page, and dropped the blade and ended up with 63 heads in the basket - not the 22 I am after. :roll:

I have had some success by taking the orig and by using the RectSelTool and drawing 5px x 850px boxes between each column - vert & then horz. The first page I did it to worked great - then on the second it stared cutting people off at the nose, at the ears from both sides ^&$!#!.

Question: does it make any difference that I scanned 96dpi and grayscale?

Also trying to use the command line sample (way) above
gimp -ibdf '(script_fu_BatchDivideScannedImagesCL "/A6/chuck/div" 0 100 80 25 1 5 5 "/A6/chuck/divout/" 1 "44" 1)' -b '(gimp-quit 0)'
It says "batch command experienced an execution error" and quits. Woops, just notice "Batch" & "CL". I don't have that - so I changed it to script_fu_DivideScannedImages -> batch command experienced an execution error

I've gotten to the place where "I will make this work!!!" :x

--------- 10 min later got it to work - sort of ...
How does it scan looking for an image(s) I've got images
A B C D E
F G H I J etc 5 per row - the first row came out A B D C E

------ some time later - AhHa (i think) (note: HS annual, printed 1961 using half tone, now scanned. When I look at an image in the book with a magnifier dots - lots and lots of little tiny dots.)
I opened the file I'm trying to divide and zoomed way in and found the edges of the images were ... fuzzy. So I made sure that the edges where "clean" ------------------------------------------ not v^v^v^v^v^v^ and it scanned fine. I'll add to this later as I can.
----------------------
Suck-Sess -
In the script Version 1.9 (20101007)
line 197 "RGB* GRAY*"
line 289 "" I changed it to match 197 and things started working much better

I also have figured that the BG color has to be 1 color as in "Select - By color" on the menu bar - 1 freek'n number off and forget it. So what I do is bring in my scan of the annual page, RecSel across the top of the page to include the top 2 or 3 px of the top images and hit "Del" and I then do that all over the page - not dislike "Guides". Make sure RecBox "Feather edge" is off :oops:
----------------------
Several hours later - 678 thumbnails have been extracted and uploaded. I still can't get the command line to work.

Thanks for the pointers.
0

#37 User is offline   esac 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 25-October 10

Posted 25 October 2010 - 05:02 PM

I tried modifying the script, but my Scheme and gimp skills are poor. I want to take the background color from the bottom right of the first photo in batch mode, but then keep that same background color for the rest of the photos, as some of the scanned images are utilizing that corner (all 4 corners are used throughout the set of images, but they were all with the same scanner, so the background color should be the same).

Any ideas how to accomplish this?
0

#38 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 25 October 2010 - 07:17 PM

esac said:

I tried modifying the script, but my Scheme and gimp skills are poor. I want to take the background color from the bottom right of the first photo in batch mode, but then keep that same background color for the rest of the photos, as some of the scanned images are utilizing that corner (all 4 corners are used throughout the set of images, but they were all with the same scanner, so the background color should be the same).

Any ideas how to accomplish this?


It has been a while since I looked at the code. I thought it would be simple but it isn't quite. The script doesn't select by colour, it does a magic wand pick to get the BG. selecting a colour would also select any items in the images that matched the colour which didn't work well in my testing.

I've made a test version you might want to try that (if you select a new fifth option for the corner "Use BG Colour") it will enlarge the source image to create a frame using the BG colour then magic wand select in that colour. So Load up tyour first image and use the eye dropper tool to set the background colour to whatever you want as the "background" then run the script with that option.

Get it here: <!-- m -->http://www.silent9.com/incoming/sc ... Images.scm<!-- m --> and give it a test, OK?

-Rob A>

This post has been edited by RobA: 24 April 2013 - 01:49 AM

Posted Image
Fantasy Cartography and Mapping by RobA
0

#39 User is offline   liderbug 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 23-September 10

Posted 25 October 2010 - 07:42 PM

Rob, check my post of Fri Sep 24, 2010 11:55 am. In my experimenting I zoomed way in to where each pixel was about 1/2" square. I could tell that my scanner colored every background pixel differently IE: #FEFFFE and the next one was #FEFFFD. The only way I can think to get around that is if the code would build a range of colors +/- some number and search that way. The problem is guess what happens when the code runs into that range inside the image.

Now by using the Rect Sel Tool and hitting "Delete" ... think of using masking tape - taped of a border around each thumbnail so it looks like the "Font colour" chart to the right of this Post a reply box (you'll have to click on the Reply button). Then it worked like a charm. It saved me tons of work and time. :D

Hmmmm... just went through my mind - something akin to the Crop feature - but wouldn't stop at a gross border but would be .. a CropFill thing.

Chuck
0

#40 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 25 October 2010 - 07:48 PM

liderbug said:

The only way I can think to get around that is if the code would build a range of colors +/- some number and search that way.


That is exactly what the script does. The first option "Selection Threshold" adjusts the tolerance/deviation of the selected point.

-Rob A>
Posted Image
Fantasy Cartography and Mapping by RobA
0

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic