$30
. For skeletonization, the basic idea is to remove any pixel on the boundary of the foreground which has more than one foreground neighbor. But this needs to be done in such a way that removing the pixel does not split the connected component, to which the pixel belongs, into two.
Consider the following structuring elements:
Here, ∗ stands for don’t care; whether image pixel underneath is foreground or background. In morphological operations, note that a structuring element whose origin is placed on a pixel will be compared to the corresponding neighborhood and if they match, then the corresponding pixel in the output image is usually set to foreground.
In this case, suppose that we change the rule and set the pixel to background (i.e. to value 0). Suppose S(θ) stands for structuring element S rotated by angle θ degrees.
I1 −→S I2 denote that I2 is a result of applying structuring element S on image I1. A single skeletonization pass is defined as:
S1(0) S2(0) S1(90) S2(90) S1(180) S2(180) S1(270) S2(270)
I1 −−−→ I2 −−−→ I3 −−−→ I4 −−−→ I5 −−−−→ I6 −−−−→ I7 −−−−→ I8 −−−−→ I9
To obtain the skeleton, the operations defined by the above skeletonization pass need to be repeated until a particular structuring element pass leaves the image unchanged.
1. Write code for the above skeletonization process and display the computed skeleton for the image thumb print.jpg. Note that the image will need to be binarized first ! You can use cv2.threshold or any other inbuilt function for binarization.
2. Explain the role of structuring elements S1,S2.
3. By analyzing the outputs at the end of each skeletonization pass, explain why multiple passes are/may be required.
4. Try out the skeletonization algorithm described above on dragon.jpg, butterfly.jpg and keyhole.jpg and comment on what you observe.
2. Find the organs of interest in the provided CT image kidney.jpg. The organs of interest are as shown below.
(a) Original kidney image (b) Isolated organs
Hint: Use thresholding and morphological operations.
Note: You need to implement the connected components for this question.
3. Read in the binary image coins.jpg and write a script which uses the image as input and outputs a new image containing
1. only the coins touching the boundary of the image
2. only the coins which overlap with each other
3. only non-overlapping coins
Hint: You can use the previously implemented connected components function for this question.
4. Read in the binary image objects.png and write a script which uses the image as input and uses morphological and logical operations to answer the questions below.
1. How many objects have one or more holes?
2. How many square objects are in the image?
3. Identify the square objects that have holes.
4. Identify the circular objects that have no holes
Hint: You can use the previously implemented connected components function for this question.
5. The questions below pertain to connected components. In the questions below, assume 8-connectivity.
1. The image colourful text.png contains text characters in five different colors. Write a script which takes the image as input and outputs the number of components for each of the five colors. Note that the components may be non-letters (e.g. . and |).
2. For telugu.jpeg and tamil.jpeg write a script which produces a binary image containing
(a) Only those letters that enclose one empty region (e.g. examples of English letters containing a single empty region are - o,e,a)
(b) only those letters that enclose two empty regions (e.g. example letter from English - g, B)
6. Given the label map of a scene,
1. How do you upscale the label map by factor k?
2. How do you rotate the label map by θ?
The before/after label maps should look meaningful when visualized using label2rgb.
7. Image rotation:
1. Write a function rotImage which rotates an input image about its center and takes the following parameters:
• Input image
• Angle of rotation in degrees
• A boolean parameter, retain, such that,
– If it is true, you retain the original dimensions of the input image and crop out all pixels that map to locations outside of these dimensions.
– If it is false, your output dimensions should accommodate the entire image (without cropping) after rotation.
2. Show outputs of a rectangular image of your choice with angle 30◦, 45◦, 90◦ and 2 other angles of your choice.