Skip to main content

Converting a Panoromic Image into a circular Image

rect2circ.c is a small piece of C code based on OpenCV to convert a panoramic image into a circular image. My idea was to convert a speech signal recorded for a long duration of time continuously

to be represented in a way the time during which it was recorded. In the below image it is between 10 and 5.
While this is simple, I did not find anything readily available and hence write this small piece of C code using OpenCV. The usage (when compiled) is
Usage: ./rect2circ -> an input rectangle image -> output circular image -> start time (0 .. 12) -> number of hours (0 .. 12) -> inner radius (0 .. 200)
The source code.
/*======
Convert a panoramic image into a circular image.
La updated by Sunil Kumar Kopparapu at 21/10/2013 (23:07)
===== */

#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "opencv/cv.h"
#include "opencv/cxcore.h"
#include "opencv/highgui.h"

#define FAIL -1
#define DISPLAY 0 
#define COMMENT 0 
#define my_min(x,y)(xy?x:y)
#define PI 4*atan(1.0)
#define a_RADIUS 100


int main(int argc, char** argv) {

IplImage *im = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;
int out_height;
int c_x, c_y, X, Y, x, y;
int radius = -1, my_radius, a_radius;
double span = -1.0, start = -1.0;
double i_span = -1.0, i_start = -1.0;

IplImage *out = 0;

if(argc != 6){
  fprintf(stderr,"Usage: %s     \n", argv[0]);
  fprintf(stderr,"\t  -> an input rectangle image\n");
  fprintf(stderr,"\t  -> output circular image\n");
  fprintf(stderr,"\t  -> start time (0 .. 12)\n");
  fprintf(stderr,"\t  -> number of hours (0 .. 12)\n");
  fprintf(stderr,"\t  -> inner radius (0 .. 200)\n");
  return(FAIL);
}

im = cvLoadImage(argv[1], 1);

if(!im) {
  fprintf(stderr,"Unable to Read %s\n",argv[1]);
  return(FAIL);
}
else {
  height    = im->height;
  width     = im->width;
  step      = im->widthStep;
  channels  = im->nChannels;
  data      = (uchar *)im->imageData;
  fprintf(stderr,"Processing %s, %d x %d image with %d channels\n",argv[1], height, width, channels);

  if(DISPLAY) {
    cvShowImage("Original", im);
    cvWaitKey(0);
  }
}

/* Create the output image */
a_radius = atoi(argv[5]);

if(a_radius < 0) a_radius = a_RADIUS;
radius = (a_radius + im->height);
i_start = atof(argv[3]);
i_span = atof(argv[4]);

if(i_start < 0.0) {
 i_start = 0.0;
}
start = 2.0*(i_start/12.0)*PI;

if(i_span <0 .0="" adius:="" argv="" channels="" d="" f="" fprintf="" i_span="12.0;" if="" image="" ipl_depth_8u="" n="" out-="" out="cvCreateImage(cvSize(out_height," out_height="" radius="" reating="" s="" span="" start="" stderr="" with="" x="">height, out->width, out->nChannels);
fprintf(stderr,"Clock display starts at %.2f and displays for %.2f hours\n", i_start, i_span);

c_x = (int) (out->height/2);
c_y = (int) (out->width/2);

if(COMMENT) fprintf(stderr,"center: %d %d\n",c_x,c_y);


for (x=0; x< im->width; x++){
  for(y=0; y< my_max(1,im->height); y++){
      my_radius = radius - y;
      X = my_radius*sin((((float)x/(float)im->width)*span)+start);
      Y = my_radius*cos((((float)x/(float)im->width)*span)+start);
      X = c_x + X;
      Y = c_y - Y;
      for (k=0; k< my_max(1,channels); k++){
      out->imageData[Y*(out->widthStep) + X*channels + k] =im->imageData[y*(im->widthStep) + x*channels + k];
    }
  }
}


cvSaveImage(argv[2], out, 0);

if(DISPLAY) {
  cvShowImage("Output", out);
  cvWaitKey(0);
}

return(1);
}

Comments

Popular posts from this blog

Visualizing Speech Processing Challenges!

Often it is difficult to emphasize the difficulty that one faces during speech signal processing. Thanks to the large population use of speech recognition in the form of Alexa, Google Home when most of us are asking for a very limited information ("call my mother", "play the top 50 international hits" or "switch off the lights") which is quite well captured by the speech recognition engine in the form of contextual knowledge (it knows where you are; it knows your calendar, it know you parents phone number, it knows your preference, it knows your facebook likes .... ). Same Same - Different Different:   You speak X = /My voice is my password/ and I speak Y= /My voice is my password/. In speech recognition both our speech samples (X and Y) need to be recognized as "My voice is my password" while in speaker biometric X has to be attributed to you and and Y has to be attributed to me! In this blog post we try to show   visually   what it means to pro...

BITS Pilani Goa Campus - Some Useful Information

You have cleared the BIT Aptitude Test and have got admission to BITS Pilani Goa Campus. Congratulation . Well Done. This is how the main building looks! Read on for some useful information, especially since you are traveling for the first time to the campus and more or less you will face the same scenario that we faced! We were asked report on 29-Jul-2018 (Sunday) to take admission on, 30-Jul-2018.  We reached Madgoan (we traveled by train though the airport is pretty close to the BITS campus, primarily to allow us to carry more luggage!)at around 0700 hours (expect a few drizzles to some good rain - so carry an umbrella) on 29-July-2019. As you come out you will be hounded by several taxi drivers, but the best is to take the official pre-paid taxi. It should cost you INR 700 to reach the BITS campus. We had booked a hotel in Vasco (this is one of the closest suburb from BITS campus, a taxi should charge you around 300-350 INR; you will make plenty of trips!) ...

Paying Property Taxes Online - Government of Andhra Pradesh

When my father received a SMS stating that you can pay your property tax online. I was thrilled. Why? My father stays with me in Mumbai and paying property tax for a small flat in   Proddatur Municipality was always a pain. The best was to request someone to pay it on behalf of him which meant it was at the time and convenience of the person we requested. Mind you this is no easy task, asking someone to pay on your behalf. A quick search on the web got me to  Commissioner & Director of Municipal Administration  and I it does have an online payment of taxes tab. And boy this was a breeze. As soon as you press the online payment tab you see a neat selection of District | Muncipality | Tax Type. For my purposes I choose Ysr Kadapa (it would be nice if they changed it to read "YSR Kadapa") and then "1014-Proddatur" for Municipality and I chose Tax Type is "Property Tax" (the other option is Water tax) Once you fill in these details. You are directe...