With ImageAlign result is another image, that is composition of another two. But I'm looking for function that will find position, x-y coordinates of smaller image inside bigger one. Is there such function? I'm not looking for position of some feature, that is on smaller and bigger image, but for exact coordinate of upper left corner of smaller image inside bigger.

  • $\begingroup$ I have marked this question as a duplicate. A link is inserted above your post. Please review the question and its answers. If you feel that your question is different please edit it, making reference to older question and clarifying how your needs differ. $\endgroup$ – Mr.Wizard Jun 7 '16 at 4:23

The most straightforward approach is ImageCorrelate. I'll show you an example. nikie wrote an excellent answer explaining this method here.

large = ExampleData[{"TestImage", "Boat"}]

Mathematica graphics

smaller = ColorConvert[Import["http://i.stack.imgur.com/NAHqc.png"], "Grayscale"]

Mathematica graphics

corr = ImageCorrelate[large, smaller, EuclideanDistance];

Mathematica graphics

The minimum – the blackest area – is the best match between the smaller image and the larger image.

min = PixelValuePositions[corr, "Min"] // First;
 large, Rectangle[
  min - ImageDimensions[smaller]/2,
  min + ImageDimensions[smaller]/2

Mathematica graphics

| improve this answer | |
  • $\begingroup$ may I ask what version Mma you are using. The documentation states an image can be used as a kernel (as you have done). I run your code and get "is not a valid kernel specification" for smaller. $\endgroup$ – ubpdqn Jun 6 '16 at 23:29
  • $\begingroup$ @ubpdqn I can replicate your problems, thank you for pointing it out. It appears something happens when I upload the image and then download it again, so everyone will have to crop their own subimage for demonstration. $\endgroup$ – C. E. Jun 7 '16 at 2:21
  • 1
    $\begingroup$ thank you for clarifiying. The image information of uploaded (the context sensitive menu Mma provides) is different for the the two images, so I think the conversion process renders the smaller an unsuitable kernel. This is a minor point and I had already +1 your answer. I like that what almost seems to be a black dot served as the anchor for the highlight in the highlighted image. :) $\endgroup$ – ubpdqn Jun 7 '16 at 2:25
  • $\begingroup$ @ubpdqn Now figured out why, had to convert it to grayscale. Thanks again for pointing out that there was a problem. $\endgroup$ – C. E. Jun 7 '16 at 2:46
  • $\begingroup$ The PixelValuePositions call can be simplified to PixelValuePositions[corr, "Min"]. $\endgroup$ – Alexey Popkov Jun 7 '16 at 4:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.