Set operations A=imread(‘utk.tif’); B=imread(‘gt.tif’); Ex#1: Perform (a) Complement of A (b) Union of A and B (c) Intersection of A and B (d) Set difference A-B Hint: help & for other logical operators
Dilation Ex. Ex. Dilate broken-txt.tif with b a=zeros(10,10); a(4:7, 4:7)=ones(4,4); b=[0 1 0; 1 1 1; 0 1 0]; c=imdilate(a,b);
Dilation (cont.) t=imread(‘text.tif’); sq=ones(3,3); td=imdilate(t,sq); Exercise#2: Dilate twice Dilate 3 times Dilate once with diamond structuring element Dilate once with 5x5 square 0 1 0 1 1 1
Erode Command: imerode Ex#3: generate the following images original image erosion dilation small-squares.tif 13x13 square
Boundary detection rice=imread(‘rice.tif’); r=rice > 110; A-(A B) Exercise#4: produce Internal boundary: A-(A B) - External boundary: (A B)-A + Morphological gradient: (A B)-(A B) + -
Opening and closing I=imread('shapes.tif'); b=ones(20, 20); f=imopen(I, b); g=imclose(I, b);
Opening and closing (cont.) Ex#5: Generate the following images open close noisy-fingerprint.tif
Hit-or-miss transformation 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 1 1 1 1 0 0 0 0 0 0; 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0; 0 0 1 0 0 1 0 0 0 0 0 0 1 1 1 0; 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Ex6: Generate the right images
Region filling Sample code: function out=regfill(im, pos, kernel) current=zeros(size(im)); last=zeros(size(im)); last(pos(1), pos(2))=1; current=imdilate(last, kernel) & ~im; while any(current(:) ~= last(:)), last=current; end; out=current; Exercise#7: Perform boundary detection to nicework.tif, then apply region filling to it, modify regfill using getpts