Currently, I am practicing with retrieving the total of the pixel values above a threshold based on the mean of the whole image. (I am very new to Python). I am using Python 3.5.2, and the above code was copied from the Atom program I am using to write and experiment with the code.
For the time being, I am just practicing with the red channel - but eventually, I will need to individually analyse all colour channels.
The complete code that I am using so far:
from skimage import io
from tkinter import *
from tkinter.filedialog import askopenfilename
M = askopenfilename() #to select a file
image = io.imread(M) #to read the selected file
red = image[:,:,0] #selecting the red channel
red_av = red.mean() #average pixel value of the red channel
threshold = red_av + 100 #setting the threshold value
red_val = red > threshold
red_sum = sum(red_val)
Button(text = 'Select Image', command = callback).pack(fill = X)
When you did (red > threshold) you got a mask such that all the pixels in red that are above the thrshold got the value 1 and 0 other wise. Now to get the values you can just multiply the mask with the red channel. The multiplcation will zero all the values that are less than the threshold and will leave the values over the threshold unchanged.
red_val = (red > threshold)*red red_sum = sum(red_val)