Laplacian of Gaussian Filter in MATLAB Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report The Laplacian filter is used to detect the edges in the images. But it has a disadvantage over the noisy images. It amplifies the noise in the image. Hence, first, we use a Gaussian filter on the noisy image to smoothen it and then subsequently use the Laplacian filter for edge detection. Dealing with a noisy image without a Gaussian Filter:Function used imread( ) is used for image reading.rgb2gray( ) is used to get gray image.conv2( ) is used for convolution.imtool( ) function is used to display the image.Example: Matlab % Read the image in MatLab j=imread("logo.png"); % Convert the image in gray scale. j1=rgb2gray(j); % Generate the noise of size equal to gray image. n=25*randn(size(j1)); % Generate noisy image by adding noise to the grayscale image. j2=n+double(j1); % Display the original color image. imtool(j,[]); % Display the gray image. imtool(j1,[]); % Display the noisy image. imtool(j2,[]); % Define the Laplacian Filter. Lap=[0 -1 0; -1 4 -1; 0 -1 0]; % Convolve the noisy image with Laplacian filter. j3=conv2(j2, Lap, 'same'); % Display the resultant image. imtool(abs(j3), []); Output: Figure: Input Noisy imageFigure: Edge detected imageExplanation of Code: j=imread("logo.png"); This line Reads the image in MatLabExtension of the image can be anything i.e jfif, png, jpg, jpeg, etc.j1=rgb2gray(j); This line converts the image in grayscale, we avoid dealing with colored images.This function takes only one parameter and returns back the gray image.n=25*randn(size(j1)); This line generates the noise of size equal to gray image.Gaussian noise is additive in nature, so added directly using +.j2=n+double(j1); This line Generates noisy images by adding noise to the grayscale image.imtool(j,[]); This line display the original color image.imtool(j1,[]); This line display the gray image.imtool(j2,[]); This line display the noisy image.Lap=[0 -1 0; -1 4 -1; 0 -1 0]; This line of code define the Laplacian Filter.j3=conv2(j2, Lap, 'same'); This line Convolve the noisy image with Laplacian filter.conv2( ) performs the convolution. It takes 3 parameters. 'same' ensures that result has the same size as of input image.imtool(abs(j3), []); This line display the resultant image.Dealing with a noisy image using LOG: Logarithmic transformation of an image is one of the gray-level image transformations. Log transformation of an image means replacing all pixel values, present in the image, with its logarithmic values. Log transformation is used for image enhancement as it expands dark pixels of the image as compared to higher pixel values. Example: Matlab % Read the image in MatLab j=imread("logo.png"); % Convert the image in gray scale. j1=rgb2gray(j); % Generate the noise of size equal to gray image. n=25*randn(size(j1)); % Generate noisy image by adding % noise to the grayscale image. j2=n+double(j1); % Display the original color image. imtool(j,[]); % Display the gray image. imtool(j1,[]); % Display the noisy image. imtool(j2,[]); % Create the gaussian Filter. Gaussian=fspecial('gaussian', 5, 1); % Define the Laplacian Filter. Lap=[0 -1 0; -1 4 -1; 0 -1 0]; % Convolve the noisy image % with Gaussian Filter first. j4=conv2(j2, Gaussian, 'same'); % Convolve the resultant % image with Laplacian filter. j5=conv2(j4, Lap, 'same'); % Display the Gaussian of noisy_image. imtool(j4,[]); % Display the Laplacian of % Gaussian resultant image. imtool(j5,[]); Output: Figure: Input Noisy imageFigure: Edge detected imageExplanation of Code: j=imread("logo.png"); This line Reads the image in MatLabimage is stored in variable j.j1=rgb2gray(j); This line converts the image in grayscale, we avoid dealing with colored images.j1 is the gray image and j is the color image.n=25*randn(size(j1)); This line generates the noise of size equal to gray image.random Gaussian noise is created.j2=n+double(j1); This line Generates noisy images by adding noise to the grayscale image.due to the addictive nature of gaussian noise, it has been directly added to the image.Gaussian=fspecial('gaussian', 5, 1); This line creates the gaussian Filter.5 is the mean and 1 is the variance of the gaussian filter.Lap=[0 -1 0; -1 4 -1; 0 -1 0]; This line of code define the Laplacian Filter.j4=conv2(j2, Gaussian, 'same'); This line Convolves the noisy image with Gaussian Filter first.j5=conv2(j4, Lap, 'same'); This line Convolves the resultant image with Laplacian filter.imtool(j4,[]); This line displays the Gaussian of noisy_image.imtool(j5,[]); This line Displays the Laplacian of Gaussian resultant image. Create Quiz Comment P pintusaini Follow 1 Improve P pintusaini Follow 1 Improve Article Tags : Software Engineering MATLAB image-processing Explore Software Engineering BasicsIntroduction to Software Engineering7 min readSoftware Development Life Cycle (SDLC)6 min readSoftware Quality - Software Engineering5 min readISO/IEC 9126 in Software Engineering4 min readBoehm's Software Quality Model4 min readSoftware Crisis - Software Engineering3 min readSoftware Measurement & MetricesSoftware Measurement and Metrics4 min readPeople Metrics and Process Metrics in Software Engineering7 min readHalsteadâs Software Metrics - Software Engineering10 min readCyclomatic Complexity6 min readFunctional Point (FP) Analysis - Software Engineering8 min readLines of Code (LOC) in Software Engineering4 min readSoftware Development Models & Agile MethodsWaterfall Model - Software Engineering12 min readWhat is Spiral Model in Software Engineering?9 min readPrototyping Model - Software Engineering7 min readIncremental Process Model - Software Engineering6 min readRapid Application Development Model (RAD) - Software Engineering9 min readCoupling and Cohesion - Software Engineering10 min readAgile Software Development - Software Engineering15+ min readSRS & SPMSoftware Requirement Specification (SRS) Format5 min readSoftware Engineering | Quality Characteristics of a good SRS7 min readSoftware Project Management (SPM) - Software Engineering8 min readCOCOMO Model - Software Engineering15+ min readCapability Maturity Model (CMM) - Software Engineering10 min readIntegrating Risk Management in SDLC | Set 18 min readSoftware Maintenance - Software Engineering13 min readTesting & DebuggingWhat is Software Testing?11 min readTypes of Software Testing15+ min readTesting Guidelines - Software Engineering3 min readWhat is Debugging in Software Engineering?11 min readVerification & ValidationVerification and Validation in Software Engineering6 min readRole of Verification and Validation (V&V) in SDLC5 min readRequirements Validation Techniques - Software Engineering8 min readPractice QuestionsTop 50+ Software Engineering Interview Questions and Answers15+ min read Like