UIImage rotation axis - iphone

I want to rotate an image (UIImage) but can only do it from a default axis which is dead centre of the image ! as in Fig A. I want to move the axis to the centre of the x axis at the foot of the image as in Fig B. Can someone help me with this? I can only think of work arounds such as placing the image on an imaginary circle around the origin where the centre of the image would be where I position, then rotate the objects. This is too complicated and hopefully unneccessary. Imagine i want to place a number of images around a clock face with the origin in the centre where the clock hands originate, that's what I want to achieve. (The maths for doing this would also be appreciated).
(mid x axis and mid y axis).

Try using the view's underlying CALayer's anchorPoint property.
http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004500-CH1-SW36

I think you can do it by first rotating using CGContextRotateCTM and then shifting that center point to the point you want it to be by using CGContextTranslateCTM
Like rotate 90 degree first to right
then shift center(x,y) to newPoint((x- width/2), (y - height/2)) here width and height are of rotated image.
I hope this helps.

Related

Rotate an image around x or y axis in Matlab

If a camera is looking at say 6 evenly spaced dots in the real world it would look like the image below if the camera is looking at the image straight on with no rotation in the x, y or z axis
The z-axis is perpendicular to the image sensor so rotation around the z-axis is simple, it's just a tilt of the image. If I were to rotate the camera (or objects being looked at) around the x axis (if the x-axis is up down) the rows and columns will no longer be parallel and would project off to a vanishing point, like this.
What I would like to do is take a 2 dimensional image of say, dots, and be able to apply different rotations around the x,y and z axes independently. I've experimented with reading my image in Matlab and multiplying by a rotation matrix, or even a full camera matrix but I can't figure out how to take a 2D image, simulate rotating it around the x axis and then saving that back to an image. So that my original grid of dots would look like the bottom image with lines going off to a vanishing point. I've seen some examples using imwarp but I didn't see how I can set the angle of rotation. I'm working on camera calibration so I really want to be able to specify an angle of rotation around each axis.
Thanks for any help.

When rotating an image about its center, why do you need to add/subtract the centroid?

I'm learning about image processing in class, and it's all going quite fast so I'm having a bit of trouble wrapping my head around the different concepts. In rotation specifically, I understand that you need to multiply each of the pixel coordinates of an input image by the rotation matrix to get an output image. However, when you are rotating an image around its center, you need to do a translation to subtract the centroid, then rotate, then add the centroid back in. What is the logic behind this, how does it work?
In general, when you rotate an object, you rotate it about origin (0,0). But if you want to rotate the object about some other point, which in your case is centroid, you move the origin to that point by subtracting it. After rotation, when you want the output in the same coordinate system as you began with, you bring back the origin to its normal position by adding it back.
The images below demonstrate it to make better sense-
The object to rotate initially.
When you rotate it by 135 degrees anticlock. Output1
But if you want to rotate about centroid, move the origin there.
How it now looks -
Rotating the same 135 degrees anticlock now-
Getting back to the old coordinate system by adding back the centroid - Output2
Clearly the Output1 and Output2 are not same right, so subtracting and adding the centroid or not depends on about which point you want to rotate.

Images rotate along y axis

How can let the images rotate along y axis?
I try to use this code,but it just rotate along image's y axis.
imageView.layer.transform = CATransform3DConcat(imageView.layer.transform, CATransform3DMakeRotation(180,0.0,1.0,0.0));
Anybody can solve my question?many thanks.
Translate first (by half of image width) and then rotate.

How to rotate an image about a point that is not the image's center point using MATLAB?

What is the method to use to rotate an image about a point that is not the image's center point using MATLAB?
Two rotations of the same angle are equal up to a translation. So you can just do rotation around the center, and then translate the image to put your own center of rotation at its old position.
The help to 'rotate' says:
ROTATE Rotate objects about specified origin and direction.
ROTATE(H,[THETA PHI],ALPHA) rotates the objects with handles H
through angle ALPHA about an axis described by the 2-element
direction vector [THETA PHI] (spherical coordinates).
All the angles are in degrees. The handles in H must be children
of the same axes.
...
ROTATE(...,ORIGIN) uses the point ORIGIN = [x0,y0,y0] as the center
of rotation instead of the center of the plot box.
To rotate about a point other than the origin you:
Translate the point you want to rotate around to the origin. For example, if you want to rotate around (3,5), you would translate by (-3,-5).
Perform your rotation.
Undo the initial translation. So in my example you would now translate by (+3,+5).

iPhone CALayer's rotation axis

I'm rotating a CALayer on the X axis, but even if it's displaced on the Z axis, it uses the Z = 0 as axis for the rotation?
Is there a way of telling it to use the bottom of the plane, as the axis?
Thank you!
The transform of a CALayer uses the layer's anchor as its origin. You could try adjusting the anchorPoint and anchorPointZ properties of the layer.