Image Formation Fundamentals: CS308 Data Structures
Image Formation Fundamentals: CS308 Data Structures
Image Formation Fundamentals: CS308 Data Structures
fX
x
Z
fY
y
Z
Camera optics
• In practice, the aperture must be larger to admit more light.
• Lenses are placed to in the aperture to focus the bundle of rays
from each scene point onto the corresponding point in the image
plane
Image formation (cont’d)
• Optical parameters of the lens
– lens type
– focal length
– field of view
• Photometric parameters
– type, intensity, and direction of illumination
– reflectance properties of the viewed surfaces
• Geometric parameters
– type of projections
– position and orientation of camera in space
– perspective distortions introduced by the imaging process
Image distortion
What is light?
private:
int N, M, Q; //N: # rows, M: # columns
int **pixelValue;
};
An example - Threshold.cpp
void readImageHeader(char[], int&, int&, int&, bool&);
void readImage(char[], ImageType&);
void writeImage(char[], ImageType&);
// read image
readImage(argv[1], image);
Threshold.cpp (cont’d)
cout << "Enter threshold: ";
cin >> thresh;
// threshold image
// write image
writeImage(argv[2], image);
}
Reading/Writing PGM images
Writing a PGM image to a file
void writeImage(char fname[], ImageType& image)
int N, M, Q;
unsigned char *charImage;
ofstream ofp;
image.getImageInfo(N, M, Q);
int val;
if (ofp.fail()) {
cout << "Can't write image " << fname << endl;
exit(0);
}
ofp.close();
}
Reading a PGM image from a file
void readImage(char fname[], ImageType& image)
{
int i, j;
int N, M, Q;
unsigned char *charImage;
char header [100], *ptr;
ifstream ifp;
ifp.open(fname, ios::in);
if (!ifp) {
cout << "Can't read image: " << fname << endl;
exit(1);
}
// read header
ifp.getline(header,100,'\n');
if ( (header[0]!=80) || /* 'P' */
(header[1]!=53) ) { /* '5' */
cout << "Image " << fname << " is not PGM" << endl;
exit(1);
}
Reading a PGM image …. (cont’d)
ifp.getline(header,100,'\n');
while(header[0]=='#')
ifp.getline(header,100,'\n');
M=strtol(header,&ptr,0);
N=atoi(ptr);
ifp.getline(header,100,'\n');
Q=strtol(header,&ptr,0);
if (ifp.fail()) {
cout << "Image " << fname << " has wrong size" << endl;
exit(1);
}
ifp.close();
Reading a PGM image…(cont’d)
//
// Convert the unsigned characters to integers
//
int val;
}
How do I “see” images on the computer?