Edge finding algorithm using gradient map and local grayscale average

3 views (last 30 days)
Hey guys!
Hope someone can help me with this problem. I want to detect vertical edges without using the edge() function in order to emulate a commercial software package for image analysis.
The idea is as follows (if I understood the manual of the mentioned software):
- filter (smooth) the image using an average filter with a given height (i.e. 11 px) - calculate the gradient of the image and find maxima of the slopes - calculate the intersection of the slopes with a local image graylevel average (baseline), taken to be a 4pixel mean value from the point of maximum gradient.
I am unfortunately not sure how I can implement the last part. If I understood correctly the edge function usually looks for a maximum in the gradient (which is not where I would like to have my edge defined, within an offset of up to 4 px).
So far I managed to get the gradient within 7px, I can detect the local maxima for the gradient (imregionalmax); but from here on I am pretty unsure how to proceed!
Any help is very much appreciated! (But thank you anyway for reading the long text ;) )
PS: I am not so sure about the smoothing mechanism the commercial program uses; the manual says, that 'every line is approximated by an odd number of lines average', not sure if my average filter accomplishes that!
% Read image and smooth it
close all;
clear all;
% Parameters Start
meas_pnts=32;
sum_lines=32;
method='linear';
smoothing=11;
diff_num=7;
baseline_area=4;
edge_thres=0.5; %*100%
% Parameters End
% Load the image and check if it is graylevel
img_in=imread(load_im());
if ndims(img_in)>2
fprintf('This is no gray scale image!\nNow exiting!\n')
break;
end
img_height=size(img_in,1);
img_width=size(img_in,2);
% Smoothing the image by averaging over SUM_LINES lines
stepsize=ceil(img_height/sum_lines);
% Create filter and filter the image
h = fspecial('average', [1 stepsize])
img_filtered = imfilter(img_in,h,'replicate');
% Compare the images visually
figure, subplot(1,2,1), imshow(img_in), title('Original grayscale SEM image')
subplot(1,2,2), imshow(img_filtered), title(['Image filtered with a linear ' num2str(sum_lines) ' averaging filter'])
% Calculate the gradient of the image and highlight maxima
img_gradx=gradient(double(img_filtered),diff_num);
img_gradx_max=imregionalmax(img_gradx);
figure, subplot(1,2,1), imshow(img_gradx),title(['Gradient map of the filtered image. Differential approximation by ' num2str(diff_num) ' pixels']);
subplot(1,2,2), imshow(img_gradx_max), title('Local maxima of the image gradient')

Answers (0)

Community Treasure Hunt

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

Start Hunting!