How to find area in pixels output

Viewed 139

I need to output the area in pixels for the binary_mole.

mole_1 = mpimg.imread('mole_1.png')
gray_mole = rgb2grey(mole_1)
threshold = skimage.filters.threshold_otsu(gray_mole)
binary_mole = (gray_mole < threshold)

My attempt to find the area in pixels is below

trys = np.sum(binary_mole == 255)
print('number of white pixels = ' , trys)

The binary_mole looks likeenter image description here

How do I fix this or go about it?

1 Answers

There is a built in function called regionprops, that has numerous measurements.

import skimage.measure as meas
binary_label = meas.label(binary_mole)
measurements = meas.regionpros(binary_label)

area = measurements[0]['area']
Related