- In image matting, trimap estimates foreground from background by inscribing unknown region
- Mathematically, an image can be represented by the following equation:
On the other hand,
- Generate a trimap (foreground, background, and unknown regions) from an input of binary (mask) image
- Foreground has a pixel value of 255; background has a pixel value of 0; and unknown has a pixel value of 127
- In this example, the trimap is generated by extending a binary image of a previously segmented tumor
- A binary image consists of two parts: foreground (white) which is the tumor and background (black) which is the surrounding region
- Keep in mind that the unknown region is simply an approximation rather than an exact delineation. Therefore, matting process becomes a crucial key to extract foreground images with exact precision
- All binary images in this repository were generated from U-Net with a Jaccard's Coefficient of 0.94 (out of 1), indicating a high agreement between the ground truth and segmented mask images
- Image erosion feature is added which may anticipate any overestimating foreground issue
Input: a binary image (from a segmented lesion)
Output: a trimap with unknown region (gray) from tumor dilation
TO DO:
- Flow Chart -- illustrate how the program works
- Finding The Most Dominant Foreground -- using morphology closing and morphology opening
- Unit Testing
1 Dilating the binary image
import cv2, os, sys
from trimap_module import trimap
path = "./image/samples/seg_image.png";
image = extractImage(path);
name = "testImage";
size = 10; # how many pixel extension do you want to dilate
number = 1; # numbering purpose
trimap(image, name, size, number, erosion=False)
FULL IMAGE | MASK IMAGE | FOREGROUND | BACKGROUND |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
BINARY IMAGE | TRIMAP (10 PX) | TRIMAP (20 PX) | TRIMAP (30 PX) |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
2 Handling Non-Dominant Foreground (Ongoing Investigation)
NOISES | ORIGINAL IMAGES | TRIMAP RESULTS |
---|---|---|
Outside FG | ![]() |
![]() |
Inside FG | ![]() |
![]() |
3 Impact of Eroding Foreground
The illustration starts with zero erosion; followed with one, three, five, until eleven iterations (an increment of two).