当前位置: 首页>>代码示例>>Python>>正文


Python measure.ssim函数代码示例

本文整理汇总了Python中skimage.measure.ssim函数的典型用法代码示例。如果您正苦于以下问题:Python ssim函数的具体用法?Python ssim怎么用?Python ssim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ssim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_distance_matrix

def get_distance_matrix(img_dir):
    f_list, IS_IMG = get_f_list(img_dir)

    os.chdir(img_dir)
    N = len(f_list)
    dm = np.ones((N, N))
    if IS_IMG:
        # distance matrix, n by n init to zeros
        for i_tuple in itertools.combinations(range(len(f_list)), 2):
            i, j = i_tuple
            img1 = cv2.imread(f_list[i])
            img2 = cv2.imread(f_list[j])
            # to grey scale
            img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
            img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

            s = 1 - ssim(img1, img2)    # so that distance makes sense

            # symmetric matrix!
            # not sparse anymore!!!!
            dm[i][j] = s
            dm[j][i] = s
    else:
        for i_tuple in itertools.combinations(range(len(f_list)), 2):
            i, j = i_tuple
            i_dat = get_csv_array(f_list[i])
            j_dat = get_csv_array(f_list[j])

            s = 1-ssim(i_dat, j_dat)

            dm[i][j] = s
            dm[j][i] = s
    return dm
开发者ID:xiaoyingpu,项目名称:SIParCS_NCAR,代码行数:33,代码来源:dm_manifold.py

示例2: test_ssim_patch_range

def test_ssim_patch_range():
    N = 51
    X = (np.random.rand(N, N) * 255).astype(np.uint8)
    Y = (np.random.rand(N, N) * 255).astype(np.uint8)

    assert(ssim(X, Y, win_size=N) < 0.1)
    assert_equal(ssim(X, X, win_size=N), 1)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_structural_similarity.py

示例3: test_ssim_multichannel

def test_ssim_multichannel():
    N = 100
    X = (np.random.rand(N, N) * 255).astype(np.uint8)
    Y = (np.random.rand(N, N) * 255).astype(np.uint8)

    S1 = ssim(X, Y, win_size=3)

    # replicate across three channels.  should get identical value
    Xc = np.tile(X[..., np.newaxis], (1, 1, 3))
    Yc = np.tile(Y[..., np.newaxis], (1, 1, 3))
    S2 = ssim(Xc, Yc, multichannel=True, win_size=3)
    assert_almost_equal(S1, S2)

    # full case should return an image as well
    m, S3 = ssim(Xc, Yc, multichannel=True, full=True)
    assert_equal(S3.shape, Xc.shape)

    # gradient case
    m, grad = ssim(Xc, Yc, multichannel=True, gradient=True)
    assert_equal(grad.shape, Xc.shape)

    # full and gradient case
    m, grad, S3 = ssim(Xc, Yc, multichannel=True, full=True, gradient=True)
    assert_equal(grad.shape, Xc.shape)
    assert_equal(S3.shape, Xc.shape)

    # fail if win_size exceeds any non-channel dimension
    assert_raises(ValueError, ssim, Xc, Yc, win_size=7, multichannel=False)
开发者ID:Britefury,项目名称:scikit-image,代码行数:28,代码来源:test_structural_similarity.py

示例4: test_mssim_mixed_dtype

def test_mssim_mixed_dtype():
    mssim = ssim(cam, cam_noisy)
    with expected_warnings(['Inputs have mismatched dtype']):
        mssim_mixed = ssim(cam, cam_noisy.astype(np.float32))
    assert_almost_equal(mssim, mssim_mixed)

    # no warning when user supplies data_range
    mssim_mixed = ssim(cam, cam_noisy.astype(np.float32), data_range=255)
    assert_almost_equal(mssim, mssim_mixed)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:9,代码来源:test_structural_similarity.py

示例5: svd_compress_ssim

def svd_compress_ssim(img, target_ss):
	"""Compress image by finding k that is closest to target ssim.
	Since rank and ssim relationship is linear, we do a 
	binary search, followed by finer grained linear search"""
	rank = min(img.shape[0], img.shape[1])
	left = 1
	right = rank
	last_ss = 100
	k = 1
	compressed = None
	U, singular_vals, V = linalg.svd(img)
	# binary search
	while left < right:	
		k = (left + right) / 2
		S_p = np.zeros((k, k), img.dtype)
		for i in range(k):
			S_p[i][i] = singular_vals[i]
		compressed = combine(U[:,:k], S_p, V[:k,:])
		ss = ssim(img, compressed,
			dynamic_range=compressed.max()-compressed.min())
		if abs(ss - target_ss) < abs(last_ss - target_ss):
			last_ss = ss
			if ss > target_ss:
				right = k
			else:
				left = k
		else:
			break
	# more fine grained linear search
	if last_ss < target_ss:
		while 1:
			S_p = np.zeros((k + 1, k + 1), img.dtype)
			for i in range(k + 1):
				S_p[i][i] = singular_vals[i]
			compressed = combine(U[:,:k+1], S_p, V[:k+1,:])
			ss = ssim(img, compressed,
				dynamic_range=compressed.max()-compressed.min())
			if abs(ss - target_ss) < abs(last_ss - target_ss):
				last_ss = ss
				k += 1	
			else:
				break
	else:
		while 1:
			S_p = np.zeros((k - 1, k - 1), img.dtype)
			for i in range(k - 1):
				S_p[i][i] = singular_vals[i]
			compressed = combine(U[:,:k-1], S_p, V[:k-1,:])
			ss = ssim(img, compressed,
				dynamic_range=compressed.max()-compressed.min())
			if abs(ss - target_ss) < abs(last_ss - target_ss):
				last_ss = ss
				k -= 1
			else:
				break	
	print "Best k found %r with ssim %r" % (k, last_ss)
	return compressed
开发者ID:mutaphore,项目名称:svd-image-compression,代码行数:57,代码来源:image_compression.py

示例6: test_ssim_image

def test_ssim_image():
    N = 100
    X = (np.random.random((N, N)) * 255).astype(np.uint8)
    Y = (np.random.random((N, N)) * 255).astype(np.uint8)

    S0 = ssim(X, X, win_size=3)
    assert_equal(S0, 1)

    S1 = ssim(X, Y, win_size=3)
    assert(S1 < 0.3)
开发者ID:lforet,项目名称:CoinVision,代码行数:10,代码来源:test_structural_similarity.py

示例7: test_ssim_grad

def test_ssim_grad():
    N = 30
    X = np.random.random((N, N)) * 255
    Y = np.random.random((N, N)) * 255

    f = ssim(X, Y, dynamic_range=255)
    g = ssim(X, Y, dynamic_range=255, gradient=True)

    assert f < 0.05
    assert g[0] < 0.05
    assert np.all(g[1] < 0.05)
开发者ID:ChrisBeaumont,项目名称:scikit-image,代码行数:11,代码来源:test_structural_similarity.py

示例8: find_flat

    def find_flat(self, image, flat):
        best = [0, 0]
        for f in range(flat.shape[2]):
            if cut:
                rms = ssim(image, flat[:, :, f])
            else:
                rms = ssim(image[a:c, b:d], flat[a:c, b:d, f])

            if rms > best[0]:
                best = [rms, f]

        arr = image / flat[:, :, best[1]]
        return arr
开发者ID:vrey01,项目名称:HardwareRepository,代码行数:13,代码来源:EMBLXrayImaging.py

示例9: do_all_metrics

def do_all_metrics(comparison_dict):
    
    pairs_lvl0 = [k for k in comparison_dict.iterkeys()]
    
    for p in pairs_lvl0:
        
        data_keys = [j for j in comparison_dict[p].iterkeys()]
        regex = re.compile('2')
        snow = [string for string in data_keys if re.match(regex, string)]
        
        comparison_dict[p]['MSE'] = round(mse(comparison_dict[p][data_keys[0]],
                                        comparison_dict[p][data_keys[1]]),3)
                                        
        comparison_dict[p]['SSIM'] = round(ssim(comparison_dict[p][data_keys[0]],
                                        comparison_dict[p][data_keys[1]]),3)
                                        
        comparison_dict[p]['MSE Map'] = (comparison_dict[p][data_keys[0]] - 
                                          comparison_dict[p][data_keys[1]])**2
                                          
        comparison_dict[p]['SSIM Map'] = ssim(comparison_dict[p][data_keys[0]], 
                                          comparison_dict[p][data_keys[1]],
                                            full = True)[1]
    
        comparison_dict[p]['CW-SSIM'] = cw_ssim(comparison_dict[p][data_keys[0]],
                                        comparison_dict[p][data_keys[1]], 40)[0]
                                        
        comparison_dict[p]['CW-SSIM Map'] = cw_ssim(comparison_dict[p][data_keys[0]],
                                        comparison_dict[p][data_keys[1]], 40)[1]
                                        
        comparison_dict[p]['GMS'] = gmsd(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[0]
                                        
        comparison_dict[p]['GMS Map'] = gmsd(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[1]

    
        comparison_dict[p][snow[0]+' DCT Map'] = discrete_cosine(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[0]
                                        
        comparison_dict[p][snow[1]+' DCT Map'] = discrete_cosine(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[1]
                                        
        comparison_dict[p][snow[0]+' DCT Curve'] = discrete_cosine(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[2]
                                        
        comparison_dict[p][snow[1]+' DCT Curve'] = discrete_cosine(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])[3]
                                        
                                        
        comparison_dict[p]['FSIM'] = feature_sim(comparison_dict[p][snow[0]],
                                        comparison_dict[p][snow[1]])
开发者ID:charparr,项目名称:tundra-snow,代码行数:51,代码来源:toolkit_master.py

示例10: test_ssim_dtype

def test_ssim_dtype():
    N = 30
    X = np.random.rand(N, N)
    Y = np.random.rand(N, N)

    S1 = ssim(X, Y)

    X = (X * 255).astype(np.uint8)
    Y = (X * 255).astype(np.uint8)

    S2 = ssim(X, Y)

    assert S1 < 0.1
    assert S2 < 0.1
开发者ID:TheArindham,项目名称:scikit-image,代码行数:14,代码来源:test_structural_similarity.py

示例11: test_ssim_multichannel_chelsea

def test_ssim_multichannel_chelsea():
    # color image example
    Xc = data.chelsea()
    sigma = 15.0
    Yc = np.clip(Xc + sigma * np.random.randn(*Xc.shape), 0, 255)
    Yc = Yc.astype(Xc.dtype)

    # multichannel result should be mean of the individual channel results
    mssim = ssim(Xc, Yc, multichannel=True)
    mssim_sep = [ssim(Yc[..., c], Xc[..., c]) for c in range(Xc.shape[-1])]
    assert_almost_equal(mssim, np.mean(mssim_sep))

    # ssim of image with itself should be 1.0
    assert_equal(ssim(Xc, Xc, multichannel=True), 1.0)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:14,代码来源:test_structural_similarity.py

示例12: test_ssim_dynamic_range_and_data_range

def test_ssim_dynamic_range_and_data_range():
    # Tests deprecation of "dynamic_range" in favor of "data_range"
    N = 30
    X = np.random.rand(N, N) * 255
    Y = np.random.rand(N, N) * 255

    with expected_warnings(
            '`dynamic_range` has been deprecated in favor of '
            '`data_range`. The `dynamic_range` keyword argument '
            'will be removed in v0.14'):
        out2 = ssim(X, Y, dynamic_range=255)

    out1 = ssim(X, Y, data_range=255)

    assert_equal(out1, out2)
开发者ID:noahstier,项目名称:scikit-image,代码行数:15,代码来源:test_structural_similarity.py

示例13: test_ssim_grad

def test_ssim_grad():
    N = 30
    X = np.random.rand(N, N) * 255
    Y = np.random.rand(N, N) * 255

    f = ssim(X, Y, data_range=255)
    g = ssim(X, Y, data_range=255, gradient=True)

    assert f < 0.05

    assert g[0] < 0.05
    assert np.all(g[1] < 0.05)

    mssim, grad, s = ssim(X, Y, data_range=255, gradient=True, full=True)
    assert np.all(grad < 0.05)
开发者ID:andreydung,项目名称:scikit-image,代码行数:15,代码来源:test_structural_similarity.py

示例14: compute_loss

def compute_loss(reconstructed_output, original, loss_type):
    """
    Computes the loss associated with an MR image slice 
    and a reconstruction of the slice after subsampling. 
    The loss function is specified by `loss_type`
    
    Parameters
    ------------
    reconstructed_output : np.ndarray
        The reconstructed MR image slice, represented as a 
        numpy array with datatype `np.float32`
    original : np.ndarray
        The original MR image slice (before subsampling),
        represented as a numpy array with datatype `np.float32`
    loss_type : str
        The type of loss to compute (either 'mse' or 'mae')

    Returns
    ------------
    float
        The specified loss computed between the
        reconstructed slice and the original slice
    """

    output = np.array(reconstructed_output, dtype=np.float64) / 255.0
    original = np.array(original, dtype=np.float64) / 255.0
    if loss_type == LOSS_TYPE_MSE:
        return np.mean((reconstructed_output - original)**2)
    elif loss_type == LOSS_TYPE_SSIM:
        return ssim(reconstructed_output, original)
    else:
        raise Exception("Attempted to compute an invalid loss!")
开发者ID:snowbhr06,项目名称:MRI-Reconstruction,代码行数:32,代码来源:test_net.py

示例15: compare_images

def compare_images(imageA, imageB, title, show_plot=True):
    # compute the mean squared error and structural similarity
    # index for the images
    m = mse(imageA, imageB)
    s = ssim(imageA, imageB)

    if show_plot:
        import matplotlib.pyplot as plt

        # setup the figure
        fig, ax = plt.subplots(1, 2)
        fig.suptitle("%s\nMSE: %.5f, SSIM: %.5f" % (title, m, s))

        # show first image
        ax[0].imshow(imageA, cmap=plt.cm.gray)
        ax[0].axis("off")

        # show the second image
        ax[1].imshow(imageB, cmap=plt.cm.gray)
        ax[1].axis("off")

        # show the images
        plt.show()

    return m, s
开发者ID:Eric-Rosenkrantz,项目名称:specfem2d,代码行数:25,代码来源:compare_two_images_to_compare_sensitivity_kernels.py


注:本文中的skimage.measure.ssim函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。