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
Posts: 1
Joined: 2017-11-04T04:08:16+00:00
Authentication code: 1152

cropping inner rectangle

Post by Mets »


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 ... eight:160) ... -doors.jpg ... 50x250.jpg ... _(PSF).png ... window.jpg

Thank you for any suggestions.
Best regards
User avatar
Posts: 25562
Joined: 2007-07-03T00:14:51+00:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cropping inner rectangle

Post by fmw42 »

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:


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
Post Reply