How to Create MATLAB Code for Geometrical Optics Image Transformation?

wuid
Messages
38
Reaction score
0
Hello all,

i have frustrating task in my lab...

i have to generate a code in MATLAB that will get the focal length and the object distance from the lens, i.e image (1000X1000 pixels).
transfer it through the lens and, for the output it should be the result of it: inverse,magnified/shrinked version of the image. of course depends on the focal & distance of the object.
this should be done considering that the lab is on geometrical optics...

any help/reference would be appreciated

my thought was to form a incidence matrix that will be transformed after multiplication with transfer matrix (Air,Lens,Air) and apply this matrix to the image matrix.
 
Physics news on Phys.org
Lets make sure I understand you:
You have been given an image - and you need to know how far the object is.

Presumably you know something about the lens-system and/or the object?

My immediate approach would be to run the optics backwards - since geometric optics is reversible.
I'd also just pick one point on the image as the "arrow head".

But yeah - transfer matrix etc.
 
we know all about the lens system: f,distance of from the object,distance of the image.
i'm pretty lack of knowledge how to implement it with matlab. need for some sort of algorithm of how to do it.
 
I'm not sure I see the problem - you know the image and object distances, the focal length, so you know the magnification (you have a formula for that?) So what is wrong with a script that takes these details as the input, calculates the magnification, and interprets it?

i.e. how would you perform this task on paper?

But now I suspect that I have not understood the problem ... what will the program take as input, what is to be assumed (i.e. is it always the same lens? Is it a thin lens? What?), and what is the output supposed to be? Try to be more careful in your description.
 
ok, sorry,
you understood very well the problem, but the implementation is not so obvious (for me i guess...).
as an input i have:
1)1000X1000 image.
2)distance of the image from the lens
3)focal length

now i can calculate as you said the distance of the image after the lens & the magnification.
that's the easy part.
now i have to apply some algorithm that will take the original image and will transform it to the expected image,
let's say that magnification was calculated and it equals 2.
so I'm expecting to see a 2000x2000 magnified image upside down and mirrored.
how do i map each of indices of the original image to the expected image ?
example: the [(1,1)] pixel should be mapped to [(2000,2000)] pixel of the magnified version of the image.
 
So you just need the transformations of the image ... like how to turn it upside down, scale it, etc?
Why not just use Matlab's built-in image processing functions?
http://www.mathworks.com/help/images/functionlist.html
 
thought to do it in more "analytic" way...
i accomplished the assignment as you suggested, but in this way there is no "lens" in the code only the outcomes.

Code:
clear
%Input object distance do
do=15;
%Input focal length of lens f
f=-lO;
% Input distance behind lens z
z=30;
%Input object ray coordinates ro
ro-[O;1];
To=[ 1 ,do;0,1 ];
sf:[1,0;-(1/f),l];
Ti=[ 1 ,z;0,1 ];
S=Ti*Sf*To;
%Check for determinant of overall matrix S
detS=det(S)
%"image" ray coordinate is ri
ri=S*ro
Output from MATLAB
detS =
1
ri =
0
-0.5000

variation of this code.
 
Well done - sometimes it's just a mater of kickstarting the old grey matter.
 
thanks for the help, Simon :)
 
Back
Top