Exemple #1
0
def test_single_tile(test_apply_correction, render, tmpdir):

    # get tilespecs
    # Z = test_apply_correction.args['z_index']
    Z = 400
    inp_tilespecs = renderapi.tilespec.get_tile_specs_from_z(
        test_apply_correction.args['input_stack'],
        Z,
        render=test_apply_correction.render)
    corr_tilespecs = renderapi.tilespec.get_tile_specs_from_z(
        test_apply_correction.args['correction_stack'],
        Z,
        render=test_apply_correction.render)
    # mult intensity correct each tilespecs and return tilespecs
    N, M, C = getImage(corr_tilespecs[0])
    corr_dict = {}
    for channel in ["DAPI_1", "PSD95"]:
        _, _, corr_dict[channel] = getImage(corr_tilespecs[0], channel=channel)

    process_tile(C,
                 test_apply_correction.args['output_directory'],
                 test_apply_correction.args['output_stack'],
                 True,
                 1.0,
                 0,
                 65535,
                 inp_tilespecs[0],
                 corr_dict=corr_dict)
Exemple #2
0
def test_apply_correction(test_median_stack, mini_raw_stack, render,
                          tmpdir_factory):
    output_directory = str(tmpdir_factory.mktemp('intensity_corrected'))
    output_stack = "Flatfield_corrected_test"
    params = {
        "render": render_params,
        "input_stack": mini_raw_stack,
        "correction_stack": test_median_stack,
        "output_stack": output_stack,
        "output_directory": output_directory,
        "z_index": 0,
        "pool_size": 10,
        "overwrite_zlayer": True
    }
    mod = MultIntensityCorr(input_data=params, args=[])
    mod.run()

    expected_directory = os.path.join(multiplicative_correction_example_dir,
                                      'intensity_corrected')
    output_tilespecs = renderapi.tilespec.get_tile_specs_from_z(output_stack,
                                                                0,
                                                                render=render)

    for ts in output_tilespecs:
        N, M, out_image = getImage(ts)
        out_filepath = ts.ip[0].imageUrl
        out_file = os.path.split(out_filepath)[1]
        exp_image = tifffile.imread(os.path.join(expected_directory, out_file))
        assert (np.max(np.abs(exp_image - out_image)) < 3)
    return mod
Exemple #3
0
def test_median_stack(raw_stack, render, tmpdir_factory):
    median_stack = 'median_stack'
    output_directory = str(tmpdir_factory.mktemp('Median'))
    params = {
        "render": render_params,
        "input_stack": raw_stack,
        "file_prefix": "Median",
        "output_stack": median_stack,
        "output_directory": output_directory,
        "minZ": 0,
        "maxZ": 0,
        "pool_size": 3,
        "log_level": "DEBUG"
    }
    mod = MakeMedian(input_data=params, args=[])
    mod.run()

    median_tilespecs = renderapi.tilespec.get_tile_specs_from_stack(
        median_stack, render=render)
    N, M, median_image = getImage(median_tilespecs[0])

    expected_median_file = os.path.join(multiplicative_correction_example_dir,
                                        'median', 'Median_median_stack_0.tif')
    expect_median = tifffile.imread(expected_median_file)

    assert (np.max(np.abs(median_image - expect_median)) < 3)

    yield median_stack
def make_median_image(alltilespecs,
                      numtiles,
                      outImage,
                      pool_size,
                      chan=None,
                      gauss_size=10):
    # read images and create stack
    N, M, img0 = getImage(alltilespecs[0], channel=chan)
    stack = np.zeros((N, M, numtiles), dtype=img0.dtype)
    mypartial = partial(getImageFromTilespecs, alltilespecs, channel=chan)
    indexes = range(0, numtiles)
    with renderapi.client.WithPool(pool_size) as pool:
        images = pool.map(mypartial, indexes)

    # calculate median
    for i in range(0, len(images)):
        stack[:, :, i] = images[i]
    np.median(stack, axis=2, overwrite_input=True)
    (A, B, C) = stack.shape
    if (numtiles % 2 == 0):
        med1 = stack[:, :, numtiles // 2 - 1]
        med2 = stack[:, :, numtiles // 2 + 1]
        med = (med1 + med2) // 2
    else:
        med = stack[:, :, (numtiles - 1) // 2]
    med = gaussian_filter(med, gauss_size)

    tifffile.imsave(outImage, med)
Exemple #5
0
def test_single_tile(test_apply_correction, render, tmpdir):

    # get tilespecs
    Z = test_apply_correction.zValues[0]
    inp_tilespecs = renderapi.tilespec.get_tile_specs_from_z(
        test_apply_correction.args['input_stack'],
        Z,
        render=test_apply_correction.render)
    corr_tilespecs = renderapi.tilespec.get_tile_specs_from_z(
        test_apply_correction.args['correction_stack'],
        Z,
        render=test_apply_correction.render)
    # mult intensity correct each tilespecs and return tilespecs
    N, M, C = getImage(corr_tilespecs[0])

    process_tile(C, test_apply_correction.args['output_directory'],
                 test_apply_correction.args['output_stack'], True, 1.0, 0,
                 65535, inp_tilespecs[0])
def getImageFromTilespecs(alltilespecs, index, channel=None):
    N, M, img = getImage(alltilespecs[index], channel)
    return img