python - Transform and remap an equirectangular image with a 90° roll -


i have transform , remap equirectangular image other equirectangular image 90° roll.

i did pano2vr.

the problem have programmatically server side. can't use g.u.i. it.

first, oriented research imagemagick. tried fred imagemagick scripts not find want do. moreover, processing time of image appears long compared pano2vr.

i directed investigations opencv , libgnomonic. it's presently interesting way. library allows te user transform projections (equirectangular rectilinear , vice versa) or make equirectangular mapping transformation. played norama-suite wich contains scripts deal library. example, convert rectilinear image equirectangular the output black background image (why ? didn't find answer).

however, second link resolve problem. have image :

and want transform image

well, i'm not comfortable @ c. think should use 2 files :

but don't know how. , above all, want understand.

am on right way ? transformation applied on first image ? there way python or bash script ?

well, thank help.


**edit transposition of c in python ** following code didn't work , return , indexerror. tried catch , pass exception , first right part of image did not seem changed.

import math pil import image  img = image.open("img1.jpg") img = img.convert('rgb') pixel = img.load() width, height = img.size  img2 = img.copy() y in xrange(height):     x in xrange(width):         xx = 2*(y+0.5) / width - 1.0         yy = 2*(y+0.5)/ height - 1.0         lng = math.pi * xx         lat = 0.5 * math.pi * yy          z = math.cos(lat) * math.cos(lng)         y = math.cos(lat) * math.sin(lng)         x = -math.sin(lat)         d = math.sqrt(x*x+y*y)          lat = math.atan2(z, d)         lng = math.atan2(y, x)          #ix , iy must integers         ix = int((0.5 * lng / math.pi + 0.5) * width - 0.5)         iy = int((lat/math.pi + 0.5) * height  - 0.5)          #not sure of part remap image         newpixel = pixel[ix, iy]         img2.putpixel([(x+width/4) % width, y], newpixel)         #i tries mentionned in following code invert x , y in 2 previous lines index error out of range comes  img2.show() 

your transformation has 2 steps. first step transformation of projection sphere, second 90° roll.

a 90° roll of equirectangular image horizontal shift of quarter of image width. first transformation more complicated: want rotate sphere north pole @ latitude 0 , longitude 0 (somewhere in gulf of guinea, if take thze earth reference.)

you can go transformation these steps;

  • translate x , y position of each pixel longitude, −π ≤ long ≤ π, , latitude, −π/2 ≤ lat ≤ π/2. linear transformation.
  • create x, y, , z coordinates of corresponding longitude , latitude on unit sphere; positive z north pole.
  • rotate these cartesian coordinates. in case, have swap dimensions, general transformation transformation matrix.
  • calculate longituide , latitude of rotated coordinates.
  • transform new longitude , latitude pixel position.

here's c code works. (i know have tagged question python, code below formulas work in python. have take care: of number floating point numbers except pixel indixes x, y, ixand iy. have done in python, have no experience python image library.)

for (y = 0; y < height; y++) {     (x = 0; x < width; x++) {         double xx = 2 * (x + 0.5) / width - 1.0;         double yy = 2 * (y + 0.5) / height - 1.0;         double lng = pi * xx;         double lat = 0.5 * pi * yy;          double x, y, z;         double d;         int ix, iy;          z = cos(lat) * cos(lng);    // corresponds original x         y = cos(lat) * sin(lng);    // corresponds original y         x = -sin(lat);              // corresponds original z          d = sqrt(x*x + y*y);        // distance in xy plane         lat = atan2(z, d);         lng = atan2(y, x);          ix = (0.5 * lng / pi + 0.5) * width - 0.5;         iy = (lat / pi + 0.5) * height - 0.5;          dest[y][(x + width / 4) % width] = src[iy][ix];                                     // width/4 offset ist 90° roll                                     // % width wraps longitude     } } 

the quality of resulting image okay, not of reference image, near poles. better algorithm woul average , smoothze colour values. algorithm above maps 1 destination pixel source pixel.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -