210 likes | 457 Views
Morphology Image Processing. Lab 6. Dilation & Erosion. Function strel. Create morphological str ucturing el ement (STREL), with a variety of shapes and sizes. se = strel ( shape,parameters );. imdilate example with binary. >> bw = imread ('text.png'); >>se = strel ('line',11,90);
E N D
Function strel • Create morphological structuring element (STREL), with a variety of shapes and sizes. se = strel(shape,parameters);
imdilate example with binary >>bw= imread('text.png'); >>se = strel('line',11,90); >>bw2 = imdilate(bw,se); >>imshow(bw), title('Original'), figure, imshow(bw2), title('Dilated');
imdilate example with grayscale >>I = imread('cameraman.tif'); >>se = strel(‘rectangle',[5,5]); >>I2 = imdilate(I,se); >>imshow(I), title('Original'),figure, imshow(I2), title('Dilated');
imerode example with binary >>originalBW= imread('circles.png'); >>se = strel('disk',11); >>erodedBW= imerode(originalBW,se); >>imshow(originalBW), figure, imshow(erodedBW)
imerode example with grayscale >>I = imread('cameraman.tif'); >> se=strel('rectangle',[5,5]); >>I2 = imerode(I,se); >>imshow(I), title('Original'), figure, imshow(I2), title('Eroded‘);
imdilate, imerode Example >> BW = imread('circbw.tif'); >> se=strel('square',3); >> BWD = imdilate(BW,se); >> BWE = imerode(BW,se); >>imshow(BW),figure,imshow(BWD),figure,imshow(BWE);
Combining Dilation & Erosion • The most common combinations of dilation and erosion: • opening. • closing.
imopen Example • This example uses imopen to filter out the smaller objects in an image. >> I = imread('snowflakes.png'); • Create a disk-shaped structuring element with a radius of 5 pixels. >>se = strel('disk',5); • Remove snowflakes having a radius less than 5 pixels by opening it with the disk-shaped structuring element. >> I_opened = imopen(I,se); >>Imshow(I), figure, imshow(I_opened,[]);
imclose example • This example uses imclose to join the circles in the image together by filling in the gaps between them and by smoothening their outer edges. >>originalBW = imread('circles.png'); • Create a disk-shaped structuring element. Use a disk structuring element to preserve the circular nature of the object. Specify a radius of 10 pixels so that the largest gap gets filled. >>se = strel('disk',10); >>closeBW = imclose(originalBW,se); >> imshow(originalBW),figure, imshow(closeBW);
Some morphological operations • There are a variety of morphological operations based on combinations of dilations, erosions, and lookup table operations: • Thickening. • Thinning. • Skeletonization. • These operations can be accomplished by bwmorph function in matlab.
bwmorph • g = bwmorph( i , operation , n) • i the input image(should be black&white) • operation string specifying the operation • n number of times the operation should be repeated. • If n is ommited n=1 • If n = Inf repeat the operation until the image stops changing. (should used with ‘skel’)
Examples BW1 = imread('circbw.tif'); BW2 = bwmorph(BW1,'skel',Inf); imshow(BW1) ,figure, imshow(BW2); BW = imread('circles.png'); BW2 = bwmorph(BW,'skel',Inf); imshow(BW) ,figure, imshow(BW2);