Ejemplo n.º 1
0
def test_otsu_camera_image():
    camera = skimage.img_as_ubyte(data.camera())
    assert 86 < threshold_otsu(camera) < 88
def test_otsu_lena_image():
    img = skimage.img_as_ubyte(data.lena())
    with expected_warnings(['grayscale']):
        assert 140 < threshold_otsu(img) < 142
Ejemplo n.º 3
0
def test_bimodal_multiotsu_hist():
    image = data.camera()
    thr_otsu = threshold_otsu(image)
    thr_multi = threshold_multiotsu(image, classes=2)
    assert thr_otsu == thr_multi
Ejemplo n.º 4
0
def test_otsu_astro_image():
    img = skimage.img_as_ubyte(data.astronaut())
    with expected_warnings(['grayscale']):
        assert 109 < threshold_otsu(img) < 111
Ejemplo n.º 5
0
 def test_otsu_negative_int(self):
     image = self.image - 2
     assert threshold_otsu(image) == 0
Ejemplo n.º 6
0
def test_otsu_one_color_image():
    img = np.ones((10, 10), dtype=np.uint8)
    with pytest.raises(ValueError):
        threshold_otsu(img)
Ejemplo n.º 7
0
def test_otsu_coins_image():
    coins = skimage.img_as_ubyte(data.coins())
    assert 106 < threshold_otsu(coins) < 108
Ejemplo n.º 8
0
def test_otsu_coins_image():
    coins = util.img_as_ubyte(data.coins())
    assert 106 < threshold_otsu(coins) < 108
Ejemplo n.º 9
0
def test_otsu_coins_image_as_float():
    coins = util.img_as_float(data.coins())
    assert 0.41 < threshold_otsu(coins) < 0.42
Ejemplo n.º 10
0
def test_otsu_camera_image_counts():
    camera = util.img_as_ubyte(data.camera())
    counts, bin_centers = histogram(camera.ravel(), 256, source_range='image')
    assert 101 < threshold_otsu(hist=counts) < 103
Ejemplo n.º 11
0
def test_otsu_one_color_image_3d():
    img = np.ones((10, 10, 10), dtype=np.uint8)
    assert threshold_otsu(img) == 1
Ejemplo n.º 12
0
def test_otsu_camera_image_histogram():
    camera = util.img_as_ubyte(data.camera())
    hist = histogram(camera.ravel(), 256, source_range='image')
    assert 101 < threshold_otsu(hist=hist) < 103
Ejemplo n.º 13
0
def test_otsu_camera_image():
    camera = util.img_as_ubyte(data.camera())
    assert 101 < threshold_otsu(camera) < 103
Ejemplo n.º 14
0
import scipy.misc
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from skimage.measure  import label
from scipy.misc.pilutil import Image
from skimage.measure import regionprops
from skimage.filters.thresholding import threshold_otsu

# opening the image and converting it to grayscale 
a = Image.open('../Figures/objects.png').convert('L') 
# a is converted to an ndarray
a = scipy.misc.fromimage(a)
# threshold value is determined by 
# using Otsu's method

thresh = threshold_otsu(a)
# the pixels with intensity greater than 
# theshold are kept
b = a > thresh
# labelling is performed on b
c = label(b)
# c is converted from an ndarray to an image 
c1 = scipy.misc.toimage(c)
# c1 is saved as label_output.png
c1.save('../Figures/label_output.png')
# on the labelled image c, regionprops is performed

d = regionprops(c)

# the following command creates an empty plot of 
# dimension 6 inch by 6 inch
Ejemplo n.º 15
0
def test_otsu_lena_image():
    img = skimage.img_as_ubyte(data.lena())
    assert 140 < threshold_otsu(img) < 142
Ejemplo n.º 16
0
def test_otsu_astro_image():
    img = util.img_as_ubyte(data.astronaut())
    with expected_warnings(['grayscale']):
        assert 109 < threshold_otsu(img) < 111
Ejemplo n.º 17
0
def test_otsu_astro_image():
    img = skimage.img_as_ubyte(data.astronaut())
    assert 109 < threshold_otsu(img) < 111
Ejemplo n.º 18
0
def test_otsu_one_color_image():
    img = np.ones((10, 10), dtype=np.uint8)
    with testing.raises(ValueError):
        threshold_otsu(img)
Ejemplo n.º 19
0
def test_otsu_camera_image():
    camera = skimage.img_as_ubyte(data.camera())
    assert 86 < threshold_otsu(camera) < 88
Ejemplo n.º 20
0
 def test_otsu(self):
     assert threshold_otsu(self.image) == 2
Ejemplo n.º 21
0
def test_otsu_coins_image_as_float():
    coins = skimage.img_as_float(data.coins())
    assert 0.41 < threshold_otsu(coins) < 0.42
Ejemplo n.º 22
0
 def test_otsu_negative_int(self):
     image = self.image - 2
     assert threshold_otsu(image) == 0
Ejemplo n.º 23
0
 def test_otsu(self):
     assert threshold_otsu(self.image) == 2
Ejemplo n.º 24
0
 def test_otsu_float_image(self):
     image = np.float64(self.image)
     assert 2 <= threshold_otsu(image) < 3
Ejemplo n.º 25
0
 def test_otsu_float_image(self):
     image = np.float64(self.image)
     assert 2 <= threshold_otsu(image) < 3
Ejemplo n.º 26
0
def console_estimate_response_matrix():

    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'config',
        type=str,
        help=
        'Name of the configuration file to use (don\'t include the path or extension).'
    )
    parser.add_argument(
        '--fits_file',
        type=str,
        default=None,
        help=
        'Explicitly specify the fits file to process. If not given, defaults to latest interaction matrix in the calib directory.'
    )
    parser.add_argument('--nproc',
                        type=int,
                        default=2,
                        help='Number of processes to spawn. [Default: 2]')
    #parser.add_argument('--paramfunc','-p', type=str, default=None, help='Function from which to define fitting parameters. Specified as module.function Default: get_magaox_fitting_params')
    parser.add_argument(
        '--override',
        '-o',
        type=str,
        default=None,
        nargs='+',
        help=
        'Space-delimited list of config parameters to override, set as section.option=value'
    )
    args = parser.parse_args()

    # get parameters from config file
    config_params = Configuration(args.config)
    # update with override args, if any
    if args.override is not None:
        override = parse_override_args(args.override)
        config_params.update_from_dict(override)

    validate_calibration_directory(config_params)

    calib_path = config_params.get_param('calibration', 'path', str)
    sympath_in = path.join(calib_path, 'measrespM.fits')

    # find and read in fits cube
    if args.fits_file is not None:
        pathname = args.fits_file
    else:
        pathname = sympath_in

    with fits.open(pathname) as f:
        image_cube = f[0].data

    logger.info(f'Performing estimation for {image_cube.shape} FITS file.')

    # get fitting params
    calib_func = config_params.get_param('calibration', 'function', str)
    mname, fname = calib_func.rsplit('.', 1)
    mod = import_module(mname)
    param_func = getattr(mod, fname)

    # get default steps
    config_steps = config_params.get_param('calibration', 'default_steps', str)
    mname, fname = config_steps.rsplit('.', 1)
    mod = import_module(mname)
    default_steps = getattr(mod, fname)

    # get default steps (no xy)
    config_steps = config_params.get_param('calibration', 'default_steps_noxy',
                                           str)
    mname, fname = config_steps.rsplit('.', 1)
    mod = import_module(mname)
    default_steps_noxy = getattr(mod, fname)

    fitting_params = param_func(
        camera=config_params.get_param('camera', 'name', str),
        wfilter=config_params.get_param('diversity', 'wfilter', str),
        mask=config_params.get_param('estimation', 'pupil', str),
        N=config_params.get_param('estimation', 'N', int),
        divtype=config_params.get_param('diversity', 'type', str),
        divvals=config_params.get_param('diversity', 'values', float),
        npad=config_params.get_param('estimation', 'npad', int),
        nzernikes=config_params.get_param('estimation', 'nzernike', int),
    )

    estdict = estimate_response_matrix(
        image_cube,
        fitting_params,
        processes=config_params.get_param('estimation', 'nproc', int),
        gpus=config_params.get_param('estimation', 'gpus', int),
        fix_xy_to_first=config_params.get_param('interaction',
                                                'fix_xy_to_first', bool),
        default_steps=default_steps,
        steps_noxy=default_steps_noxy)
    pupil = fitting_params['pupil_analytic'].astype(bool)
    estrespM = np.asarray(estdict['phase']) * pupil

    # amplitude thresholding
    amp = np.mean(estdict['amp'], axis=0)
    amp_norm = amp / np.mean(amp[pupil])
    thresh_amp = threshold_otsu(amp_norm)
    threshold = config_params.get_param('control', 'ampthreshold', float)
    amp_mask = amp_norm > (thresh_amp * threshold)

    estrespM *= amp_mask

    date = datetime.now().strftime("%Y%m%d-%H%M%S")
    outname = path.join(calib_path, 'estrespM', f'estrespM_{date}.fits')

    # write phases out to file
    fits.writeto(outname, estrespM)

    # replace symlink
    sympath_out = path.join(calib_path, 'estrespM.fits')
    replace_symlink(sympath_out, outname)