I want to rotate an object in a image about its centroid. here is my code but the result is not as expected. Normally the centroid of the object does not change, except the case when the object is very close to the edge of the image.
edge = MorphologicalPerimeter[img] // DeleteSmallComponents; center = Round[ComponentMeasurements[edge, "Centroid"][[1, 2]]] (*we can use directly the image instead of the edge.*) im2 = ImageForwardTransformation[img,N[RotationMatrix[90 Degree].(# - center)] &, DataRange -> Full]