예제 #1
0
    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)
예제 #2
0
        if c.shape[0] >= 5:
            x, y, w, h = cv2.boundingRect(c)
            area = cv2.contourArea(c)
            perimeter = cv2.arcLength(c, True)
            if area > 100 and perimeter > 150 and area < 6000 and perimeter < 300:
                features = extractFeatures(c)
                # Original
                #            features = [imgname + "_{}".format(count) + ".png"] + [count] + features
                # MODIFIED
                #            features = [imgname + "_{}".format(count) + ".png"] + [ '<img src=' + '"..\\Cell_Images\\' + imgname + "_{}".format(count) + ".png" + '">'] + [count] + features
                features = [imgname + "_{}".format(count) + ".png"] + [
                    '<img src="' + imgname + "_{}".format(count) + ".png" +
                    '">'
                ] + features

                # End Modified

                append_csv(features, filepath + "_data")
                roi = clean[y:y + h, x:x + w]
                contours.append(c)
                count += 1


#    print num, count

if __name__ == "__main__":
    img, gray = img_load("0073")
    clean = img.copy()
    imgthresh = thresh(img, gray)
    calcFeatures(clean, imgthresh, gray)