def QuantStain(self, image, filename, save=False):
img_hsv = rgb2hsv(image)
img_hue = img_hsv[:, :, 0]
image_sat = img_hsv[:, :, 1]
hue = np.logical_and(img_hue > 0.02, img_hue < 0.10) # BROWN PIXELS BETWEEN 0.02 and 0.10
if self.threshold:
stain = np.logical_and(hue, image_sat > self.threshold) # USER DEFINED MINIMUM SATURATION THRESHOLD
else:
print("Defult threshold")
stain = np.logical_and(hue, image_sat > 0.79) # DEFAULT SATURATION THRESHOLD APPLIED IF NO USER INPUT
self.current_image = stain[::10, ::10].astype(float) # SHOW A LOW RESOLUTION MASK AS A FIGURE
self.figures.emit()
if save:
self.info.emit("Saving - " + filename+'_stain.tiff') # SAVE A FIGURE IF REQUIRED
imagesave = Image.fromarray(stain)
imagesave.save(self.inputpath+os.sep+filename+'_stain.tiff')
stint = np.copy(image)
stint = exposure.rescale_intensity(stint, out_range=(0, 255))
stint[stain == 0] = 0 # array with only the stained pixels
stint = color.rgb2gray(stint) # convert to greyscale
stint = np.ravel(stint) # flatten image array
stint = stint[stint != 0] # remove all zeros
stint_mean = stint.mean()
stint_std = stint.std()
stained = np.sum(stain)
return stained, stint_mean, stint_std