3

I would like to convert a Jpeg image (its coordinates (x,y)) into a Cylindrical coordinates..

Is there a function in opencv that can do this directly? or what functions in opencv can I use to create my own??

I am having confusion between 2d coordinates, 3d coordinates and cylindrical coordinates.. can someone briefly discuss this?

Is there a mathematical algorithms available to convert 2d to 3d? 2d to cylindrical coordinates? 3d to cylindrical coordinates?

I read the previous post regarding this topic but does not understand it..

I have not take a course on image processing but I'm in a rush to read books.. I learn by experience and by studying other programmers code.. so source code will be much appreciated..

thanks to everyone and sorry for my elementary post,,

njm
  • 51
  • 1
  • 2
  • 7
  • i would like to convert the 2d coordinates of the jpeg image into cylindrical coordinates.. I will be using the converted coordinates into image stitching function later.. – njm Dec 17 '11 at 02:45

1 Answers1

7

In the 2D realm, you have Polar coordinates. OpenCV has two nice functions for converting between Cartesian and Polar coordinates cartToPolar and polarToCart. There doesn't seem to be a good example of using these functions, so I made one for you using the cartToPolar function:

#include <opencv2/core/core.hpp>
#include <iostream>

#include <vector>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    vector<double> vX;
    vector<double> vY;

    for(int y = 0; y < 3; y++)
    {
        for(int x = 0; x < 3; x++)
        {
            vY.push_back(y);
            vX.push_back(x);
        }
    }

    vector<double> mag;
    vector<double> angle;

    cartToPolar(vX, vY, mag, angle, true);

    for(size_t i = 0; i < mag.size(); i++)
    {
        cout << "Cartesian (" << vX[i] << ", " << vY[i] << ") " << "<-> Polar (" << mag[i] << ", " << angle[i] << ")" << endl;
    }

    return 0;
}

Cylindrical coordinates are the 3D version of Polar coordinates. Below is a small sample to show how you could implement cylindrical coordinates. I'm not sure where you'll be getting your 3D z-coordinate, so I just made it arbitrary (e.g., x + y):

Mat_<Vec3f> magAngleZ;

for(int y = 0; y < 3; y++)
{
    for(int x = 0; x < 3; x++)
    {
        Vec3f pixel;
        pixel[0] = cv::sqrt((double)x*x + (double)y*y); // magnitude
        pixel[1] = cv::fastAtan2(y, x);                 // angle
        pixel[2] = x + y;                               // z
        magAngleZ.push_back(pixel);
    }
}

for(int i = 0; i < magAngleZ.rows; i++)
{
    Vec3f pixel = magAngleZ.at<Vec3f>(i, 0);
    cout << "Cylindrical (" << pixel[0] << ", " << pixel[1] << ", " << pixel[2] << ")" << endl;
}

If you're interested in image stitching, have a look at the stitching.cpp and stitching_detailed.cpp samples provided by OpenCV.

EDIT :
You may find these resources on cylindrical projection helpful:

Computer Vision: Mosaics
Why Mosaic?
Automatic Panoramic Image Stitching using Invariant Features
Creating full view panoramic image mosaics and environment maps

mevatron
  • 13,911
  • 4
  • 55
  • 72
  • Yes, you're right I'm interested in image stitching.. I was able to successfully run your first program but having problems in the your second source code with line >>magAngleZ.push_back(pixel); – njm Dec 17 '11 at 15:32
  • Thanks for the help.. Appreciated. I have another question.. An image has pixel values located in each (x,y) coordinates. My question is if I convert my (x,y) coordinates into cylindrical coordinates will the pixel value located on that coordinate changed?? Hope you get my question.. Correct me I have misunderstanding.. – njm Dec 17 '11 at 15:38
  • @NicoleMontecalvo If you are having trouble with the `Mat::push_back()` function, you may be running an older version of OpenCV. What version are you using? – mevatron Dec 17 '11 at 17:33
  • I am running opencv 2.3.0 in Codeblocks 10.05, MinGw Gnu Gcc Compiler.. I have read through a lot of articles.. Do i need to calibrate my camera? i will be using a casio exilim ex-z77 but the examples i saw, it seems that they are using webcameras.. Is there a way I can calibrate my camera. Correct me if I'm wrong.. This maybe different from what I initially asked.. Regards and thank you. – njm Dec 18 '11 at 01:51