简体   繁体   中英

how to use python to calculate the percentage of the dark area of a noise image

Here I uploaded a image which is very noisy. and in the image there are some dark areas. is there a way to use python to do image processing and calculate the percentage of the dark area?

noise x-ray image

I am not sure about the exact requirement so let me formalize a little bit what I understood from the limited description in the question:

Required:

For some grayscale image img , we want to calculate as a percentage of the total number of pixels, the number of pixels that have an intensity value below a certain threshold, say t

Assuming you have loaded your image into a numpy array, you can simply calculate the total number of pixels with intensity value < t and divide by the total number of pixels.

num_dark_px    = sum(img[img < t])
num_total_px   = img.shape[0] * img.shape[1]
dark_area_pcnt = num_dark_px / num_total_px

If there is another objective, please specify more information about the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM