To split the histological slides into several layers based on color, I changed some of the common codes (1) available through the OpenCV community. In our staining procedure, various types of cells of tissue sections of different colors are noted (B cells are red, macrophages are brown, background nodules have a bluish tint).
I am interested in choosing only the magenta and brown parts of the image.

Here is my attempt to create a mask for magenta pigment:
import cv2
import numpy as np
def mask_builder(filename,hl,hh,sl,sh,vl,vh):
bgr = cv2.imread(filename)
hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
lower_bound = np.array([hl,sl,vl],dtype=np.uint8)
upper_bound = np.array([hh,sh,vh],dtype=np.uint8)
return cv2.inRange(hsv, lower_bound,upper_bound)
mask = mask_builder('sample 20 138 1.jpg', 170,180, 0,200, 0,230)
cv2.imwrite('mask.jpg', mask)
So far, trial and error has led to poor results:

- HSV? , , , - .
:
UPDATE:
. "S" "V" , FOR, . , S V 100 125. :
