3
$\begingroup$

I have an binarized image

enter image description here

and a center

cvx = Import@"https://i.stack.imgur.com/1QoEo.png";
center = {258.19137417775005`, 150.8459811782782`};
HighlightImage[cvx, center]

gives

enter image description here

I want to rotate this white triangle by 180 degree around this center point and keep the original image dimension.

If I run

rotCvx = 
 ImageTransformation[cvx, RotationTransform[\[Pi], center], 
  PlotRange -> All, Background -> White]

which gives

enter image description here

But this is not the correct rotated one. You can see from

ImageAdd[cvx, rotCvx]

gives

enter image description here

The correct one should give

enter image description here

So how to rotate components on image around a fixed point?

$\endgroup$

1 Answer 1

4
$\begingroup$

Well, this may be easy to overlook, but it's actually mentioned in Details and Options section of document of ImageTransformation:

In 2D, the range of the coordinate system for the input image is assumed to be {{0,1},{0,a}}, where a is the aspect ratio. The bottom-left corner of the image corresponds to coordinates {0,0} by default.

Other coordinate systems can be specified by setting the DataRange option.

Typical settings for DataRange include: Full - same ranges as the input image

So, you just need DataRange -> Full:

rotCvx = ImageTransformation[cvx, RotationTransform[π, center], 
  Background -> White, DataRange -> Full]

enter image description here

$\endgroup$
1
  • $\begingroup$ I like it and accept it. Instantly solve the problem : ) $\endgroup$
    – matheorem
    Jul 16, 2023 at 10:34

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.