Exemple #1
0
def color_normalization(template_image_path, color_norm_method):
    """
    The function put all the color normalization methods together.

    :param template_image_path: the template image for normalization
    :type template_image_path: string
    :param color_norm_method: the method for color normalization
    :type color_norm_method: string

    :return: color_normalizer. It is the initialized object for the
             actual normalization.
    :rtype: object

    """
    template_image = staintools.read_image(template_image_path)
    standardizer = staintools.LuminosityStandardizer.standardize(
        template_image)
    if color_norm_method == 'Reinhard':
        color_normalizer = stainNorm_Reinhard.Normalizer()
        color_normalizer.fit(standardizer)
    elif color_norm_method == 'Macenko':
        color_normalizer = stainNorm_Macenko.Normalizer()
        color_normalizer.fit(standardizer)
    elif color_norm_method == 'Vahadane':
        color_normalizer = staintools.StainNormalizer(method='vahadane')
        color_normalizer.fit(standardizer)
    return color_normalizer
Exemple #2
0
def colorN(img_path):
    img = utils.read_image(img_path)
    fit_img = utils.read_image('/cptjack/totem/zhaofeiyan/DataSet/data-ori/target.png')
    n = stainNorm_Macenko.Normalizer()
    n.fit(fit_img)
    t_img = n.transform(img)
    return t_img
def colorN(img):

    #  染色标准化处理,选取目标图片target.png作为参考图,调用stainNorm_Macenko.Normalizer()方法

    fit_img = utils.read_image(
        '/cptjack/totem/zhaofeiyan/DataSet/data-ori/target.png')
    n = stainNorm_Macenko.Normalizer()
    n.fit(fit_img)
    t_img = n.transform(img)
    return t_img
def color_normalization(template_image_path, color_norm_method):
    """
    The function put all the color normalization methods together.
    :param string template_image_path: the path of the image used as a template
    :param string color_norm_method: one of the three methods: vahadane, macenko, reinhard.
    :return object 
    """
    template_image = staintools.read_image(template_image_path)
    standardizer = staintools.LuminosityStandardizer.standardize(
        template_image)
    if color_norm_method == 'Reinhard':
        color_normalizer = stainNorm_Reinhard.Normalizer()
        color_normalizer.fit(standardizer)
    elif color_norm_method == 'Macenko':
        color_normalizer = stainNorm_Macenko.Normalizer()
        color_normalizer.fit(standardizer)
    elif color_norm_method == 'Vahadane':
        color_normalizer = staintools.StainNormalizer(method='vahadane')
        color_normalizer.fit(standardizer)

    return color_normalizer
Exemple #5
0
def Normalization(inputPath, outputPath, sampleImagePath, num_threads=8):

    inputPathContent = os.listdir(inputPath)
    normPathContent = os.listdir(outputPath)

    remainlList = []
    for i in inputPathContent:
        if not i in normPathContent:
            remainlList.append(i)

    inputPathContent = [i for i in remainlList if not i.endswith('.bat')]
    inputPathContent = [i for i in inputPathContent if not i.endswith('.txt')]

    target = cv2.imread(sampleImagePath)
    target = cv2.cvtColor(target, cv2.COLOR_BGR2RGB)
    normalizer = stainNorm_Macenko.Normalizer()
    normalizer.fit(target)

    pool = ThreadPool(num_threads)
    pool.map(Normalize_Main, inputPathContent)
    pool.close()
    pool.join()
Exemple #6
0
import stain_utils as utils
import stainNorm_Macenko

import cv2

i3 = utils.read_image('./data/i3.png')
i2 = utils.read_image('./data/i2.png')
n = stainNorm_Macenko.Normalizer()
n.fit(i2)
out = n.transform(i3)
cv2.imwrite('ans1.jpg', out)
Exemple #7
0
import stainNorm_Reinhard
import vahadane

import cv2 as cv

from os import listdir, mkdir
from os.path import isfile, join, isdir

# paths
source_path = "/home/fred/Projects/srt-cancer-img/pair-data/"
suffix = "frames/x40/"
save_path = "/home/fred/Projects/srt-cancer-img/pair-data/output/"

# normalizers
normalizer_rd = stainNorm_Reinhard.Normalizer()
normalizer_mk = stainNorm_Macenko.Normalizer()
normalizer_vd = vahadane.vahadane()

for dirname in listdir(source_path):
    if 'A06' in dirname:
        print("Processing directory ", dirname)

        imgs = [f for f in listdir(join(source_path, dirname, suffix))]

        for img in imgs[1:]:
            source = stain_utils.read_image(
                join(source_path, dirname, suffix, img))
            target = stain_utils.read_image(
                join(source_path, dirname.replace('A', 'H', 1), suffix,
                     img.replace('A', 'H', 1)))