Click here to Skip to main content
15,891,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionvariable, a simple suggestion to C/C++ beginner Pin
includeh1014-Jan-06 17:13
includeh1014-Jan-06 17:13 
AnswerRe: variable, a simple suggestion to C/C++ beginner Pin
El Corazon14-Jan-06 17:49
El Corazon14-Jan-06 17:49 
GeneralRe: variable, a simple suggestion to C/C++ beginner Pin
Stephen Hewitt14-Jan-06 18:03
Stephen Hewitt14-Jan-06 18:03 
GeneralRe: variable, a simple suggestion to C/C++ beginner Pin
El Corazon14-Jan-06 18:39
El Corazon14-Jan-06 18:39 
GeneralRe: variable, a simple suggestion to C/C++ beginner Pin
Shraddhan22-Jan-06 23:34
Shraddhan22-Jan-06 23:34 
Questionstructure representing file Pin
John Simon14-Jan-06 14:50
John Simon14-Jan-06 14:50 
AnswerRe: structure representing file Pin
El Corazon14-Jan-06 15:04
El Corazon14-Jan-06 15:04 
QuestionHard maths problem Pin
Christian Graus14-Jan-06 12:41
protectorChristian Graus14-Jan-06 12:41 
I've inherited an image processing task which I didn't initially write, but which I need to modify - I need to change an input parameter according to the position within the input image. Naturally, the code works by iterating over the destination image, but now I need to change it to iterate over the source image, so I can work out this parameter as I go. The parameter is called sourceFOVRads ( for reference in the code ). The trouble is, I can't work out how to reverse the code so that it iterates over the source instead of destination image. Of course, I know how to iterate over an image using polar co-ordinates, but I think the transform needs to be completely rewritten, I don't see how to reverse the Atan2 calls to get the input parameters.

for(int j=0;j<output.height;j++)
{
for(int="" i="0;i<output.Width;i++)
" {
="" double="" x="2" *="" (double)output.width="" -="" 1;="" -1="" to="" 1

="" y="2" j="" (double)output.height="" calculate="" phi="" and="" theta=""
="" latitude="y*Math.PI/2;" -pi="" 2="" <="y" pi="" longitude="x*Math.PI;"

="" p="" is="" the="" vector="" from="" camera="" position="" into="" scene="" p.x="Math.Cos(latitude)*" math.sin(longitude);
="" p.y="Math.Cos(latitude)*" math.cos(longitude);
="" p.z="Math.Sin(latitude);

" fisheye="" polar="" coordinates
="" r="pixelRadius*phi" sourcefovrads;
="" determine="" coordinate="" in="" source="" image
="" u="Convert.ToInt32(fishCentre.X" +="" r*math.cos(theta));
="" if(u="" 0="" ||="">=source.Width)
continue;
v=Convert.ToInt32(fishCentre.Y - r*Math.Sin(theta));
if(v < 0 || v>=source.Height)
continue;

pOut[(outputStride*j)+(i*3)]=(Byte)(int)pSrc[(sourceStride*v)+(u*3)];
pOut[(outputStride*j)+(i*3)+ 1]=(Byte)(int)pSrc[(sourceStride*v)+(u*3)+ 1];
pOut[(outputStride*j)+(i*3)+ 2]=(Byte)(int)pSrc[(sourceStride*v)+(u*3)+ 2];

As I said, I can do the basic stuff, like so:

for (double t = 0; t < 2 * Math.PI; t += .01)
{
for (int radius = 0; radius < pixelRadius; ++radius)
{
int xSrc = (int)(radius * Math.Cos(t)) + fishCentre.X;
int x = 2 * (xSrc/source.Width) - 1;
int ySrc = (int)(radius * Math.Sin(t)) + fishCentre.Y;
int y = 2 * (xSrc/source.Height) - 1;

pOut[(int)(x*3 + y * sourceStride)] = pSrc[(int)(x*3 + y * sourceStride)];
pOut[(int)(x*3 + 1 + y * sourceStride)] = pSrc[(int)(x*3 + 1 + y * sourceStride)];
pOut[(int)(x*3 + 2 + y * sourceStride)] = pSrc[(int)(x*3 + 2 + y * sourceStride)];
}
}

This code uses polar co-ordinates to copy just the circle of the image that we're interested in, without any transform. It steps over the theta far too quickly mostly so I can quickly see the results of my code Smile | :)

However, in this block:

theta=Math.Atan2(p.z,p.x);
phi=Math.Atan2(Math.Sqrt(p.x*p.x+p.z*p.z),p.y);
r=pixelRadius*phi / sourceFOVRads;

I don't know where to start. I have the pixel radius and r, and as I have my source radius, I can calculate which sourceFOVRads value to use, so I can work out phi, easily. But, I obviously cannot derive the values for p.x, p.y and p.z from this value, and I'm not sure how else to go about it. Any help on this will be greatly appreciated, because I am really stuck.

BTW, the code is C#, I posted it here for visibility.

Christian Graus - Microsoft MVP - C++
AnswerRe: Hard maths problem Pin
Sean Cundiff14-Jan-06 14:25
Sean Cundiff14-Jan-06 14:25 
GeneralRe: Hard maths problem Pin
Christian Graus14-Jan-06 19:56
protectorChristian Graus14-Jan-06 19:56 
AnswerRe: Hard maths problem Pin
Stephen Hewitt14-Jan-06 14:35
Stephen Hewitt14-Jan-06 14:35 
GeneralRe: Hard maths problem Pin
Christian Graus14-Jan-06 19:52
protectorChristian Graus14-Jan-06 19:52 
AnswerRe: Hard maths problem Pin
Michael A. Barnhart14-Jan-06 14:36
Michael A. Barnhart14-Jan-06 14:36 
AnswerRe: Hard maths problem Pin
El Corazon14-Jan-06 14:41
El Corazon14-Jan-06 14:41 
GeneralRe: Hard maths problem Pin
Christian Graus14-Jan-06 20:05
protectorChristian Graus14-Jan-06 20:05 
Questioni need TIC TAC TOE source vc++ Pin
peyman1361814-Jan-06 10:23
peyman1361814-Jan-06 10:23 
AnswerRe: i need TIC TAC TOE source vc++ Pin
Christian Graus14-Jan-06 12:38
protectorChristian Graus14-Jan-06 12:38 
QuestionAccessing Video Files Pin
AJ12314-Jan-06 9:15
AJ12314-Jan-06 9:15 
AnswerRe: Accessing Video Files Pin
Chris Losinger14-Jan-06 9:45
professionalChris Losinger14-Jan-06 9:45 
Questionloading and displaying images Pin
Fatima Tuz Zahra13-Jan-06 19:37
Fatima Tuz Zahra13-Jan-06 19:37 
AnswerRe: loading and displaying images Pin
zubair_ahmed13-Jan-06 20:06
zubair_ahmed13-Jan-06 20:06 
GeneralRe: loading and displaying images Pin
Fatima Tuz Zahra13-Jan-06 20:25
Fatima Tuz Zahra13-Jan-06 20:25 
GeneralRe: loading and displaying images Pin
includeh1013-Jan-06 20:38
includeh1013-Jan-06 20:38 
GeneralRe: loading and displaying images Pin
Fatima Tuz Zahra13-Jan-06 20:54
Fatima Tuz Zahra13-Jan-06 20:54 
GeneralRe: loading and displaying images Pin
includeh1014-Jan-06 3:32
includeh1014-Jan-06 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.