Converting Fish Eye image to Panoramic image?

I have acquired a fish eye lens image of the sky and I would like to "unfold" this image, in matlab, into a Panoramic image instead of spherical. I am having a very hard time figuring out how to do so. I've found a function in MATLAB, which I think might be useful:
[x,y,z] = sph2cart(azimuth,elevation,r)
But i simply can't figure out how to use it.
I was wondering if any one might have created an example of how to use this function to convert an image from Spherical to panoramic coordinates.

 Réponse acceptée

Image Analyst
Image Analyst le 3 Avr 2014
Modifié(e) : Image Analyst le 3 Avr 2014
In optical distortion, the distance the pixel moves from its correct location is proportional to the cube of the radius from the optical axis. In other words:
rBad = rTrue + df * rTrue;
Where rTrue is where it should be if there were no distortion, df is the magnitiude of the fish-eye effect, and rBad is where it actually is (because of the distortion). You can use that formula to get find out where bad pixels should get mapped (sent) to. Make a grid of every 10 pixels or so and find out what their true location should be.
Then I believe you can use those locations (the actual bad locations, and the desired good locations) in imtransform() to un-distort the image. Give it a try. Demo attached. See if you can finish it by using imtransform().
The + are the distorted points and the o are the corrected points. Not sure why the legend function is not realizing what points are what.

9 commentaires

Thank you very much for your answer. I am kind a new to the whole matlab syntax and therefor find it difficult to follow you. Could you perhaps further elaborate on how to use the imtransform() function? And am i understading it right if a say that the calculated rBad is the current pixel position and the calculated rTrue is where it would like the pixel to go? Again, i really appreciate you talking your time to help med :)
Yes, that's correct. I wrote a demo to calculate the bad and true coordinates. It's attached. I don't have time today to figure out how to use it in imtransform(). If you figure it out, then post it. Maybe I'll get to it on the weekend, but maybe not.
Thank you very much. I will do my very best :)
I still can't seem to figure it out how i should actually be able to unwarp a fish eye image using the code you have provided (though i am very grateful you have done so) instead i stumbled upon this example.
However, i can't seem to figure out how to perform the operation on a picture.. yet :)..
See MATLAB example. Sorry I haven't had a chance to finish the code for you. But it looks like you can do it with interp2 as shown here: http://www.mathworks.com/matlabcentral/answers/23708#answer_31442
Hello again.. I really appreciate you talking time to help me out. I tried implementing the code you have linked, unfortunately this has no effect on the image. Perhaps I am doing it wrong?
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Specify the distortion correction factor.
% Positive to correct pincushion distortion, and bring coreners inwards.
% Negative to correct barrel (fisheye) distortion, and push corners outward.
df = -0.5;
xCenter = columns / 2; % Assume optical axis in center of image.
yCenter = rows / 2;
samplingRate = 50;
[xBad, yBad] = meshgrid([1 : samplingRate : columns], [1: samplingRate :rows]);
hold on;
plot(xBad, yBad, 'r+', 'MarkerSize', 5, 'LineWidth', 2);
for r = 1 : size(xBad, 1)
for c = 1 : size(xBad, 2)
x = xBad(r, c);
y = yBad(r, c);
% Get the actual distance from the optic axis.
rBad = sqrt((x - xCenter)^2 + (y - yCenter)^2);
% Get the delta R that is moved.
deltaRadius = df * rBad / (1 + df);
rTrue = rBad - deltaRadius;
angle = atan2((y - yCenter), (x - xCenter));
xTrue(r, c) = xCenter + rTrue * cos(angle);
yTrue(r, c) = yCenter + rTrue * sin(angle);
D = interp2(double(grayImage), x-xTrue, y-yTrue);
% display the result
imshow(D, []);
end
end
plot(xTrue, yTrue, 'bo', 'MarkerSize', 5, 'LineWidth', 2);
legend({'+ = Distorted'; 'o = Corrected'});
N A
N A le 25 Jan 2020
This provides a correction algorithm for distortion, but I'm trying to take a grayscale image (that's rendered) and apply a barrel distortion to it. How would I approach this problem?
Neil
Neil le 30 Jan 2024
Not sure if this is worth it's own question or not, but you seem like the best person to ask. Suppose I have a cube of material with a index of refraction that varies in a known way, like a GRIN lens. I can calcuate the optical path lengths and get the optical path difference as a function of position on the imager. So I know . Then say I have one the matlab stock images, like cameraman.tif. How would I go about calculating what the image would look like when viewed through this material.
So basically trying to do something similar to the answer above, but instead of a fish eye, it is some arbitrary aberation.
Thanks.
@Neil I don't believe MATLAB has any kind of general functions for that. You'd have to write your own. Or you can use an optical design program like FRED
or Code V

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by