0

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

ussrback
  • 491
  • 2
  • 8
  • 22
  • Please try to improve your question, firstly by making it a *"Minimum Complete Verifiable Example"* meaning you put back all the `import` statements you have removed for some reason, and secondly by being more specific about the issue with the result - maybe you could share the results you surely must have? Thank you. – Mark Setchell Jan 10 '21 at 16:09
  • Use erosion (erode), not dilation.. – Alex Alex Jan 10 '21 at 19:54
  • 1
    I see you've corrected the example to use erosion. Now, note that there is a vertical black bar on the right edge of your input image: that will mess with your horizontal erosion (as you can see). Other than that, the results look correct: note that a footprint of 20 is equivalent to a radius of 10, and if you look at the top of the A it appears to have moved by about 10 pixels. So you just need to increase the size of your footprint. – Juan Jan 11 '21 at 23:38

1 Answers1

2

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.
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432