Jump to content
You must now use your email address to sign in [click for more info] ×

Crop White Space From Around Multiple Images


Recommended Posts

I have a large number of images which were scanned from photo prints. Many of them have a pure white border around them.
I want to crop the images so that there is no white border at all.

It's easy enough to do this manually, but it's very time consuming (I have a thousand or more to crop).

Is there any way I can Automate the process within Affinity? I have V1 and am perfectly happy with it, but I'm also happy to upgrade to the V2 Suite if that's what's required.
Thanks in advance for any advice.

Edited by Andy Nickless
Correct spelling
Link to comment
Share on other sites

Hi @Andy Nickless and welcome to the forums,

Do all the scanned images have the same pixel dimensions or do they vary and are they a mix of landscape and portrait?

You may be able to process these in a batch using a simple macro to crop and then resave them which would massively speed up the process...

Affinity Designer 2.5.5 | Affinity Photo 2.5.5 | Affinity Publisher 2.5.5
MacBook Pro M3 Max, 36 GB Unified Memory, macOS Sonoma 14.6.1, Magic Mouse
HP ENVY x360, 8 GB RAM, AMD Ryzen 5 2500U, Windows 10 Home, Logitech Mouse

Link to comment
Share on other sites

7 minutes ago, Hangman said:

Hi @Andy Nickless and welcome to the forums,

Do all the scanned images have the same pixel dimensions or do they vary and are they a mix of landscape and portrait?

No, sadly, there are very few which have the same dimensions.
I was rather hoping there might be a way to delete the white part, and then crop it out.

(Quite surreal to be welcomed by someone who calls themselves '@Hangman' - but thanks for the welcome all the same)!

Link to comment
Share on other sites

can you upload a few (3-5) sample images?

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

Thanks

It looks doable

Have to go out for about an hour but will take a look when I get back, if no one else has

 

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

1 minute ago, carl123 said:

Thanks

It looks doable

Have to go out for about an hour but will take a look when I get back, if no one else has

 

No problem - thanks for your interest.
I have to go out for an hour or so now, too.

You'll see the images have rounded corners. I'm not worried about that, I just want to reduce the space around them.
The old photos weren't cropped very squarely either, so there will be some difficulty there. I would prefer not to crop any of the actual image if that's possible.

Link to comment
Share on other sites

I have attached a macro that works on the 5 samples you sent me

I have been overly cautious to not cut out any of the image, so the border may appear a bit ruff in places

Each photo required something different/extra each time to compile a macro that worked on all of them. Therefore, you may find other images it does not work properly on but hopefully a lot of them will be OK

The file attached is imported into the Library panel. The category name is "scan crop" the macro name is "scan4"

You can attach and run the macro in the File > New Batch Job window.

Always save to a new folder so as not to overwrite the originals

I would batch test a few dozen at a time

scan crop.afmacros

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

44 minutes ago, carl123 said:

I have attached a macro that works on the 5 samples you sent me

 

Thank you so much - but unfortunately I got this error message:
"Unexpected Macros Format.........  Downloads/scan crop.afmacros"
I was trying to import it into Affinity Photo (V1) on an M2 (Silicon) Mac running Sonoma 14.5
....

Link to comment
Share on other sites

I wrote it on a V2 version

I'll redo it on V1

That's probably the reason

Standby...

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

Here's a version that runs in V1

 

Scan Crop V1.afmacros

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

Yes, I was worried about those dark images being produced

The V2 flood select tool is more configurable than the V1 version

Can you upload the ones that failed in your screenshot (the originals) and I might get to relook at it again over the weekend

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

6 minutes ago, carl123 said:

The V2 flood select tool is more configurable than the V1 version

That's very kind of you Carl.
I'll upgrade to V2 now - and try the Macro again (just in case it's any better).
Attached are the originals of the failed ones.

Your help is very much appreciated!

160924 011.jpeg

160924 012.jpeg

170919 005.jpg

170919 006.jpg

170919 007.jpg

170919 008.jpg

Silk Cards - WW1 0100a.jpg

Link to comment
Share on other sites

5 minutes ago, Andy Nickless said:

I'll upgrade to V2 now

I'd wait until I can retest this

or just download the trial version

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

carl123's macro is undoubtedly ingenious but I would use imagemagick for a job like this involving a thousand or so images

If you have all of the images in a folder, make a sub-folder called out and run
magick mogrify -path .\out -fuzz 50% -trim -quality 85 *.jpg
I think you'll be impressed with the results, the five you posted took 230 ms to process

Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe
Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10

Link to comment
Share on other sites

Posted (edited)
17 hours ago, carl123 said:

I'd wait until I can retest this

I ran the Macro in V2 and the result was much better. Only two of the 12 images were spoiled.
I've attached the originals of the two which didn't work so well below.

Otherwise, the results were excellent!

160924 012.jpeg

170919 006.jpg

Edited by Andy Nickless
Clarification
Link to comment
Share on other sites

17 hours ago, David in Яuislip said:

carl123's macro is undoubtedly ingenious but I would use imagemagick for a job like this involving a thousand or so images

Thanks for your helpful suggestion.
I didn't reply immediately because I wanted to try carl123's macro on V2. I would prefer to use Affinity if I can, because I don't really want to learn yet another application.
I'll certainly keep imagemagick in mind though. Thanks again!

Link to comment
Share on other sites

4 hours ago, Andy Nickless said:

I ran the Macro in V2 and the result was much better. Only two of the 12 images were spoiled.
I've attached the originals of the two which didn't work so well below.

Otherwise, the results were excellent!

OK, I'm attaching a totally new reworked macro from the start. Using a different technique to the previous one and which, hopefully, will work on more images but impossible to say it will work on every one you have.

I have tested it on the 12 images you uploaded to the forum and it works for all of them

The main benefits of this one are...
 

  • Where possible it will produce a super straight tight crop
  • Should work for more images than previous version
  • Much faster processing

 

Let me know how it performs

 

Scan Crop V2.afmacros

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

2 hours ago, carl123 said:

OK, I'm attaching a totally new reworked macro from the start. Using a different technique to the previous one and which, hopefully, will work on more images but impossible to say it will work on every one you have.

That was VERY fast, and did a great job generally, but there were a few exceptions.
As in the (before and after) example below, you'll see that for some reason, a white margin remains on the left edge of the 'landscape' photos - and (usually) the top edge of the portrait photos. This happened in 50 of the 273 scans which I processed.
On the remainder, the result is perfect!
You have spent a lot of time on this, and I'm really grateful. Please don't do any more on it if you don't feel like it.
I would be more than happy with the job this last macro is doing, as it reduces my work by about 80%!

Harvest-Hops150617041.thumb.jpg.d801053342461b27094b86bb2face5de.jpgHarvest-Hops150617041.thumb.jpg.3fadfb26936a237fc3719eef8cb3c30d.jpg

Link to comment
Share on other sites

15 hours ago, Andy Nickless said:

That was VERY fast, and did a great job generally, but there were a few exceptions.

 

Unfortunately, I expected that.

If we were only dealing with images, we could have more aggressively trimmed on all 4 sides to achieve a perfect crop. Doing so would have resulted in losing some of the image pixels on the sides but it would not have changed the message the image was portraying in any way, since the focal point of those images was the centre.

But some of those postcard images have hand-written text that went all the way to the edge of the image. An aggressive crop would have cropped some of that text and since the text is paramount in portraying what was being written on those postcards I had to compromise so that the text was preserved at the expense of a more aggressive crop on the images. Since these postcards appear to be from around the 1910/1920 period in time, their historical value could be important so I did not want to crop the text in any way.

Changing the previously upload macro to an aggressive crop one required only one change. So, I have made that change and attached an aggressive-crop macro to this post. If you create a folder with just your images in it you may want to test this macro to see if you are happy with the results. 

15 hours ago, Andy Nickless said:

You have spent a lot of time on this, and I'm really grateful. Please don't do any more on it if you don't feel like it.

That's OK, I enjoy a challenge and seeing what Affinity macros can do especially in cases like this where someone has 1000+ images to process.

Unfortunately, Affinity have not improved the macro system much since it was first introduced and it is lacking in a lot of places but hopefully, they are working on scripting which should bridge that gap

Scan Crop V3 Aggressive.afmacros

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

@carl123 nice job!

could you give a brief description how the macro works?
from the forum post i assume it use flood selection ad the crop,(to selection), but how do you determine the position where you sample the color?

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

I get very good and fast results with few steps:

  • flood select the white background color (with continuous active)
  • add a levels adjustment on alpha channel, white level and black level set to 50%
  • add mask
  • merge visible
  • deactivate all layers below
  • selection from merged image
  • crop tool (uses selection) and apply
  • the 2 problematic images are slightly tilted. I cannot imagine a simple way to streighten images automatically, but it takes 1 minute manually.

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.