How to Create MATLAB Code for Geometrical Optics Image Transformation?

Click For Summary

Homework Help Overview

The discussion revolves around creating MATLAB code for geometrical optics, specifically focusing on image transformation through a lens. The original poster seeks assistance in generating a code that processes an image based on the focal length and object distance, resulting in a transformed image that may be inverted or magnified.

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants explore the concept of using a transfer matrix to manipulate an image based on lens parameters. Questions arise about the implementation details in MATLAB, such as how to map pixel indices from the original image to the transformed image. There is also a discussion about the reversibility of geometric optics and the assumptions regarding the lens system.

Discussion Status

The discussion is ongoing, with participants providing insights and suggestions. Some have offered guidance on using built-in MATLAB functions for image processing, while others are focused on a more analytical approach to the problem. There is recognition of the complexity involved in the implementation, and participants are actively seeking clarification on specific aspects of the task.

Contextual Notes

Participants note the need for clarity regarding the inputs required for the MATLAB code, including the dimensions of the image, object distance, and focal length. There is also mention of assumptions related to the lens type and the nature of the 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 :)
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K