Imagemagick position and size of a sub-image <h3>Problem description:</h3> <p>In imagemagick, it is very easy to diff two images using compare, which produces an image with the same size as the two images being diff'd, with the diff data. <strong>I would like to use the diff data and crop that part from the original image, while maintaining the image size by filling the rest of the space with alpha</strong>.</p> <h3>The approach I am taking:</h3> <p>I am now trying to figure the bounding box of the diff, without luck. For example, below is the script I am using to produce the diff image, see below. Now, I need to find the bounding box of the red color part of the image. The bounding box is demonstrated below, too. Note that the numbers in the image are arbitrary and not the actual values I am seeking.</p> <pre><code>compare -density 300 -metric AE -fuzz 10% ${image} ${otherImage} -compose src ${OUTPUT_DIR}/diff${i}-${j}.png </code></pre> <p><img src="https://i.stack.imgur.com/edPdf.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/AZkdz.png" alt="enter image description here"></p>