• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python measure.ssim函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: compare

def compare(file1, file2):
    image1 = io.imread(file1, as_grey = True)
    image2 = io.imread(file2, as_grey = True)
    image1 = feature.canny(image1)
    image2 = feature.canny(image2)

    return ssim(image1, image2)
开发者ID:tabletenniser,项目名称:thesis,代码行数:7,代码来源:compare_image_edge_detection.py


示例17: compare_images

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

    return round(m,2), round(s,2)
开发者ID:ChrisDan9,项目名称:Raspi-Cam,代码行数:7,代码来源:compare.py


示例18: compare_images

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

    # setup the figure
    fig = plt.figure(title)
    plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s))
    #plt.suptitle("MSE: %.2f, SSIM: ??" % (m))
    # show first image
    ax = fig.add_subplot(1, 2, 1)
    plt.imshow(imageA, cmap=plt.cm.gray)
    plt.axis("off")

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

    # show the images
    plt.show()
开发者ID:Callwoola,项目名称:picture-compare,代码行数:25,代码来源:testOne.py


示例19: matchFindNonORB

def matchFindNonORB(TestImName, RefImName,TestIm,RefIm, Method):
	""" Inputs:  two strings: an image name, TestImName, and the name of a reference image, RefImName,
				  a string containing the specified Method used to compare the images
				  an optional parameter: the number of distances, NumDist, which will perform the operations on a subset of the information provided
						Any number greater  than 0 for NumDist will truncate the distances
		Outputs: a number, answer, that comes from the comparison method used between the two images """

	if TestImName == RefImName: #if an image is tested against itself, let's save time by returning a value eliminating it from contention...
		if Method == 'ssim': #for these methods, higher is better, so we return a huge value
			return 1000000
		else: #otherwise, return -1, a number lower than any value we should see...
			return -1

	answer = 0	
	"""Now, the user chooses the method, and the answer gets returned accordingly """	
	if Method == 'mse': #mean squared error
		answer = mse(TestIm,RefIm)
	elif Method == 'ssim': #structural similarity index
		answer = ssim(TestIm,RefIm)
	elif Method == 'rms': #root means squared difference between pixels
		answer = rms(TestIm,RefIm)
	elif Method == 'ccv2':
		answer = ccv2.main(TestImName,RefImName)


	#print TestIm, answer 
	return answer
开发者ID:JMedina,项目名称:VA3DR,代码行数:27,代码来源:ICE_normal.py


示例20: cal_similarity

def cal_similarity(image_name, image_files, directory):
    # rdb.set_trace()
    original = io.imread(os.path.join(directory, image_name))
    original = rgb2gray(original)
    similarity = {}
    for image in image_files:
        if image_name != image:
            compare = rgb2gray(io.imread(os.path.join(directory, image)))
            sim = ssim(original, compare)
            if len(similarity) >= 2:
                min_ssim = min(similarity, key=similarity.get)
                if sim > similarity[min_ssim]:
                    del similarity[min_ssim]
                else:
                    continue
            similarity[image] = sim

            # update the cache
            if image in redis_cache.keys():
                image_similarity = pickle.loads(redis_cache.get(image))
                if len(image_similarity) < 2:
                    image_similarity[image_name] = sim
                    redis_cache.set(image, pickle.dumps(image_similarity, pickle.HIGHEST_PROTOCOL))
                min_ssim = min(image_similarity, key=image_similarity.get)
                if sim > image_similarity[min_ssim]:
                    del image_similarity[min_ssim]
                    image_similarity[image_name] = sim
                    redis_cache.set(image, pickle.dumps(image_similarity, pickle.HIGHEST_PROTOCOL))
    return similarity
开发者ID:owen-hzy,项目名称:scalable-album,代码行数:29,代码来源:tasks.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python measure.CircleModel类代码示例发布时间:2022-05-27
下一篇:
Python measure.regionprops函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap