Page 1 of 1

Remove irregular rounded corners from scanned images

Posted: 2017-10-05T03:05:13-07:00
by michelgalibert
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
Image

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

Re: Remove irregular rounded corners from scanned images

Posted: 2017-10-05T03:57:20-07:00
by snibgo
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.

Re: Remove irregular rounded corners from scanned images

Posted: 2017-10-13T11:45:53-07:00
by fmw42
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.