| | |
image rotation
![]() |
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
hi,
i have to rotate an image. the image is stored in an image[rows][cols] array..
i am trying to rotate it using trignometric functions.
i am not sure what happens when i rotate the image,
does the address of the pixel vary or the value of the pixel vary.
and when i rotate an image by say 45 degrees, then wont it fall out of the gird?
please clear my doubts :-|
i have to rotate an image. the image is stored in an image[rows][cols] array..
i am trying to rotate it using trignometric functions.
i am not sure what happens when i rotate the image,
does the address of the pixel vary or the value of the pixel vary.
and when i rotate an image by say 45 degrees, then wont it fall out of the gird?
please clear my doubts :-|
>>does the address of the pixel vary or the value of the pixel vary.
Depends how you see this matter: let's assume the rotation center is the center of the image. So, rotating the image means the pixel p[x][y] will have the value that was allocated to the pixel p[x1][y1] - the value of the pixel vary. Or, the value GREEN that was on the pixel p[x][y] will be, after rotation, in the pixel p[x1][y1] - the address of the pixel vary () (I assumed "the address of the pixel" is the position of a pixel with a certain value)
>>when i rotate an image by say 45 degrees, then wont it fall out of the gird
If your image is rectangular, imagine that rotating it will change it's position on the screen like you will rotate a sheet of paper on the table. How will differ these two positions?
Depends how you see this matter: let's assume the rotation center is the center of the image. So, rotating the image means the pixel p[x][y] will have the value that was allocated to the pixel p[x1][y1] - the value of the pixel vary. Or, the value GREEN that was on the pixel p[x][y] will be, after rotation, in the pixel p[x1][y1] - the address of the pixel vary () (I assumed "the address of the pixel" is the position of a pixel with a certain value)
>>when i rotate an image by say 45 degrees, then wont it fall out of the gird
If your image is rectangular, imagine that rotating it will change it's position on the screen like you will rotate a sheet of paper on the table. How will differ these two positions?
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
i tried this code for rotating,
but for r1 and c1, i am getting negative values..
and the rotation is also not proper..
------------------------------------
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
r1=(i*cos(angle))-(j*sin(angle));
c1=(i*sin(angle))+(j*cos(angle));
rot_image[r1][c1]=image[i][j];
}
}
---------------------------------------
:-?
but for r1 and c1, i am getting negative values..
and the rotation is also not proper..
------------------------------------
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
r1=(i*cos(angle))-(j*sin(angle));
c1=(i*sin(angle))+(j*cos(angle));
rot_image[r1][c1]=image[i][j];
}
}
---------------------------------------
:-?
I think the correct relations are more like
r1 = iorig + (i - iorig)sin(angle)
c1 = jorig + (j - jorig)cos(angle)
where iorig, jorig are th ecoordinates of the rotation center.
(but I'm not too sure - it's a long time since I did some trigonometry
()
And, also, there is possible to obtain negative values for the new coordinates, since they are reported to the coordinates of the rotation origin.
r1 = iorig + (i - iorig)sin(angle)
c1 = jorig + (j - jorig)cos(angle)
where iorig, jorig are th ecoordinates of the rotation center.
(but I'm not too sure - it's a long time since I did some trigonometry
()And, also, there is possible to obtain negative values for the new coordinates, since they are reported to the coordinates of the rotation origin.
If you rotate a square image about it's center, clipping will occur on all sides. The most clipping will occur when the image is rotated by a multiple of 45 degress. At a multiple of 45 degrees, any part of the image extending past the original boundries will clip, which is anything about ImageWidth*cos(PI/4) (or ImageWidth*sqrt(2)/2) along the line from the center to a corner's worth of pixels. The only way to do it and keep all of the data is to make the boundries of the image larger. The easiest way is to have a source and dest images, where dest is approximately sqrt(2) larger in each dimension for all rotations, or variations of 1.0f/cos(Angle) or 1.0f/sin(Angle) depending on the range of angles to avoid asymptotes.
-don't listen to me-
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
hey u can rotate an image by using c,,,just use geometric equations and u must have a good knowkedge about cordinate systems , and frame of referances ..i achived it .but the problem is that it losses quality..
there is a problem when rounding the digit .. if u have any doubt u pls mail me...
<email snipped>
....here im doing a project on that.............
there is a problem when rounding the digit .. if u have any doubt u pls mail me...
<email snipped>
....here im doing a project on that.............
Last edited by WolfPack; Feb 5th, 2008 at 5:04 am. Reason: Removed email as per forum rule : Keep it within the site
![]() |
Similar Threads
- Image rotation not visible in Firefox (Web Browsers)
- Image rotation (C)
- BCB6 Image Rotation (Compass) Help!!!!!! (C++)
- Image Rotation w/Links (JavaScript / DHTML / AJAX)
- Rotation (Java)
Other Threads in the C Forum
- Previous Thread: plz help me
- Next Thread: easy question... i think
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






