I have segmented and binary image of biological cells and using openCV I have extracted the areas and perimeters of the contours. I am trying to label and color with a colormap each cell according to a parameter q=perimeter/Sqrt(area) but have no idea where to even start. Essentially each cell will have a unique color according to this value.
Any help would be greatly appreciated! Here is what I have so far:
> #specify folders
filelocat = '/Users/kate/Desktop/SegmenterTest3/SegmentedCells/'
#process image
img = cv2.imread(str(filelocat) + 'Seg3.png')
image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(image, 60, 255, cv2.THRESH_BINARY)[1]
kernel = np.ones((20,20), np.uint8)
closing = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
#inverts image so that the objects are white (for analysis)
imagem = cv2.bitwise_not(closing)
#Find contours
cnts = cv2.findContours(imagem.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
#calculate moments and extract cell shape info
moment_dict = {}
for index, cnt in enumerate(cnts):
moment_dict[index] = cv2.moments(cnt)
obj_properties = {}
for index, (key, obj_moments) in enumerate(moment_dict.items()):
if obj_moments['m00'] > 1000 and obj_moments['m00'] < 20000:
area = obj_moments['m00']
cx = obj_moments['m10'] / obj_moments['m00']
cy = obj_moments['m01'] / obj_moments['m00']
peri = cv2.arcLength(cnts[index], True)
q = (peri/(math.sqrt(area)))
props = {}
props['q']=q
props['peri']=peri
props['area']=area
props['cx']=cx
props['cy']=cy
obj_properties[key] = props
Thank you for your help!!