However, imaging functions usually take up a lot of memory and computation power due to the complexity of the equations which limit their usage on low memory devices like microcontrollers and single chip boards.
In such case a Linear equation can serve our purpose with a low computation complexity, efficient memory utilisation and faster execution time.
Loading image to find edges :
Reading and displaying image to process |
Edge Finder |
Edges obtained by the difference equation:
Processed image overlayed on original image |
Here is the Edgefinder function, Lines 8-10 are what we are supposed to be looking at :
1: function out=Edgefinder(I)
2: I1=rgb2gray(I); % conversion to grayscale
3: I2=imbinarize(I1); % conversion to binary image,using Otsu's method
4: [m,n]=size(I2); % size of the image
5: out=zeros(size(I2)); % preallocating memory
6: for i=2:m-1
7: for j=2:n-1
8: out(i,j)= (0.25*I2(i+1,j+1))- I2(i+1,j) + (0.25*I2(i+1,j-1)) ...
9: - I2(i,j+1) + 3*I2(i,j) - I2(i,j-1) ...
10: +(0.25*I2(i-1,j+1))- I2(i-1,j) + (0.25*I2(i-1,j-1));
11: end
12: end
13: out=imoverlay(I,out,'red'); % 'I' was preserved for image overlay,not really necessary
14: imshow(out);
15: end
Take a look at the coefficients of the difference equation:
Observe the oscillatory nature of the coefficients: A characteristics of a high pass filter.
Also you may observe that the sum of all coefficients is equal to Zero,
quite intuitive.
It is also evident that this algorithm can find edges at all inclinations so simplicity and efficiency are the key factors here.
Peace out.
Used:
MATLAB 2016a
0 comments:
Post a Comment