Page 1 of 1

cropping inner rectangle

Posted: 2017-11-05T02:30:59+00:00
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

Re: cropping inner rectangle

Posted: 2017-11-05T02:50:19+00:00
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