def pipeline(): for img in glob.glob('..\\HemaCam-Data\\Input_Images\\*.jpg'): image = cv2.imread(img) imgname, extension = os.path.basename(img).split(".") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) threshold = thresh(image, gray) cellSegmentation(image, threshold, gray, filepath + imgname) calcFeatures(image, threshold, gray, filepath2 + imgname, imgname)
def calcHist(roi, filepath, count): roi_copy = roi.copy() cellgray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) cellthresh = thresh(roi, cellgray) cellmask = cellthresh color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([roi_copy],[i],cellmask,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) fig = plt.gcf() fig.savefig(rootpath + filepath + "_hist_{}.jpg".format(count)) plt.clf()
for label in np.unique(labels): if label == 0: continue mask = np.zeros(gray.shape, dtype="uint8") mask[labels == label] = 255 cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] c = max(cnts, key=cv2.contourArea) if c.shape[0] >= 5: x, y, w, h = cv2.boundingRect(c) # Filter out small/incomplete cells area = cv2.contourArea(c) perimeter = cv2.arcLength(c, True) if area > 100 and perimeter > 150 and area < 6000 and perimeter < 300: roi = clean[y:y + h, x:x + w] cv2.imwrite(rootpath + filepath + "_{}.png".format(count), roi) # calcHist(roi, filepath, count) contours.append(c) count += 1 # print num, count if __name__ == "__main__": img, gray = img_load(imgname) clean = img.copy() imgthresh = thresh(img, gray) cellSegmentation(clean, imgthresh, gray)
import cv2 from HemaCamSegmentation import img_load, thresh from realCellSegmentation import cellSegmentation from cellArea import cellArea from boundingEllipse import boundingEllipse from cellCount import cellCount from features import calcFeatures from boundingRectangle import boundingRectangle imgname = 'Sickle2' filepath = "demo_out" + "\\" + imgname rootpath = "C:\\Users\\eshikasaxena\\Desktop\\HemaCam Project\\HemaCam-Data\\" img = cv2.imread(rootpath + imgname + ".jpg") cv2.imwrite(rootpath + filepath + ".jpg", img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imshow("img", img) cv2.imshow("gray", gray) cv2.imwrite(rootpath + filepath + "_gray.jpg", gray) threshold = thresh(img, gray) cv2.imshow("thresh", threshold) cv2.imwrite(rootpath + filepath + "_thresh.jpg", threshold) area = cellArea(img, threshold, gray, filepath) ellipse = boundingEllipse(img, threshold, gray, filepath) count = cellCount(img, threshold, gray, filepath) cv2.imwrite(rootpath + filepath + "_count.jpg", count) rect = boundingRectangle(img, threshold, gray, filepath) cellSegmentation(img, threshold, gray, filepath) #calcFeatures(img, threshold, gray, filepath, imgname) cv2.imshow("out", np.hstack([ellipse, area, rect])) cv2.waitKey(0) cv2.destroyAllWindows()