cropping inner rectangle

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
Mets
Posts: 1
Joined: 2017-11-03T21:08:16-07:00
Authentication code: 1152

cropping inner rectangle

Post by Mets » 2017-11-04T19:30:59-07:00

Hi,

In the example images below, I am looking to crop to the inner rectangular-like shape.
This target shape does not have to have 90 degree angles for example the old fashioned TV set screen does qualify.
Most of the examples are of doors and I would like to crop out the window or rectangular-like shape within a door.
If there are more than one outer rectangular shapes, then all of their "children" or inner rectangular-shapes are indeed targets.
If there is no outer and inner rectangle and the image contains just one or more rectangles, then I would like to target these rectangles and to crop them out as well.
Is this achievable? I have Version: ImageMagick 7.0.7-9 Q16 x86_64 2017-10-31 on Mac

https://nofile.io/f/zc25H3s5bTb/sw.jpg
https://nofile.io/f/VQWjykSFY7Z/IMG_4588.JPG
https://nofile.io/f/pYFKg6bWnDW/10.jpg? ... eight:160)
https://nofile.io/f/temtn5Bpvta/IMG_1937-1.jpg
https://nofile.io/f/JWPVpNEfRdC/eddce97 ... -doors.jpg
https://nofile.io/f/M9Z64MmyyAm/single- ... 50x250.jpg
https://nofile.io/f/cbYjYMxom2D/10.jpg
https://nofile.io/f/zWaPN0mV6eS/1200px- ... _(PSF).png
https://nofile.io/f/KXNpT9eTJme/PrimeDoorSmall1.jpg
https://nofile.io/f/3GEw2qVP5RE/cottage ... window.jpg

Thank you for any suggestions.
Best regards
Mets

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: cropping inner rectangle

Post by fmw42 » 2017-11-04T19:50:19-07:00

If you want some inner shape, then I know of no automatic way. You can however, pick outlining points and then draw a polygon on the image, fill the interior with white and the exterior with black to make a mask. Then use the mask to make the outside transparent and the inside the image, then crop to the bounding box of that area.

For example:

Input:
Image

Code: Select all

convert p.jpeg \( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon 255,72 350,64 345,310, 252,289" \) \
-alpha off -compose copy_opacity -composite -trim +repage p_crop.png
Image

Post Reply