Image Processing Reference
In-Depth Information
None of these approaches is optimal. The results here use the first option and set border
pixels to black. Note that in many applications the object of interest is imaged centrally or,
at least, imaged within the picture. As such, the border information is of little consequence
to the remainder of the process. Here, the border points are set to black, by starting
functions with a zero function which sets all the points in the picture initially to black (0).
The Matlab implementation of a general template convolution operator convolve is
given in Code 3.5 . This function accepts, as arguments, the picture image and the template
to be convolved with it, template . The result of template convolution is a picture
convolved . The operator first initialises the temporary image temp to black (zero
brightness levels). Then the size of the template is evaluated. These give the range of
function convolved=convolve(image,template)
%New image point brightness convolution of template with image
%Usage: [new image]=convolve(image,template of point values)
%Parameters: image-array of points
% template-array of weighting coefficients
%Author: Mark S. Nixon
%get image dimensions
[irows,icols]=size(image);
%get template dimensions
[trows,tcols]=size(template);
%set a temporary image to black
temp(1:irows,1:icols)=0;
%half of template rows is
trhalf=floor(trows/2);
%half of template cols is
tchalf=floor(tcols/2);
%then convolve the template
for x=trhalf+1:icols-trhalf %address all columns except border
for y=tchalf+1:irows-tchalf %address all rows except border
sum=0;
for iwin=1:trows %address template columns
for jwin=1:tcols %address template rows
sum=sum+image(y+jwin-tchalf-1,x+iwin-trhalf-1)*
template(jwin,iwin);
end
end
temp(y,x)=sum;
end
end
%finally, normalise the image
convolved=normalise(temp);
Code 3.5
Template convolution operator
Search WWH ::




Custom Search