3
$\begingroup$

I import the test image eloquently named "Tank2":

img = ExampleData[{"TestImage", "Tank2"}]

And do an extremly poor corner detection:

GetCorners[img_] :=
  Module[{
    filtered = ImageConvolve[GaussianFilter[img, 1.1], ( {
        {0, -1, 0},
        {-1, 4, -1},
        {0, -1, 0}
       } )]
    },
   ImageValuePositions[filtered // ImageAdjust, White, 0.5]
   ];

Now I want to overlay the "corners" as small circles, and do this:

g = Graphics[{{Red, Circle[#1, 1]} & /@ GetCorners[img]}, 
  ImageSize -> ImageDimensions[img], PlotRangeClipping -> True, 
  AspectRatio -> ImageAspectRatio[img]]
ImageCompose[img, g]

Alas, the result is not aligned, as you can see below, what to do? Is there a better way to draw "on top" of an image? I guess the Graphics function pads the image in some way, then crops it with the wrong midpoint?

Poor image of a tank and a very bad corner detection

$\endgroup$
2
$\begingroup$
Show[img, Graphics@{Red, Point@GetCorners[img]}]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ Wow, that's much more terse than mine. Upvote for that. $\endgroup$ – Skurmedel Mar 11 '16 at 2:10
  • 1
    $\begingroup$ @Skurmedel Mixing images and graphics need some practice. Usually the most obvious thing works. But when it doesn't you're in a dangerous terrain. $\endgroup$ – Dr. belisarius Mar 11 '16 at 3:08
  • 1
    $\begingroup$ That terrain does look dangerous, with the tank and all :-p $\endgroup$ – LLlAMnYP Mar 11 '16 at 15:05
0
$\begingroup$

Well I solved my own problem :), I used Show[img, g], which did the business.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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