File Exchange

image thumbnail

Slant Edge Script

version (394 KB) by Patrick Granton
This code can be used to measure the pre-sampled MTF of an image.


Updated 03 Sep 2010

View License

This code can be used to measure the pre-sampled MTF of an image, which is a quantity that describes the resolution of linear imaging systems. The code is based on measuring the pre-sample MTF using a precision machined edge that is aligned - with respect to the columns or rows of an image - at an angle between 1-5 degrees.

To learn more about the pre-sampled MTF consult the references at the end of this script.

When you run this script your image containing the edge with appear with the cropping tool. Crop your image to the region containing only the edge. Double-click your cropped area for the script to continue.

A Gaussian fitting tool has been used in this code. You can download this tool on the Matlab central website here:

comments, and suggestions, including areas of improvement may be welcomed.

Cite As

Patrick Granton (2020). Slant Edge Script (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (31)

Hello Patrick Garton,

I am getting a following error, i was unable to solve this issue.Any help would be appreciated.

''Error using roicolor (line 39)
Images with dimensions greater than two are not supported.

Error in MTFscript (line 130)
BW1 = roicolor(image,threshold,max(max(image)));''

If anyone has an idea on how to resolve this issue, please shed some light on the same.

Thank you in Advance.

Rani Al-Senan

Simply, it doesn't work!


How do you generate that dicom file. Code only works for it

Carlos Macias

John Grossmann

I spent an hour or two trying to fix issues with the code. Initially, the issues I found were similar to those reported by others -- interp1 getting duplicate values, and indices exceeding matrix dimensions on line:
array_values_near_edge(ii,:) = (image(i,bound_edge_left_expand:bound_edge_right_expand));

In my case, (which might be unique to my situation) I found that the actual problem was that the code incorrectly determined the *orientation* of my particular edge image. I made the following substitution and then everything worked and all the other issues went away.

%if abs(Angle_radians) > pi/4 % i.e. edge is vertical
% Changed code 10/10/2017
if abs(Angle_radians) < pi/4 % i.e. edge is vertical

I also remembered how important it is to clear variables between runs of code - this avoids some of the array indexing issues.


Lots of issues, code quality insufficient


For repeated value affecting interp1 one can use unique() or find(diff()==0) to remove/locate/manipulate them so that interpolation can go through.


Very sensitive to the input edge images? Always saying the interp1 errors, is it because the interpolation contains too many duplicate values? How to fix it? Thx.

dongri meng

Do you guys have a sample edge image for me to try out? My own image keep getting errors.

Thanks a bunch!

dongri meng

Parimalah Velo

Really helpful. Thank you for sharing.

Louise Morel

Does this script work regardless of wether the image data has been linearized to the deposited-energy ?
I used this script on image data that I know is not linearized relative to the deposited energy and I still get seemingly correct MTF results. How is this possible ?

Harry Chen

I was trying to estimate the relative edge response of a natural image. This code makes my job much easier.


Basim Kakakhel

Is anyone getting the following error

Index exceeds matrix dimensions.

Error in MTFscript (line 230)
array_values_near_edge(ii,:) = (image(i,bound_edge_left_expand:bound_edge_right_expand));

Hai Lai

Patrick Kenny

What type of smoothing would marcelo or rachel reccomend?

Having done some tinkering with wiener and Gaussian filtering of the image files, I still seem to hit errors?

Very well written in all other respects!

Patrick Granton

* Feel free to tinker everyone... perhaps I'll revisit this script and re-write to more common code practices.

Agree with Rachel.This script is not very robust to noise.

I have also found it to crash if the edge is very blurry ie extends over many (50 or so) pixels.

Also, it's always unfortunate and poor practice to name variables the same as built-in functions (e.g "image").

Having said that, with a little tinkering this script is quite nice and will get the job done.


I've been creating my own MTF script, and I wanted to compare my results to yours. However, because my slanted edge must include noise for what I'm testing, I am unable to use your program. The issue happens at line 218, because to find the edge you use interp1, and the variable "strip_cropped" is not monotonic increasing due to the noise in my image. Perhaps you could use a different smoothing method, or use thresholding before finding the subpixel edge. Otherwise, everything else looks like it would work great!

hi there i need the slant wave let for the image and what is the result needed urgently


Hi Patrick,

I have .mat file which containes 200x200 pixels of 50 um size. But the MTFscript does not work!!


Hi Patrick,

I am receiving an error at line 230 about that the index are not integers or logical.
Could you please tell me that what is the problem behind.


Hi Patrick,

thanks a lot. The code worked for me without bug with the exemplary dicom image.


Muhammad Ghani

Hi Patrick, I am receiving an error at line 232 about that the index are not integers or logical.
Could you please tell me that what is the problem behind. I am in desperate help need

Shimon Zerbib

impossible to download the file ...


I am very new to matlab so my question might be silly, but every time I double click on the cropped area, I get the following error:

Error using interp1 (line 257)
The values of X should be distinct.

Error in SlantEdgeScript (line 218)
edge_position_temp = interp1(strip_cropped,temp_y,threshold,'pchip');

I am stuck at this error and can't proceed. Any advice would be greatly appreciated.


i didn't have any problem with the cropping.
I had to modify the way to estimate the variable level.
and I had to modify many things after because the program worked only when the image is not noisy at all.
(I had to modify the way to find the edge position).

Patrick Granton

Pierre, I fixed some issues with the cropping of the image and have made it a GUI for more easy of use. Perhaps this might help you.


doesn't work at all.

lot of error to debug in it.


Excellent code! It helps a lot. Appreciate for this.

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: gaussian curve fit

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!