Matlab code for geometrical optics

In summary, Simon was trying to figure out how to generate an inverse image of an object that is 1000 pixels wide by 1000 pixels high using MATLAB. He mentioned that he would need to calculate the magnification, and then map the image coordinates to the expected coordinates in the magnified image.
  • #1
wuid
40
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 
  • #6
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
 
  • #7
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.
 
  • #8
Well done - sometimes it's just a mater of kickstarting the old grey matter.
 
  • #9
thanks for the help, Simon :)
 

1. What is Matlab code for geometrical optics?

The Matlab code for geometrical optics is a set of commands that can be used to simulate and analyze the behavior of light rays as they pass through optical systems such as lenses and mirrors. It allows for the calculation of parameters such as image formation, refraction, and reflection for various optical setups.

2. How do I plot the path of light rays using Matlab for geometrical optics?

To plot the path of light rays using Matlab for geometrical optics, you can use the "raytrace" function. This function takes in parameters such as the starting point, direction, and curvature of the rays, and plots their trajectory through the optical system. You can also customize the plot to include additional information such as the location of focal points and principal planes.

3. Can Matlab code for geometrical optics handle complex optical systems?

Yes, Matlab code for geometrical optics is capable of handling complex optical systems. It allows for the creation of multiple optical elements, such as lenses and mirrors, and the specification of their properties. This makes it suitable for simulating and analyzing the behavior of light in real-world optical setups.

4. Is there a library of pre-written Matlab code for geometrical optics available?

Yes, there are several libraries of pre-written Matlab code for geometrical optics that are available for use. These libraries contain functions and algorithms that can be used to perform common calculations and simulations in the field of geometrical optics. They can be found on various online platforms and can be easily integrated into your own code.

5. Can I use Matlab code for geometrical optics for educational purposes?

Yes, Matlab code for geometrical optics can be used for educational purposes. It can be a useful tool for teaching students about the principles of geometrical optics and how to perform calculations and simulations in this field. Many universities and educational institutions use Matlab for teaching optics and provide resources and tutorials for students to learn from.

Similar threads

Replies
13
Views
1K
Replies
17
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
903
  • Advanced Physics Homework Help
Replies
1
Views
1K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
1
Views
959
  • Introductory Physics Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top