Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Digital image processing
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Image denoising with mathematical morphology === [[Mathematical morphology]] (MM) is a nonlinear image processing framework that analyzes shapes within images by probing local pixel neighborhoods using a small, predefined function called a [[structuring element]]. In the context of grayscale images, MM is especially useful for denoising through [[Dilation (morphology)|dilation]] and [[Erosion_(morphology)|erosion]]—primitive operators that can be combined to build more complex filters. Suppose we have: * A discrete grayscale image: <math> f = \begin{bmatrix} 45 & 50 & 65 \\ 40 & 60 & 55 \\ 25 & 15 & 5 \end{bmatrix}, \quad f : \Omega \rightarrow \mathbb{R}, \quad \Omega = \{0, 1, 2\}^2, </math> * A structuring element: <math> B = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 1 & 1 \\ 1 & 0 & 3 \end{bmatrix}, \quad B : \mathcal{S} \rightarrow \mathbb{R}, \quad \mathcal{S} = \{-1, 0, 1\}^2. </math> Here, <math>\mathcal{S}</math> defines the neighborhood of relative coordinates <math>(m, n)</math> over which local operations are computed. The values of <math>B(m, n)</math> bias the image during dilation and erosion. ; Dilation : Grayscale dilation is defined as: <math display=block> (f \oplus B)(i, j) = \max_{(m, n) \in \mathcal{S}} \Bigl\{ f(i+m, j+n) + B(m,n) \Bigr\}. </math> :For example, the dilation at position {{math|(1, 1)}} is calculated as: <math> \begin{aligned} (f \oplus B)(1,1) = \max\!\Bigl( &f(0,0)+B(-1,-1), &\;45+1;&\\ &f(1,0)+B( 0,-1), &\;50+2;&\\ &f(2,0)+B( 1,-1), &\;65+1;&\\ &f(0,1)+B(-1, 0), &\;40+2;&\\ &f(1,1)+B( 0, 0), &\;60+1;&\\ &f(2,1)+B( 1, 0), &\;55+1;&\\ &f(0,2)+B(-1, 1), &\;25+1;&\\ &f(1,2)+B( 0, 1), &\;15+0;&\\ &f(2,2)+B( 1, 1) &\;5+3 \Bigr) = 66. \end{aligned} </math> ; Erosion : Grayscale erosion is defined as: <math display=block> (f \ominus B)(i,j) = \min_{(m,n) \in \mathcal{S}} \Bigl\{ f(i+m, j+n) - B(m,n) \Bigr\}. </math> :For example, the erosion at position {{math|(1, 1)}} is calculated as: <math> \begin{aligned} (f \ominus B)(1,1)= \min\!\Bigl( &f(0,0)-B(-1,-1), &\;45-1;&\\ &f(1,0)-B( 0,-1), &\;50-2;&\\ &f(2,0)-B( 1,-1), &\;65-1;&\\ &f(0,1)-B(-1, 0), &\;40-2;&\\ &f(1,1)-B( 0, 0), &\;60-1;&\\ &f(2,1)-B( 1, 0), &\;55-1;&\\ &f(0,2)-B(-1, 1), &\;25-1;&\\ &f(1,2)-B( 0, 1), &\;15-0;&\\ &f(2,2)-B( 1, 1) &\;5-3 \Bigr) =2. \end{aligned} </math> ==== Results ==== After applying dilation to <math>f</math>: <math display=block> \begin{bmatrix} 45 & 50 & 65 \\ 40 & 66 & 55 \\ 25 & 15 & 5 \end{bmatrix} </math> After applying erosion to <math>f</math>: <math display=block> \begin{bmatrix} 45 & 50 & 65 \\ 40 & 2 & 55 \\ 25 & 15 & 5 \end{bmatrix} </math> ==== Opening and Closing ==== MM operations, such as [[Opening (morphology)|opening]] and [[Closing (morphology)|closing]], are composite processes that utilize both dilation and erosion to modify the structure of an image. These operations are particularly useful for tasks such as noise removal, shape smoothing, and object separation. * ''Opening'': This operation is performed by applying erosion to an image first, followed by dilation. The purpose of opening is to remove small objects or noise from the foreground while preserving the overall structure of larger objects. It is especially effective in situations where noise appears as isolated bright pixels or small, disconnected features. For example, applying opening to an image <math>f</math> with a structuring element <math>B</math> would first reduce small details (through erosion) and then restore the main shapes (through dilation). This ensures that unwanted noise is removed without significantly altering the size or shape of larger objects. * ''Closing'': This operation is performed by applying dilation first, followed by erosion. Closing is typically used to fill small holes or gaps within objects and to connect broken parts of the foreground. It works by initially expanding the boundaries of objects (through dilation) and then refining the boundaries (through erosion). For instance, applying closing to the same image <math>f</math> would fill in small gaps within objects, such as connecting breaks in thin lines or closing small holes, while ensuring that the surrounding areas are not significantly affected. Both opening and closing can be visualized as ways of refining the structure of an image: opening simplifies and removes small, unnecessary details, while closing consolidates and connects objects to form more cohesive structures. {| class="wikitable" |- ! Structuring element ! Mask ! Code ! Example |- | '''Original Image''' | None | Use Matlab to read Original image <syntaxhighlight lang="matlab"> original = imread('scene.jpg'); image = rgb2gray(original); [r, c, channel] = size(image); se = logical([1 1 1 ; 1 1 1 ; 1 1 1]); [p, q] = size(se); halfH = floor(p/2); halfW = floor(q/2); time = 3; % denoising 3 times with all method </syntaxhighlight> | [[File:Lotus free.jpg|thumb|Original lotus]] |- |- | '''[[dilation (morphology)|Dilation]]''' | align="center" | <math> \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix} </math> | Use Matlab to dilation <syntaxhighlight lang="matlab"> imwrite(image, "scene_dil.jpg") extractmax = zeros(size(image), class(image)); for i = 1 : time dil_image = imread('scene_dil.jpg'); for col = (halfW + 1): (c - halfW) for row = (halfH + 1) : (r - halfH) dpointD = row - halfH; dpointU = row + halfH; dpointL = col - halfW; dpointR = col + halfW; dneighbor = dil_image(dpointD:dpointU, dpointL:dpointR); filter = dneighbor(se); extractmax(row, col) = max(filter); end end imwrite(extractmax, "scene_dil.jpg"); end </syntaxhighlight> | [[File:Lotus free dil.jpg|thumb|Denoising picture with dilation method]] |- | '''[[erosion (morphology)|Erosion]]''' | align="center" | <math> \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix} </math> | Use Matlab to erosion <syntaxhighlight lang="matlab"> imwrite(image, 'scene_ero.jpg'); extractmin = zeros(size(image), class(image)); for i = 1: time ero_image = imread('scene_ero.jpg'); for col = (halfW + 1): (c - halfW) for row = (halfH +1): (r -halfH) pointDown = row-halfH; pointUp = row+halfH; pointLeft = col-halfW; pointRight = col+halfW; neighbor = ero_image(pointDown:pointUp,pointLeft:pointRight); filter = neighbor(se); extractmin(row, col) = min(filter); end end imwrite(extractmin, "scene_ero.jpg"); end </syntaxhighlight> | [[File:Lotus free erosion.jpg|thumb|]] |- |- | '''[[opening (morphology)|Opening]]''' | align="center" | <math> \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix} </math> | Use Matlab to Opening <syntaxhighlight lang="matlab"> imwrite(extractmin, "scene_opening.jpg") extractopen = zeros(size(image), class(image)); for i = 1 : time dil_image = imread('scene_opening.jpg'); for col = (halfW + 1): (c - halfW) for row = (halfH + 1) : (r - halfH) dpointD = row - halfH; dpointU = row + halfH; dpointL = col - halfW; dpointR = col + halfW; dneighbor = dil_image(dpointD:dpointU, dpointL:dpointR); filter = dneighbor(se); extractopen(row, col) = max(filter); end end imwrite(extractopen, "scene_opening.jpg"); end </syntaxhighlight> | [[File:Lotus free opening.jpg|thumb|]] |- | '''[[closing (morphology)|Closing]]''' | align="center" | <math> \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix} </math> | Use Matlab to Closing <syntaxhighlight lang="matlab"> imwrite(extractmax, "scene_closing.jpg") extractclose = zeros(size(image), class(image)); for i = 1 : time ero_image = imread('scene_closing.jpg'); for col = (halfW + 1): (c - halfW) for row = (halfH + 1) : (r - halfH) dpointD = row - halfH; dpointU = row + halfH; dpointL = col - halfW; dpointR = col + halfW; dneighbor = ero_image(dpointD:dpointU, dpointL:dpointR); filter = dneighbor(se); extractclose(row, col) = min(filter); end end imwrite(extractclose, "scene_closing.jpg"); end </syntaxhighlight> | [[File:Lotus free closing.jpg|thumb|Denoising picture with closing method]] |- |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)