-1

Hello i need to calculate the height of a character from a binarzation image ( see the image bellow):

Binarization image of B

Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143

1 Answers1

2

You can calculate the row of pixels that have the most black pixels.

import cv2
import numpy as np

pic = cv2.imread('binarized.png')[:, 50:-50, 0]

np.max(np.sum(1 - (pic//255), axis=0))
382

Using MS Paint, I was able to confirm that the height is 382 by drawing a 382 pixel line next to it. I had to exclude your black borders though. enter image description here

Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
  • yes i liked the method but i doesn't give the real height ( from the first black pixel, to the last one) i tested it on another images and it failed – Mohamed Soheib Sep 14 '20 at 23:39
  • 3
    @MohamedSoheib Post more images bruh. – rayryeng Sep 15 '20 at 05:58
  • If this fails, please post more pictures. I can't propose a solution that fits data that I haven't seen. For now, this one works so I dont know what else I could suggest. – Nicolas Gervais Sep 15 '20 at 15:50