Hello,
I'm quite new to ImageMagick. I have scanned thousands of old slides. On some of them, I have rounded corners I'd like to automatically remove.
The position of the corners is not always the same so applying exactly the same inner cropping would not work.
I would like to detect automatically and crop only the red area, while respecting the ratio of the picture.
https://cl.ly/222C1b3w042R
Here are some original pictures if needed for testing:
https://cl.ly/2u2F2Q3L3P2l
https://cl.ly/3b3Z3s3w3442
https://cl.ly/3C3R0n1s0D0O
https://cl.ly/0p1B401l112k
Do you know how to do this?
Many thanks for your help,
Michel
Remove irregular rounded corners from scanned images
-
- Posts: 1
- Joined: 2017-10-05T02:58:17-07:00
- Authentication code: 1151
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Remove irregular rounded corners from scanned images
Please say what version of IM you use, on what platform (eg Windows, Unix, etc) and your preferred script language (Windows BAT, bash, etc) if any.
The first image has a "CloudApp" logo bottom-left, obscuring that corner. Has that been added by your hoster? If so, I suggest you upload them to somewhere that doesn't alter your images. For example, put them in zips that you upload to dropbox.com or somewhere.
Doing the crop is easy, with "-crop" or "-shave". Detecting whether it is needed, and how much, is more difficult. The photographed subject may be very dark in the corners, leading to false readings.
A possible approach: from each corner, examine the line at 45 degrees, towards the centre of the image. As we examine pixels from the corner inwards, if there is a jump from almost-black to something lighter, that marks a point for a crop. If all four corners have a jump at a similar distance, use the inner-most as a crop for all four.
(This could be done by rotating the image by 45 degrees, and taking horizontal or vertical crops.)
If two adjacent corners have a jump but the other two don't, do you care what happens? We could assume the other two have a jump in the same places.
The first image has a "CloudApp" logo bottom-left, obscuring that corner. Has that been added by your hoster? If so, I suggest you upload them to somewhere that doesn't alter your images. For example, put them in zips that you upload to dropbox.com or somewhere.
Doing the crop is easy, with "-crop" or "-shave". Detecting whether it is needed, and how much, is more difficult. The photographed subject may be very dark in the corners, leading to false readings.
A possible approach: from each corner, examine the line at 45 degrees, towards the centre of the image. As we examine pixels from the corner inwards, if there is a jump from almost-black to something lighter, that marks a point for a crop. If all four corners have a jump at a similar distance, use the inner-most as a crop for all four.
(This could be done by rotating the image by 45 degrees, and taking horizontal or vertical crops.)
If two adjacent corners have a jump but the other two don't, do you care what happens? We could assume the other two have a jump in the same places.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove irregular rounded corners from scanned images
I have just add a new unix bash shell script, trim corners, to my collection that should do what you want above.
It uses a similar approach as suggested by snibgo to search along the diagonals of the image.
It uses a similar approach as suggested by snibgo to search along the diagonals of the image.