dip morphological
DESCRIPTION
TRANSCRIPT
1
Image adjustment
J = IMADJUST(I) maps the values in intensity image I to new values in J such that 1% of data is saturated at low and high intensities of I. This increases the contrast of the output image J.
I = pout.tif
J = imadjust(I);
K = imadjust(I,[0.3 0.7],[])
2
Image adjustment
J = imadjust(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT])
You can use an empty matrix ([ ]) for
[LOW_IN; HIGH_IN]
or for
[LOW_OUT; HIGH_OUT]
to specify the default of [0 1].
J = imadjust(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT],GAMMA)
3
Image adjustmentRGB2 = IMADJUST(RGB1,...) performs the adjustment on each image plane (red, green, and blue) of the RGB image RGB1. As with the colormap adjustment, you can apply unique mappings to each plane.
RGB1 = imread('football.jpg');
RGB2 = imadjust(RGB1,[.2 .3 0; .6 .7 1],[ ])
4
Morphological operationsMorphology is a technique of image processing based on shapes.
The value of each pixel in the output image is based on a comparison of the corresponding pixel in the input image with its neighbors.
By choosing the size and shape of the neighborhood, a morphological operation can be applied that is sensitive to specific shapes in the input image.
Image Processing Toolbox morphological functions in Matlab can be used to perform common image processing tasks, such as contrast enhancement, noise removal, thinning, skeletonization, filling, and segmentation.
5
Neighborhood (pixel connectivity)
4-connected Pixels are connected if their
edges touch. This means that a pair of
adjoining pixels are part of the same object
only if they are both on and are connected
along the horizontal or vertical direction.
8-connected Pixels are connected if their
edges or corners touch. This means that if two
adjoining pixels are on, they are part of the
same object, regardless of whether they are
connected along the horizontal, vertical, or
diagonal direction.
6
Neighborhood (pixel connectivity)
Strel Examples -------- se1 = strel('square',11) % 11-by-11 square se2 = strel('line',10,45) % line, length 10, angle 45 degrees se3 = strel('disk',15) % disk, radius 15 se4 = strel('ball',15,5) % ball, radius 15, height 5
7
Image dilation• Dilation is an operation that “grows” or
“thickens” objects in a binary image.
• The specific manner and extent of this
thickening is controlled by a shape referred to
as a structuring element.
• Matlab “imdilate” function accepts two
primary arguments:
The input image to be processed
(grayscale, binary).
A structuring element object, returned
by the strel function, or a binary matrix
defining the neighborhood of a
structuring element.
A = imread(‘……’); se =strel(‘line’,3,45); B =
imdilate(A,se);
8
13 13 13 13 255 13 13 13 13 13 13 13 255 0 255 13 13 13 13 13 255 255 255 255 255 13 13 13 255 0 0 0 0 0 255 13 255 0 0 0 0 0 0 0 255
Image dilation
13 13 13 255 255 255 13 13 1313 13 255 255 255 255 255 13 1313 255 255 255 255 255 255 255 13255 255 255 0 0 0 255 255 255255 255 0 0 0 0 0 255 255
A =imread(A.tif)Se=strel(‘line’,3,0)
B = imdiltate(A,se)
9
Image dilation
strel('disk',5)
10
Image erosion
Erosion “shrinks” or “thins” objects in a binary image.
As in dilation, the manner and extent of shrinking is controlled by a structuring element.
Matlab “imerode” function accepts two primary arguments:
The input image to be processed (grayscale, binary)
A structuring element object, returned by the strel function, or a binary matrix defining the neighborhood of a structuring element.
A = imread(‘……’); se =strel(‘line’,3,45); B =
imerode(A,se);
11
Image erosionA =imread(‘A.tif’)se=strel(‘line’,3,0)
13 13 13 13 255 13 13 13 1313 13 13 255 0 255 13 13 1313 13 255 255 255 255 255 13 1313 255 0 0 0 0 0 255 13255 0 0 0 0 0 0 0 25513 13 13 13 13 13 13 13 1313 13 13 0 0 0 13 13 1313 13 13 255 255 255 13 13 1313 0 0 0 0 0 0 0 130 0 0 0 0 0 0 0 0
B = imdiltate(A,se)
12
strel('disk',5)
Image erosion
13
Dilation and erosion based functions
Image opening (imopen)
Morphological opening is used to remove
small objects from an image while preserving
the shape and size of larger objects in the
image.
An opening is an erosion followed by a
dilation, using the same structuring element
for both operations.
14
Dilation and erosion based functions
Image opening
15
Dilation and erosion based functions
Image close (imdilate)
Dilates an image and then erodes the dilated
image using the same structuring element for
both operations.
Imopen imcloseCircles.png
16
Morphological functions
Morphological opening operation by calling imopen with the input image, I, and a disk-shaped structuring element with a radius of 15.
The structuring element was created by the strel function.
The morphological opening has the effect of removing objects that cannot completely contain a disk of radius 15.
I = imread(‘rice.tif’);
background = imopen(I,strel('disk',15));
imshow(background)
17
Morphological functions
I2 = imsubtract(I,background);
Now subtract the background image, background, from the original image, I, to create a more uniform background.
18
Morphological functions
imadjust command to increase the contrast in the image. The imadjust function takes an input image and can also take two vectors: [low high] and [bottom top]. The output image is created by mapping the value low in the input image to the value bottom in the output image, mapping the value high in the input image to the value top in the output image, and linearly scaling the values in between.
Adjust the Image Contrast I3 = imadjust(I2, stretchlim(I2), [0 1]);
19
Morphological functions
imadjust with stretchlim(I2) as the second argument. The stretchlim function automatically computes the right [low high] values to make imadjust increase (stretch) the contrast of the image.
20
Binary image
level = graythresh(I3);bw = im2bw(I3,level);
Apply Thresholding to the Image
graythresh to automatically compute an appropriate threshold to use to convert the intensity image to binary. You then called im2bw to perform for thresholding, using the threshold, level, returned by graythresh.