Re: A "slanted edge" analysis program
- From: "Bart van der Wolf" <bvdwolf@xxxxxxx>
- Date: Tue, 27 Sep 2005 20:12:33 +0200
"Lorenzo J. Lucchini" <ljlbox@xxxxxxxxxx> wrote in message news:5KYZe.49331$nT3.33343@xxxxxxxxxxxxxxxxxxxxxxxx
SNIP
and I've created a SourceForge project at http://sourceforge.net/projects/slantededge/
with sourcecode in the CVS.
I'll explain briefly what the program does and in what order it does it, as the source is not very well commented, er, at the moment.
I've added a few comments, hopefully it will help to better understand the reasons behind the steps.
1) Read in an RGB image 2) We work with vertical edges, so rotate the image if needed
This is only done to simplify the calculations. All that's required is to get the image data in a uniform orientation, so all subsequent subroutines will know what to expect (which avoids rechecking assumptions).
3) Besides the "red", "blue" and "green" channels, create a "gray" channel that is the average of the other three
The image code values should be linarized at this stage, so film/sensor non-linearity and gamma adjustments can't influence the calculations.
It is customary to use a different weighting than the (R+G+B)/3 average. The ISO suggests the calculation of a luminance channel, so a ratio of approx. 3R:6G:1B is closer to what we experience as luminance.
4) Normalize the image, so that 0.5% of the pixels clip down, and 0.5% clip up
I think that, especially on non-linear image codes, this will influence the MTF results, because the contrast is expanded. On a perfectly symmetrical brightness distribution its effect will be small, but the possibility of clipping in later stages should be avoided. Also a check for at least 20% edge modulation should be made, in order to avoid a too low input S/N ratio.
It is however perfectly normal to normalize the ESF output to a range between 0.0 and 1.0, and later to normalize the SFR/MTF to 1.0 (100%) at zero spatial frequency.
5) For each line in the image, find the point with the max adjacent pixel difference (should be the edge)
Not necessarily, that is just the maximum gradient and that need not be the same as the edge.
The ISO suggests to combine this with with your step 9, and determine the centroid of the LSF (by calculating the discrete derivative of the ESF). The centroids can be used for regression.
The derivative suggested by the ISO is:
"for each line of pixels perpendicular to the edge, the edge is differentiated using the discrete derivative "-0,5 ; +0,5", meaning that the derivative value for pixel "X" is equal to -1/2 times the value of the pixel immediately to the left, plus 1/2 times the value of the pixel to the right".
They then specify something different in their centroid formula, but perhaps they changed that in the official standard.
There is another calculation method possible. That calculation is done in the orthogonal direction, so almost along the edge instead of across the edge.
6) By doing a least squares regression on those points, find a straight line that ought to best represent the edge
7) Associate a distance from that line to each pixel in the image.
The ISO method shifts each row of the ESF by the calculated amount from the regression, but uses quarter pixel bins. This produces a 4x oversampling per pixel position.
The function PixelValue(Distance) approximates the edge spread function.
8) Use "some kind" of local regression to create a uniformly-spaced version of the ESF, from the data described above.
9) Derive the line spread function from the edge spread function: LSF(i)=ESF(i+1)-ESF(i)
See earlier remark, and provisions need to be made to detect multiple maxima (caused by noise/graininess).
10) Apply a Hanning window to the LSF
That is needed to reduce noise and the discontinuity at the borders of the LSF.
11) Take the discrete Fourier transform or the resulting data
And take the Modulus, and normalize.
Note that, at the moment, the input image must be an RGB, 8-bit ASCII ("plain") PPM file. These can be created using "*topnm" and "pnmtoplainpnm" from the NetPBM suite, or by using the GIMP.
Type --help for some uncomprehensive help.
;-) Room for improvement ...
I have a lot of doubts and questions to ask, but first I'd like to get an overall look at the program by someone competent, to find out what I have done *badly* wrong (something awful is bound to be there).
I'll have to study the source code before I can comment.
Please keep in mind that I knew nothing about regressions, spread functions or Fourier transforms two weeks ago -- and I suppose I don't know that much more now.
Isn't that the fun of programming, it forces you to describe the principles in detail. Learning new stuff is inevitable.
I just read some Internet source and implemented what I thought they meant.
With the program (to be) available to the public, the chance of helping hands increases. The source code you have probably read will give a good start. As always, the devil is in the details, but that can be overcome.
Bart
.
- Follow-Ups:
- Re: A "slanted edge" analysis program
- From: Lorenzo J. Lucchini
- Re: A "slanted edge" analysis program
- References:
- A "slanted edge" analysis program
- From: Lorenzo J. Lucchini
- A "slanted edge" analysis program
- Prev by Date: Re: Cleaning scnner question
- Next by Date: Re: A "slanted edge" analysis program
- Previous by thread: Re: A "slanted edge" analysis program
- Next by thread: Re: A "slanted edge" analysis program
- Index(es):
Relevant Pages
|