given an image composed of a plain black field with a single white rectangle inside it somewhere, how can i extract the coordinates of the rectangle ? i've googled and googled and found numerous articles on edge detection using hough lines, convolution, morphology, etc., but all of these actually edge the image or convert it in some way. i don't want to change the image, all i want to do is find where the edges are.
obviously, i could simply iterate over the entire width+height of the image and look at the pixel colours (as some posts suggest), but that seems horribly inefficient. is there no built-in algorithm ? it seems like this must be part of imagick somewhere, otherwise how could it actually find and draw the edges of internal images ? but i'm having trouble finding out how to get at it.
A similar example is on the manual page: http://php.net/manual/en/imagick.trimimage.php#111332
it appears the complete solution to the problem as posted is as follows :
not setting the image page before getting the height and width return the height and width of the entire original image, as the note on your referenced page suggests.
it turns out the solution is even easier if you're working with an image that uses transparency ; it's just the
getImagePage()
function alone :for some reason, if
trimImage(0)
is used with this transparent image, the (x,y) coordinates are set to (-1,-1). unfortunately i don't know enough about imagick to say why this happens. maybe you could answer this, @danack ?