INSTITUTE OF TECHNOLOGY, NIRMA UNIVERSITY, AHMEDABAD – 382 481, 08-10 DECEMBER, 2011

1

MEX based Convolution For Image Gradient Filtering And Detection A.Sajan, B. Balaji and A. P. James Indian Institute of Information Technology and Management- Kerala

Abstract—Convolution is an operator that has widespread application in MATLAB based image processing. As opposed to inbuilt MATLAB implementations, we propose an efficient convolution C-MEX oriented MATLAB implementation. We demonstrate the superior performance of our proposed implementation using improved time complexity and memory complexity. I.

INTRODUCTION

M

ATLAB is a general purpose computing environment and an interpreted programing language that is widely used for research and application development. Being an interpreted language, it allows cell based execution which enables rapid testing and prototyping. However, being an interpreted language and the need to preserve generality, a typical MATLAB based implementation of convolution operator that need to use the iteration loops in its program usually would results in longer execution time. Compared to a compiled language like C, the MATLAB programs will take more time to execute conditional statements and loops. To overcome this problem techniques such as vectorization [1] [2] and writing MATLAB Executable (MEX)[3] [4] are employed. MEX functions are compiled programs written in languages such as C, C++ or Fortran and can be called from the MATLAB environment. As MEX functions are already in the machine language, execution time of MATLAB programs are considerably reduced. Convolution is useful operator [5] that has a wide variety of applications in image processing. Two dimensional convolutions is used in digital image processing. In image processing, convolution is one of the main operator that is used for implementing application such as pattern analysis [6], edge detection[7], and smoothing[8]. Any improvement in the performance of the typical MATLAB implementation can significantly improve the performance of the corresponding image processing applications. The primary built in MATLAB function called conv2 is used for two dimensional convolutions. In this paper, we propose a new implementation of conv2 using MEX function in C that has significantly lesser computational complexity with less memory usage.

II.

. CONVOLUTION THEORY

Image pixels can be seen as elements of a matrix, that makes the matrix oriented MATLAB engine a highly useful tool for image processing. The value of each element of the image matrix represents the intensity of that pixel. Two dimensional image convolution involves a moving window matrix operation over an input image. Two dimensional convolution is calculated using the Eq 1.. [

]



[

]

[

]

(1)

where y is the output image, x is the input image, h is the convolution operator and w is the dimension of convolution window. Most widely used convolution windows are Sobel [9], Laplacian [10] and Gausian blur [10], where the Sobel window is used for edge detection, Laplacian window is used to find the regions of rapid intensity changes and Gaussian blur window is used to smooth and remove noise from the image. Figure 1 is the Sobel window and Figure 2 gives the image before and after performing convolution using Sobel window.

Figure 1. The matrices shows horizontal and vertical sobel window weights The window is applied across the input image Fig 2(a) to obtain the resulting sobel edges in horizontal and vertical directions as shown in Fig 2(b) and Fig 2(c). Figure 3 shows the Laplacian window and Fig 4 gives the image before and after performing convolution using the conventional Laplacian window used in testing the convolution operator..

INSTITUTE OF TECHNOLOGY, NIRMA UNIVERSITY, AHMEDABAD – 382 481, 08-10 DECEMBER, 2011 2

Fig. 3. The matrices shows Laplacian window weights

(a)

(a)

(b)

(b)

(c) Figure 2 The image (a) shows the input image, while (b) shows the output of Sobel Horizontal convolution window operation on (a) and (c) shows the output of Sobel Vertical convolution window operation on (a).

(c) Figure 4 The image (a) shows the input image, while (b) shows the output Laplacian window operation on (a) and (c) shows the output of Laplacian convolution window operation with diagonals on (a).

INSTITUTE OF TECHNOLOGY, NIRMA UNIVERSITY, AHMEDABAD – 382 481, 08-10 DECEMBER, 2011

Before giving as the input to the new function, the input image should be converted to gray scale and then to double. The output image also will be of double precision and need to be converted back to uint8. For these conversions we can use built in functions in MATLAB. For converting the RGB image to gray scale image we can use the function rgb2gray. To convert a uint8 image to double we can use the MATLAB function double. Again to convert the output image in to uint8 format we can use the function uint8. Even though the most popular convolution operators are of size 3x3 operators of other sizes can also be used, such as the Gaussian blur window that would require more number of weights. To apply the convolution operation to an image, first we need to append elements to the edges of the input image. The number of rows and columns appended depends up on the size of the operator. For example, if the size of the operator is 3x3 when the central element of the operator is coincided with the top left element of the input image, the top row and left column of the operator will be disengage giving some undesired output. To avoid this situation we need to either append zeros or the mirror image of the elements inside the matrix. In this algorithm we are fixing the size of window to 3x3 and we append one row of zeros on each edge of the input image. This means that if the input image is of size NxM the intermediate image will be of size (N+2)(M+2). Algorithm 1 shows the psedocode of the proposed implementation of appending zeros. Input image (inputimg) is appended with zeros at the edges. Using two nested for loops, first for loop from 0 to number of rows in input image (inimgrows). The second for loop is from 0 to number of columns in the image (inimgcols). If row number or column number or both are 0 or equal to the total number, we save 0 to the intermediate image. _________________________________________________ for i = 0  inimgrows + 1 do for j = 0  inimgcols + 1 do if i == 0 | i == inimgrows + 1 then interimg[i][j]  0 else if j == 0 | j == inimgcols + 1 then interimg[i][j]  0 else interimg[i][j]  inputimg[i - 1][j - 1] end if end for end for Algorithm 1: The pseudocode of the proposed implementation that is used for appending zeros

oprws and opcls are the number of rows and columns in the operator. ____________________________________________ outimgrows  inimgrows + 2 outimgcols  inimgcols + 2 for i = 0  outimgrows do for j = 0  outimgcols do for k = i - (oprws/2)  i + (oprws/2); x = 0  oprws do for l = j - (opcls/2)  i + (opcls/2); y = 0  opcls do outimg[i][j]=outimg[i][j]+(inimg[k][l]*opt[x][y]) end for end for end for end for Algorithm 2: The pseudocode of the proposed implementation of 2D convolution

IV. PERFORMANCE ANALYSIS For analyzing the performance of the newly implemented two dimensional convolution function, experiments are conducted using various window weights. The computational and memory complexity is tested by varying the input image size. Figure 5 shows performance improvement of the proposed implementation in MEX in compairson with that of building MATLAB implementation. It can be seen that with increased image sizes, MATLAB function takes as long as 1 miniute to process a typical sobel window, the proposed implementation hardly takes 1 sec. This significant improvement in the speed shows the optimal use of C-MEX implementation over conventional MATLAB implementation.

60 50 40

Time (s)

III. THE PROPOSED IMPLEMENTATION

3

MATLAB built-in Proposed MEX

30 20 10 0 1e+3

1e+4

1e+5

1e+6

1e+7

Image size log scale (pixels)

Algorithm 2 shows the pseudocode of the proposed C-MEX convolution implementation. Our convolution implementation uses four for loops on the intermediate image. First two for loops are to traverse the intermediate image, outimgrows and outimgcols is the number of rows and columns in the output image respectively. The third and fourth for loop is to traverse the operator window. Further,

Figure 5. A graphical illustration of the improved performance showing considerable reduction in time complexity

TABLE I

INSTITUTE OF TECHNOLOGY, NIRMA UNIVERSITY, AHMEDABAD – 382 481, 08-10 DECEMBER, 2011 4 MEMORY COMPLEXITY ANALYSIS

Table 1 shows the memory complexity comparison of the proposed implementation with the conventional MATLAB implementation. It can be seen that the C MEX implementation uses lesser amount of memory than the MATLAB implementation, which makes the proposed implementation less resource hungry.

V. CONCLUSION In this paper, we presented the possibility and effectiveness of implementing the 2D image convolution using C-MEX MATLAB environment. Using the experiments on varying image sizes with different windows it is clear that the new CMEX implementation has lower time complexity and lower memory requirements compared to a conventional MATLAB program. This considerable improvement in the demonstrated performance is due to the ability of C-MEX to use the C like properties while maintaining the MATLAB variable structure and generality. Further, by applying the proposed convolution implementation considerable performance improvement can be obtained in real-time imaging convolution applications. REFERENCES [1] Aart J. C. Bik,The Software Vectorization Handbook,Intel Press, 2004 [2] Pascal Getreuer,Writing Fast MATLAB Code,MATLAB Central,2004 [3] Pascal Getreuer,Writing MATLAB C/MEX Code,MATLAB Central, 2010 [4] MATLAB - Documentation, http://www.mathworks.in/help/techdoc/ index.html [5] Isidore Isaac Hirschman and David Vernon Widder,The Convolution Transform,Princeton University Press, 1955 [6] V. Cantoni, R. Curetzburg, S. Levialdi, G. Wolf, Recent issues in Pattern Analysis and Recognition, Springer-Verlag, 1989 [7] Theodosios Pavlidis, Algorithms for graphics and image processing, Computer Science Press, 1982 [8] Kenneth R. Castleman Digital Image Processing, Prentice-Hall, 1979 [9] Ernest L. Hall, Computer Image Processing and Recognition, AcademicPress, 1979 [10] Andrew G. Tescher, Applications of digital image processing

MEX based Convolution For Image Gradient Filtering And Detection ...

MEX based Convolution For Image Gradient Filtering And Detection.pdf. MEX based Convolution For Image Gradient Filtering And Detection.pdf. Open. Extract.

622KB Sizes 1 Downloads 247 Views

Recommend Documents

VLSI Friendly Edge Gradient Detection Based Multiple Reference ...
software oriented fast multiple reference frames motion es- timation ... Through analyzing the .... tor, we can accurately analyze the frequency nature of image.

Convolution and Differential Subordination for ...
Mar 2, 2009 - 4Department of Mathematics, University of Delhi, Delhi 110 007, India ..... [13] M. S. Kasi and V. Ravichandran, On starlike functions with ...

Image processing based weed detection in lawn
Image processing based weed detection in lawn. Ukrit Watchareeruetai*,Yoshinori Takeuchi,Tetsuya Matsumoto,Hiroaki Kudo,Noboru Ohnishi. Department ...

A Gradient Based Method for Fully Constrained Least ...
IEEE/SP 15th Workshop on. IEEE, 2009, pp. 729–732. [4] J. Chen, C. Richard, P. Honeine, H. Lantéri, and C. Theys, “Sys- tem identification under non-negativity constraints,” in Proc. of. European Conference on Signal Processing, Aalborg, Denma

Bilattice-based Logical Reasoning for Human Detection.
College Park, MD [email protected]. Abstract. The capacity to robustly detect humans in video is a crit- ical component of automated visual surveillance systems.

A Block-Based Gradient Descent Search Algorithm for ...
is proposed in this paper to perform block motion estimation in video coding. .... shoulder sequences typical in video conferencing. The NTSS adds ... Hence, we call our .... services at p x 64 kbits,” ITU-T Recommendation H.261, Mar. 1993.

Spatial filtering technique to image and measure two ... - OSA Publishing
From an experimental point of view, this is challenging because the near-forward ... −360. ◦ in the polar θ and azimuthal φ angles, respectively, where θ is ...

Vision-based hexagonal image processing based hexagonal image ...
computer vision and pattern Recognition, Las Vegas, June 2006. [8] R.M. Mersereau, “The processing of Hexagonally Sampled Two-. Dimensional Signals,” Proceedings of the IEEE. 67: pp. 930 949, 1979. [9] X. He and W. Jia, “hexagonal structure for

Image Retrieval: Color and Texture Combining Based on Query-Image*
into account a particular query-image without interaction between system and .... groups are: City, Clouds, Coastal landscapes, Contemporary buildings, Fields,.

2009_TRR_Draft_Video-Based Vehicle Detection and Tracking Using ...
2009_TRR_Draft_Video-Based Vehicle Detection and Tracking Using Spatiotemporal Maps.pdf. 2009_TRR_Draft_Video-Based Vehicle Detection and Tracking ...

Content-Based Filtering for Video Sharing Social ...
for video social networks, a very challenging task, not only because the .... The most popular local descriptor, SIFT [7], is both a point of interest detector, .... classification tasks, including pornography detection in images and videos [1][4][10

SNPHarvester: a filtering-based approach for detecting ...
Nov 15, 2008 - Consequently, existing tools can be directly used to detect epistatic interactions. .... (2) Score function: the score function is defined to measure the association between .... smaller in the later stage of our algorithm. • We need

On the gradient inverse weighted filter (image ... - IEEE Xplore
V. CONCLUSION. The quantization effects are analyzed for the systolic structure of a 2-D IIR digital filter proposed by Sid-Ahmed [4]. Expressions are derived for ...

Software-based Packet Filtering
ETH | MPLS | IPv6 | TCP. Flexibility as requirement ... high speed. ▫ Need to support un-modified ...... Internet Measurement Conference 2004, pg. 233-238 ...

VUELO MEX CUN.pdf
KEN SEI FONG 90. Page 2 of 2. VUELO MEX CUN.pdf. VUELO MEX CUN.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying VUELO MEX CUN.pdf.

Method and apparatus for filtering E-mail
Jan 31, 2010 - Clark et a1., PCMAIL: A Distributed Mail System for Per. 6,052,709 A ..... keted as a Software Development Kit (hereinafter “SDK”). This Will ...

Fire Detection Using Image Processing - IJRIT
These techniques can be used to reduce false alarms along with fire detection methods . ... Fire detection system sensors are used to detect occurrence of fire and to make ... A fire is an image can be described by using its color properties.

Fire Detection Using Image Processing - IJRIT
Keywords: Fire detection, Video processing, Edge detection, Color detection, Gray cycle pixel, Fire pixel spreading. 1. Introduction. Fire detection system sensors ...

image-stylization-by-interactive-oil-paint-filtering
... is adaptively smoothed according to the. 3. Page 3 of 16. cag-2016-semmo-article--image-stylization-by-interactive-oil-paint-filtering--authors-version.pdf.

Mex'17 Overview.pdf
Photo: Spring 2016. Page 3 of 16. Mex'17 Overview.pdf. Mex'17 Overview.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Mex'17 Overview.pdf.

Comparison-Based Natural Gradient Optimization in ...
evolutionary algorithm for continuous optimization—derives from the natural gradient framework sketched above when using the family of Gaussian distributions ...

difference of gaussians type neural image filtering with ...
iment explores the edges recovery ability on a natural image. The results show that the ... The spiking neuron network and the neural filter- ing method are ...