Batch processing - detecting various colours to crop to edge of scanned document JPG? - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: Batch processing - detecting various colours to crop to edge of scanned document JPG? (/Thread-Batch-processing-detecting-various-colours-to-crop-to-edge-of-scanned-document-JPG) Pages:
1
2
|
Batch processing - detecting various colours to crop to edge of scanned document JPG? - mkilpatr - 06-29-2022 Hello all, I have just learnt to use gimp in batch processing mode to autocrop a directory of JPG images which are scans of documents (music manuscript paper). I've used this in a Windows cmd shell. I have A LOT of these directories of scans. A lot of them will crop nicely with "plug-in-autocrop" if the background from the scanner is white: the result is usually a remnant border of about 15 pixes of white around each edge of the image. That's fine. However, when some of the smaller documents are scanned, within the thin white border around the JPG image there are also areas of black, grey-blue or off-white, presumably depending on how the scanner was setup and what was behind the document. Sadly, the scans do not conveniently provide a clean, autocropable background. The manuscript papers are all a typical beige hue or off-white, and some (we're talking 1930s) are a richer, more orangy-beige than others. Is there a relatively manageable way of detecting where the off-colour border ends and where the beige/orange/off-white paper begins so that I can automate this cropping using gimp-crop-image? Perhaps sampling for a range of beige colours expected for the paper and thus intelligently detect the edge of the paper? Or would that be a total nightmare? I am attaching an example JPG (one that doesn't have any music written on the manuscript paper). Working this out from scratch, if it's even doable, would probably take me weeks of learning. Maybe someone has some similar scripts which could be adapted? Michael By the way, there is an alternatve. As all the scans are in the same orientation - any excess border is always to the right and to the bottom of the manuscript paper, is it possible to have a script that runs in the graphical user interface such that GIMP can bring up each image in turn from the folder, allow me to click on the bottom right corner of the paper and for GIMP then to crop and save to that corner, save the result, close it and and bring up the next image without lots of mouse clicks? That would be perfectly acceptable. RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - PixLab - 06-29-2022 (06-29-2022, 11:43 AM)mkilpatr Wrote: By the way, there is an alternatve. As all the scans are in the same orientation - any excess border is always to the right and to the bottom of the manuscript paper, is it possible to have a script that runs in the graphical user interface such that GIMP can bring up each image in turn from the folder, allow me to click on the bottom right corner of the paper and for GIMP then to crop and save to that corner, save the result, close it and and bring up the next image without lots of mouse clicks?Just a thought... First install the Ofnuts script ofn-export-layers.zip ➤ https://sourceforge.net/projects/gimp-tools/files/scripts/ofn-export-layers.zip/ Once it's done... Open one of your directory as layers Filters ➤ Open as Layers a window opens click on the top of the image's list to select it, then hit the Shift key and click on the bottom image while the Shift key is down to select all the image in between as well, then click the button open, all your images in the folder will be opened stacked as layer but only 1 image, all stacked above each other as layer, use the Crop tool for the whole image (so you just cut once with the mouse), then use the Ofnuts' script to export each layer as an image [attachment=8221] RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - mkilpatr - 06-29-2022 Thanks, but there will likely be several different sizes of manuscript paper so sadly this wouldn't work as some of them could be overcropped incorrectly. I can see that would certainly work for a uniform paper size on the scanner bed, however. RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - PixLab - 06-29-2022 (06-29-2022, 12:37 PM)mkilpatr Wrote: I can see that would certainly work for a uniform paper size on the scanner bed, however. Indeed I was thinking more or less than your scans might have a relative similar size (thus, the "just a thought" ). RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - Ofnuts - 06-30-2022 (06-29-2022, 12:37 PM)mkilpatr Wrote: Thanks, but there will likely be several different sizes of manuscript paper so sadly this wouldn't work as some of them could be overcropped incorrectly. I can see that would certainly work for a uniform paper size on the scanner bed, however. No automated way, but you can make things a lot faster with a script of mine. The most time-consuming part of the process isn't the crop, but saving the file and opening the next... Which is what my ofn-file-next script does. You can assign it to a key, then:
RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - mkilpatr - 06-30-2022 Thank you for that. I will have a look later - this morning is hedge-trimming time, though! Another question: is it possible to make GIMP do a rectangular crop from the top-left corner to a selected point as the bottom-right corner without having to go through the hassle of making a rectangular selection? Can I click the mouse on a point and then press a key to run a script that crops from the top-left to that point? All my images are nicely aligned to the top-left like the sample above, so I only ever need to define one corner f the crop area. if that's possible, would it also be possible to merge it with the ofn-file-next script into a single script so that each image crop operation would be one mouse point-and-click followed by a single key stroke? Michael RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - rich2005 - 06-30-2022 Gimp batch processing using the BIMP plugin https://alessandrofrancesconi.it/projects/bimp/ Quote:All my images are nicely aligned to the top-left like the sample above, so I only ever need to define one corner f the crop area. Using BIMP add your folder of scans and: [attachment=8226] RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - Ofnuts - 06-30-2022 (06-30-2022, 10:24 AM)mkilpatr Wrote: Thank you for that. I will have a look later - this morning is hedge-trimming time, though! There is no way in a script to see where you clicked. What a script sees is the result of click (for instance a selection, a path, or a guide). If you always include the top left corner in the crop, click on the bottom right corner and drag beyond the top left one and Gimp will adjust that to the corner (make sure you have disabled "Allow growing" in the Crop tool options). RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - mkilpatr - 06-30-2022 (06-30-2022, 10:55 AM)rich2005 Wrote: Gimp batch processing using the BIMP plugin https://alessandrofrancesconi.it/projects/bimp/Rich, sorry, but surely that does an identical crop for all images? My images are all aligned to the top-left corner of the scan but they are varying in sizes. RE: Batch processing - detecting various colours to crop to edge of scanned document JPG? - rich2005 - 06-30-2022 (06-30-2022, 12:02 PM)mkilpatr Wrote: Rich, sorry, but surely that does an identical crop for all images? My images are all aligned to the top-left corner of the scan but they are varying in sizes. My misunderstanding. |