示例#1
0
def main2():
    dstroot = 'fovs'
    list_dst = os.listdir(dstroot)
    for n, i in zip(list_dst, tqdm(range(len(list_dst)))):
        imgpath = os.path.join(dstroot, n)
        #     print(imgpath)
        img_org = cv2.imread(imgpath)
        img_gray = cv2.imread(imgpath, 0)
        img_gray_fit = bf.get_fit_img(img_gray)
        value_1, value_2 = bf.get_2value(img_gray_fit)  # 获取细胞核、背景阈值
        kernel_1 = np.ones((50, 50), np.uint8)
        kernel_2 = np.ones((5, 5), np.uint8)
        cells_xoy = get_cells(img_gray_fit,
                              imgpath,
                              value_2 + 10,
                              kernel_1,
                              50000,
                              1600,
                              side=5)
        value_1, value_2 = bf.get_2value(img_gray_fit, grien=3)
        clusters_xoy = get_clusters(img_gray_fit,
                                    value_1,
                                    kernel_2,
                                    20000,
                                    1000000,
                                    side=5)
        crop_from_fov(img_org, n, cells_xoy)
        crop_from_fov(img_org, n, clusters_xoy, root_='clusters')
示例#2
0
def main2():
    dstroot = 'clusters'
    listcells = os.listdir(dstroot)
    cellsinfo = []
    for n, i in zip(listcells, tqdm(range(len(listcells)))):
        cellinfo = {}
        cellpath = os.path.join(dstroot, n)
        img = cv2.imread(cellpath)
        img_gray = cv2.imread(cellpath, 0)
        img_gray = bf.get_fit_img(img_gray)
        #   cv2.imwrite(cellpath+'abc0.png',img_gray)
        value1_, value_2 = bf.get_2value(img_gray)
        value_1, _ = bf.get_2value(img_gray, grien=3)
        sign_, cell_nuclei_mask1, area1 = get_cell_nuclei_mask(
            img_gray, img, value_1)  #获取细胞核掩码、个数、面积、凸面积、周长、核形规则度、获取细胞>核深染程度
        sign_, cell_nuclei_mask2, area2 = get_cell_nuclei_mask(
            img_gray, img, value1_)  #获取细胞核掩码、个数、面积、凸面积、周长、核形规则度、获取细胞核深染
        if sign_ == 0:
            continue
    #    cv2.imwrite(cellpath+'abc1.png',cell_nuclei_mask2)
        temp = area1 / area2
        temp1 = str(temp)[0:5]
        if area1 / area2 > 0.85:
            newpath = os.path.join('ab_clusters', n + '_' + temp1 + '.png')
            shutil.copy(cellpath, newpath)
示例#3
0
def main2():
    dstroot = 'crop'
    listcells = os.listdir(dstroot)
    cellsinfo = []
    for n, i in zip(listcells, tqdm(range(len(listcells)))):
        cellinfo = {}
        cellpath = os.path.join(dstroot, n)
        img = cv2.imread(cellpath)
        img_gray = cv2.imread(cellpath, 0)
        img_gray = bf.get_fit_img(img_gray)
        #   cv2.imwrite(cellpath+'abc0.png',img_gray)
        value_1, value_2 = bf.get_2value(img_gray)
        sign_nuclei, cell_nuclei_mask, nuclei_cnt, nuclei_area, nuclei_hull_area, nuclei_circ, nuclei_rule, cell_nuclei_value = get_cell_nuclei_mask(
            img_gray, img, value_1)  #获取细胞核掩码、个数、面积、凸面积、周长、核形规则度、获取细胞核深染程度
        #   cv2.imwrite(cellpath+'abc1.png',cell_nuclei_mask)
        if sign_nuclei == 0:
            continue
        sign_cytoplasm, cell_cytoplasm_mask, cytoplasm_area, cytoplasm_hull_area, cytoplasm_circ, cytoplasm_rule, cell_cytoplasm_value, cytoplasm_var = get_cell_cytoplasm_mask(
            img_gray, cell_nuclei_mask, nuclei_area, img,
            value_2)  #获取细胞质掩码、面积、凸面积、周长、细胞规则度、获取细胞质情况
        #   cv2.imwrite(cellpath+'abc2.png',cell_cytoplasm_mask)
        if sign_cytoplasm == 0 or (cytoplasm_area - nuclei_area) == 0:
            continue
        cell_N_C = nuclei_area / (cytoplasm_area - nuclei_area)  #计算核质比
        cellinfo_keys = [
            'cellpath', 'nuclei_cnt', 'nuclei_area', 'nuclei_hull_area',
            'nuclei_circ', 'nuclei_rule', 'cell_nuclei_value',
            'cytoplasm_area', 'cytoplasm_hull_area', 'cytoplasm_circ',
            'cytoplasm_rule', 'cell_cytoplasm_value', 'cytoplasm_var',
            'cell_N_C'
        ]
        cellinfo_values = [
            cellpath, nuclei_cnt, nuclei_area, nuclei_hull_area, nuclei_circ,
            nuclei_rule, cell_nuclei_value, cytoplasm_area,
            cytoplasm_hull_area, cytoplasm_circ, cytoplasm_rule,
            cell_cytoplasm_value, cytoplasm_var, cell_N_C
        ]
        cellinfo = dict(zip(cellinfo_keys, cellinfo_values))
        cell_save_sign = get_cell_save_sign(cellinfo)
        if cell_save_sign == 0:
            continue
        cellsinfo.append(cellinfo)
        newpath = os.path.join('valid', n)
        shutil.copy(cellpath, newpath)
    np.save("./cells_info/cells_info.npy", cellsinfo)
示例#4
0
                                    20000,
                                    1000000,
                                    side=5)
        crop_from_fov(img_org, n, cells_xoy)
        crop_from_fov(img_org, n, clusters_xoy, root_='clusters')


if __name__ == "__main__":
    dstroot = 'fovs'
    list_dst = os.listdir(dstroot)
    for n, i in zip(list_dst, tqdm(range(len(list_dst)))):
        imgpath = os.path.join(dstroot, n)
        #      print(imgpath)
        img_org = cv2.imread(imgpath)
        img_gray = cv2.imread(imgpath, 0)
        img_gray_fit = bf.get_fit_img(img_gray)
        value_1, value_2 = bf.get_2value(img_gray_fit)  # 获取细胞核、背景阈值
        kernel_1 = np.ones((50, 50), np.uint8)
        kernel_2 = np.ones((5, 5), np.uint8)
        cells_xoy = get_cells(img_gray_fit,
                              imgpath,
                              value_2 + 10,
                              kernel_1,
                              50000,
                              1600,
                              side=5)
        value_1, value_2 = bf.get_2value(img_gray_fit, grien=3)
        clusters_xoy = get_clusters(img_gray_fit,
                                    value_1,
                                    kernel_2,
                                    20000,
示例#5
0
        temp1 = str(temp)[0:5]
        if area1 / area2 > 0.85:
            newpath = os.path.join('ab_clusters', n + '_' + temp1 + '.png')
            shutil.copy(cellpath, newpath)


if __name__ == "__main__":
    dstroot = 'clusters'
    listcells = os.listdir(dstroot)
    cellsinfo = []
    for n, i in zip(listcells, tqdm(range(len(listcells)))):
        cellinfo = {}
        cellpath = os.path.join(dstroot, n)
        img = cv2.imread(cellpath)
        img_gray = cv2.imread(cellpath, 0)
        img_gray = bf.get_fit_img(img_gray)
        #   cv2.imwrite(cellpath+'abc0.png',img_gray)
        value1_, value_2 = bf.get_2value(img_gray)
        value_1, _ = bf.get_2value(img_gray, grien=3)
        sign_, cell_nuclei_mask1, area1 = get_cell_nuclei_mask(
            img_gray, img, value_1)  #获取细胞核掩码、个数、面积、凸面积、周长、核形规则度、获取细胞>核深染程度
        sign_, cell_nuclei_mask2, area2 = get_cell_nuclei_mask(
            img_gray, img, value1_)  #获取细胞核掩码、个数、面积、凸面积、周长、核形规则度、获取细胞核深染
        if sign_ == 0:
            continue
    #    cv2.imwrite(cellpath+'abc1.png',cell_nuclei_mask2)
        temp = area1 / area2
        temp1 = str(temp)[0:5]
        if area1 / area2 > 0.85:
            newpath = os.path.join('ab_clusters', n + '_' + temp1 + '.png')
            shutil.copy(cellpath, newpath)