Horizontal and Vertical dilation using skimage

627 Views Asked by At

My task is to perform directional morphological dilation on character, so it produces the horizontal bar for vertical dilation and vertical bar for horizontal dilation.
![enter image description here


Where a) is an original character b) after vertical dilation and c) after horizontal dilation.

Below is the code for skimage however it did not produce the result i was expecting for.

from skimage.morphology import dilation, erosion
from skimage.io import imshow, imread, show
import numpy as np
from skimage.filters import threshold_otsu

image = imread('img/A_en.png', as_gray=True)
#binarizing the image
thresh = threshold_otsu(image)
binary = image > thresh

sev = np.ones((20,1)) #20 -row 1-column
seh = np.ones((1,20))
vertical = erosion(binary,sev)
horizontal = erosion(binary, seh)

Result:
Original ImageVerticalHorizontal

1

There are 1 best solutions below

0
Mark Setchell On

Morphology treats the white area as foreground and the black area as background. So, if you want to dilate the letters, which are black, you need to either:

  • invert the image first, or
  • use the counterpart to dilation, which is erosion.