Morphological operators
1. Basic erosion and dilation
1.1 Understanding of the basic Dilation operator
Understand the code of the dilation operator that is provided in the method dilateBasic() of the file Code.java.
Guess the structuring element from the Java code and fill in the report.
Describe how to use the plugin to determine the structuring element even if you don't have access to the source code.
The name of the plugin is Basic Dilate.
1.2 Code the Erosion operator
Write a method erodeBasic() that implements the erosion operator with the structuring element found in the question 1.1.
The name of the plugin is Basic Erode.
Test your code on the images mire.tif and nucleus.tif.
|
Programming note |
Duplicate an image |
image2 = image1.duplicate(); |
image1 → image2 |
Addition of images |
out.add(im1, im2); |
im1 + im2 → out |
Subtraction of images |
out.subtract(im1, im2); |
im1 - im2 → out |
Define the largest positive double value |
double max = Double.MAX_VALUE; |
Define the smallest negative double value |
double min = -Double.MAX_VALUE; |
Sort an array |
double arr[] = new double[count]; Arrays.sort(arr); |
|
2. Morphological operators with a user-defined structuring element
We want to implement the morphological operators for the "Block" and the "Diamond" structuring elements.
2.1 Creation of structuring elements
A structuring element is a 2D boolean array containing true in the gray cells and false in the white cells.
Code the methods block(n) and diamond(n) to build the "Block" and "Diamond" structuring elements of size n.
We assume that the size n is always odd and greater than 2.
The provided method show(boolean se[][]) can display the structuring element as an image for you to check. |
|
2.2 Implementation of the morphological operators
The task is to implement the following operators for the "Block" and the "Diamond" structuring elements.
The user chooses the shape and the size of the structuring element through the dialog box. Test your code on the images "mire.tif" and "nucleus.tif".
Operator |
Method in Code.java |
Name of the plugin |
Dilation | dilate() | Dilate |
Erosion | erode() | Erode |
Open | open() | Open |
Close | close() | Close |
Gradient | gradient() | Gradient |
Top Hat Dark | topHatDark() | Top Hat Dark |
Top Hat Bright | topHatBright() | Top Hat Bright |
Median† | median() | Median |
†The useful method Arrays.sort() can sort an array
|
Dialog box |
2.3 Understanding of the morphological operators
Use the Teacher plugins if you don't succeed in coding your own methods in Question 2.2. Fill in the report:
- Compare the results of 1 x Dilate(DIAMOND, 5) and 1 x Dilate(BLOCK, 5) on "notes.tif". Are they the same ? Why?
- Compare the results of 3 x Erode(BLOCK, 3) and 1 x Erode(BLOCK, 7) on "notes.tif". Are they the same ? Why?
- Compare the results of 3 x Close(BLOCK, 3) and 1 x Close(BLOCK, 3) on "notes.tif". Are they the same ? Why?
- Compare the Gradient(DIAMOND, 3) and the "Find Edges" command of ImageJ on "notes.tif". Comment on the functionality.
- Apply the Median(BLOCK, 3) on the images speaker.tif and nucleus.tif. Comment.
3. Applications
3.1 Detect black note heads
Propose an algorithm to detect only the black heads of the notes based on morphological operators and a final thresholding.
The goal is to replace the black heads in the image "notes.tif" by small squares (e.g. 7x7 pixels) and to remove everything else.
Save the result image and briefly describe your algorithm in "report.doc".
| Original image |
Desired result |
3.2 Mouse tracking
Based on morphological operators, propose an algorithm to segment the body of the mouse without the tail. Apply your algorithm to the
sequence "mouse-tracking.tif". To obtain the trajectory of the mouse, compute the center of gravity of the body of the mouse
using the ImageJ's command "Analyze Particles" (check the "Center of Mass" in the Set Measurements dialog of ImageJ). Fill in "report.doc".
| |
3.3 Improve weather
Propose an algorithm and write the method removeRain() to remove the rain on "rain.tif", based on morphological operators.
Use the plugin Remove Rain to call this method.
Hint: Design an appropriate structuring element.
Save the result image in "report.doc".
| |
|