Projects
Project 3: Springies
Assignment handout (v.3 -- updated questions) | Framework Code | Starred Problem handout
FAQ:
- No updates yet!
Project 2: Splines
Assignment handout (v.2) Framework Code (v.2)
FAQ:
- New! Q. What should I do if I am at the end of matching a scribble and I don't have enough points
left in P to avoid an underdetermined system (i.e. I only have one or two points left in the input, but I can't fit them in the
previous segment without violating the error tolerance)?
A.One thing you can try is to pull out a few points from the previous segment, but this may result in a cascade effect if there were only a few points in the previous segment as well. Another alternative is to introduce additional input points inbetween your remaining input, evenly spaced along the lines connecting neighboring input points. So, for instance, if you have one extra point you need to find a segment for, add in three points evenly spaced on the line segment between the extra point and the previous point in the input, then perform your LS fit.
- Q. When I am editing a regular, non-continuous Bezier curve (using constrainSplinePoint),
only one control point ever seems to move. Is this correct behavior?
A. If you formulated your system like in section, then yes. Solving the underconstrained system in MATLAB corresponds to finding the minimal norm solution that satisfies the equation, and it can be shown that the minimal norm solution will only move one point.
- Q. When I am editing a continuous Bezier curve (using constrainSplinePoint), it seems
like if I slide the second control point along its constrained line past the first control
point (so that it is on the same side of the line as the third control point in the previous
segment) then the curve becomes discontinuous. A similar thing happens with the third/fourth
control points. Do I need to handle these cases?
A. You don't have to worry about preventing this case. Some curve editors will automatically flip the control point in the other segment across the line in this situation, but the interface to your code does not allow this to occur. The important feature to preserve is the fact that the points are constrained to move along a particular line segment.
- Q. What happens if a line segment slices a spline curve at exactly t=0 or t=1?
Do we have to special case it?
A. You can assume that it doesn't happen (even though there are certain ways of making it happen repeatably). There is currently no way to tell the GUI that it should not glue neighboring segments together (such as when the split is precisely at the boundary of the curve). In general, this is an example of how one needs to always be prepared for floating point numbers being equal.
- Q. What error measure should I use for scribble?
A. In some sense, you would like to use the least squares residual, since that is what you are using to find the spline curve. One issue with this approach, though, is that as more points are added into the fit, the error of each point needs to decrease so that the total sum of squares of error is less than the fixed error tolerance. One way to correct this is to divide your least squares error by the number of points in your fit, producing a mean error estimate and ensuring in some sense that the average point is within the error tolerance. An alternative approach is to use the maximal distance of a point from the curve as your error measure; in this case you are then ensuring that all points are within the specified error tolerance.
Project 1: Color calibration
RGB values for the Color Checker: Color Checker RGB (load into MATLAB with the command load -ascii MCC_RGB.mat)
Additional notes: Image alignment | Local linear interpolation (v. 2 -- typo corrected)
Test data: Raw camera image (with MCC) | Raw camera image (no MCC)
FAQ:
- Q. I'm not sure how to use interp3(),
and MATLAB's documentation confused me. What am I doing wrong?
A. MATLAB in general has some pretty good documentation. Sadly, that documentation is pretty sparse on interp3().
The input variables X,Y,Z, and V should all in reality be 3-dimensional arrays of the same size. For instance, suppose you have 3 input variables x, y, z and some function f(x, y, z), and you want to evaluate it on an evenly spaced 3D grid. Then you would create 4 3D grids (i.e. 3D arrays), where the first one would tell you what the value of x was at each gridpoint, the second the value of y at each gridpoint, the third the value of z, and the fourth the value of the actual function at that gridpoint. 3D arrays in MATLAB are just like matrices and vectors, except they have 3 indices (instead of two), so for instance you can create a 6x6x6 3D array with zeros(6, 6, 6), and access the (2, 1, 3) element of the 3D array v with v(2, 1, 3).
For X,Y,Z, you can form these matrices programmatically or you can use the meshgrid() function, which takes three vectors of input (the sample points of each of your three dimensions) and produces suitable X,Y,Z matrices. In fact, if you give interp3() vectors for X,Y, and Z it will feed them to meshgrid() to get the 3D arrays it needs. As for creating the appropriate V matrix from your data, if you've structured your n x 3 matrix in a particular way you may be able to use reshape() in order to get it into the proper form. A couple of caveats: you may find that depending on how you convert your data into V, you may need to rethink which of your input variables (i.e. r, g, b) is X, which is Y, and which is Z -- look at the output of meshgrid() if you get confused. Also, interp3() only supports interpolating scalar functions -- if you want to interpolate [c,m,y] = f(r, g, b), then you need to make three calls to interp3, one for each of the output arguments.
To see an example of the type of input expected, type 'doc interp3' and run the example code at the bottom to get a feel of what it expects. You can also write your own function to do the linear interpolation if you want.
- Q. For printer calibration, MATLAB is complaining that my least squares systems
are very close to singular or badly scaled. How can I fix this?
A. You might see this in a few places, particularly when you are right on the boundary of the CMY gamut. If you look at your printout of your CMY points, you will see some squares that look nearly identical (some of the reddish-oranges, for instance). When you do your lookup, although you may grab 4 or more points to try and ensure that your system is not underdetermined, some of those RGB values may be nearly identical and so MATLAB will complain. A truly excellent solution may attempt to detect and handle this situation automatically, but it's okay if it happens occasionally.
- Q. How can I test to see if I am producing reasonable values for the printer
calibration?
A. One test is to feed in the RGB values you computed from your scanned CMY grid and see if you get CMY values that are reasonably close to the original CMY gridpoints. For instance, if (c, m, y) was a CMY color in your original grid of points, and you determined that it was measured in RGB as (r, g, b), then you can try feeding (r, g, b) to your computed printer calibration and see if you get a CMY color close to (c, m, y).
- Q. My results for the printer don't look great, but I think they are correct.
Is there anything I can do to improve them?
A. One approach is to weight each point that you gather by some function that makes nearby points count for more than far away points. For instance, if for a given grid point you've used a lookup radius of 0.1 and found 8 nearby points, each with distance di, then you can weight the relative importance of each point by (1 - di / 0.1) ^ 3. Note that this function is 1 if the distance is 0, and rapidly falls off to 0 as the point approaches our maximal lookup radius. In order to apply the weights in our least squares fit, scale each row by the weight. Note that you should scale the row on both the left and right hand side of the system by the same amount.
Another approach is to increase the number of points in your CMY grid -- moving least squares works best when there is a dense sampling of points. Rather than increase the number of points on your printout, though, you can generate a finer resolution CMY grid in MATLAB and then linearly interpolate the RGB values of your printout on this finer grid. For instance, if you have already computed the RGB values for a CMY grid of size 6 x 6 x 6, you can generate a new CMY grid of size 26 x 26 x 26 and linearly interpolate the RGB values on the new grid from the RGB values on the coarser grid. You can then use this finer sampling of points as input to computing the RGB grid.
Finally, you can increase the resolution of your RGB grid. The size of your CMY grid and the size of your RGB grid do not have to be equal, and making a finer RGB grid can result in some additional detail.
- Q. What should my printer results look like?
A. Here is an RGB grid and the corresponding CMY values for each point as seen by Photoshop (using Photoshop's CMYK to RGB conversion algorithm). Note that the RGB grid shows you how the RGB space was mapped to the image, while the CMY values tells you what the CMY was at each point on the grid. This image was generated using both of the improvements discussed in the question above, and a lookup radius of 0.1. The CMY printout was 6 x 6 x 6, which was then interpolated over a 26 x 26 x 26 grid. The RGB grid that was generated used a resolution of 40 x 40 x 40. Out of gamut points are displayed as white. Note that the top left corner is in fact (1, 1, 1) in CMY, but is washed out slightly by Photoshop's CMY conversion algorithm.
Note: If you try to view a TIFF file by double clicking on it, you will probably be viewing it in Windows Picture and Fax Viewer, which has a fairly poor algorithm for displaying CMYK images. Here is a screenshot of the above CMY values as viewed in that application
- Q. What should be in my writeup? How are you going to test this?
A. Your writeup should take on the task of convincing us that your solution is correct. For instance, you can discuss how you tested your calibrations to verify their accuracy. You should also discuss some way of measuring the error in your solution, where it might have come from, and descriptive plots of the error. Your code should be there as evidence of the work you did and to back up your statements, but you should not be worried that the interface to the code is ill-defined for automatic testing. Your code should be well-commented and easy to follow, though; it should be self-evident what each piece of code you submit is doing.
Ideally, your writeup will be in PDF format, since the formatting is consistent across multiple platforms. If PDF is not an option for whatever reason, Word DOC files are also acceptable (with the understanding that they may not display identically on our machines)