5
$\begingroup$

To apply DistanceTransform for shape recognition, I want to center all images in a fixed point {cx,cy}. I mean each image's centroid should be {cx,cy}. I am using this code but It does not wrok.

{cx,cy}={50,50}.
cen=ComponentMeasurements[im1, "Centroid"][[All, 2]]
ImageTransformation[im1, (# + {cx, cy} - cen) &]

What is wrong?

im1

$\endgroup$

1 Answer 1

8
$\begingroup$
im1 = Import["https://i.stack.imgur.com/78jWB.png"];
{cx, cy} = {50, 50};
cen = ComponentMeasurements[im1, "Centroid"][[All, 2]][[1]];

im2 = ImageForwardTransformation[im1, (# + {cx, cy} - cen) &, DataRange -> Full];
(* or ImageForwardTransformation[im1, TranslationTransform[{cx, cy}-cen], DataRange -> Full] *)

im3 = ImageTransformation[im1, (# - {cx, cy} + cen) &, DataRange -> Full];
(* or ImageTransformation[im1, TranslationTransform[cen - {cx, cy}],  DataRange -> Full]*)

Row[{im1, im2, im3 }, Spacer[3]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks. I understand inversely the function!!! $\endgroup$ Nov 2, 2014 at 15:45
  • $\begingroup$ @Developer2000, my pleasure. Thank you for the Accept. $\endgroup$
    – kglr
    Nov 2, 2014 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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