Beispiel #1
0
#np.random.seed(15)
#mixing_matrix = np.random.rand(2,2)
mixing_matrix = [[2.5, 0.7], [0.7, 2.5]]
print("mixing_matrix = ", mixing_matrix)
#[[0.5507979  0.70814782] [0.29090474 0.51082761]]

for i in range(5):
    print(i + 1)
    # load and mix images
    source1, source2 = load_images(
        '../images_hard/set' + str(i + 1) + '_pic1.png',
        '../images_hard/set' + str(i + 1) + '_pic2.png',
        256,
        show_images=False)
    sources, mixed_sources = linear_mixture(
        source1, source2, mixing_matrix=mixing_matrix,
        show_images=False)  #mixing_matrix = mixing_matrix,

    # Here begins the algorithm
    # whitening processing. It's important
    X = whiten_projection(mixed_sources)
    (sdr_ref, sir_ref, sar,
     perm) = mmetrics.bss_eval_sources(np.asarray(sources), np.asarray(X))
    print('The mean value of the reference SDR is: ', np.mean(sdr_ref))
    reference_sdr.append(np.mean(sdr_ref))

    Se = np.copy(X)
    Se_old = np.copy(Se)
    for it in np.arange(max_it):
        # 1. denoising
        Se = Dic_proj_double(Se_old, num_coeff, sigma)
Beispiel #2
0
plt.subplot(235)
plt.imshow(source2_hsv[:,:,1])#, cmap = 'hsv')
plt.axis('off')

plt.subplot(236)
plt.imshow(source2_hsv[:,:,2])#, cmap = 'hsv')
plt.axis('off')
plt.tight_layout()
#plt.savefig("sources_hsv_set5.png")
plt.show()

theta = np.radians(d)
mixing_matrix = [[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]

source_channel_1, mixture_channel_1 = linear_mixture(image1[:,:,0], image2[:,:,0], mixing_matrix, False)
source_channel_2, mixture_channel_2 = linear_mixture(image1[:,:,1], image2[:,:,1], mixing_matrix, False)
source_channel_3, mixture_channel_3 = linear_mixture(image1[:,:,2], image2[:,:,2], mixing_matrix, False)

print('channel R of mixture, min, max = ', mixture_channel_1.min(), mixture_channel_1.max())
print('channel G of mixture, min, max = ', mixture_channel_2.min(), mixture_channel_2.max())
print('channel B of mixture, min, max = ', mixture_channel_3.min(), mixture_channel_3.max())

mixture1 = np.zeros_like(image1)
mixture2 = np.zeros_like(image2)
mixture1[:,:,0], mixture2[:,:,0] =  unflatten(mixture_channel_1, image_size)
mixture1[:,:,1], mixture2[:,:,1] =  unflatten(mixture_channel_2, image_size)
mixture1[:,:,2], mixture2[:,:,2] =  unflatten(mixture_channel_3, image_size)

plt.figure()
plt.suptitle('The mixtures')
    '\nSSIM of source 1 with its noisy one =',
    ssim(source1,
         noisy_image1,
         data_range=noisy_image1.max() - noisy_image1.min()))
print(
    'SSIM of source 2 with its noisy one =',
    ssim(source2,
         noisy_image2,
         data_range=noisy_image2.max() - noisy_image2.min()))

# tv projection
#estimated_image1 = denoise_tv_chambolle(noisy_image1, weight = 0.01, multichannel=False)
#estimated_image2 = denoise_tv_chambolle(noisy_image2, weight = 0.01, multichannel=False)
""" Dictionary part:"""
# mix the sources
sources, mixtures = linear_mixture(source1, source2, show_images=False)

mixture1, mixture2 = unflatten(mixtures, image_size)
print('\nSSIM of source 1 with its mixture =',
      ssim(source1, mixture1, data_range=mixture1.max() - mixture1.min()))
print('SSIM of source 2 with its mixture =',
      ssim(source2, mixture2, data_range=mixture2.max() - mixture2.min()))

# whiten the mixtures
X = whiten_projection(mixtures)
mixture1, mixture2 = unflatten(X, image_size)
print('\nSSIM of source 1 with its whitened mixture =',
      ssim(source1, mixture1, data_range=mixture1.max() - mixture1.min()))
print('SSIM of source 2 with its whitened mixture =',
      ssim(source2, mixture2, data_range=mixture2.max() - mixture2.min()))
plt.show()
"""
plt.figure()
plt.hist(image1[:,:,0].flatten(), bins = 20, color = 'red', alpha = 0.5, label = 'channel R')
plt.hist(image1[:,:,1].flatten(), bins = 20, color = 'green', alpha = 0.5, label = 'channel G')
plt.hist(image1[:,:,2].flatten(), bins = 20, color = 'blue', alpha = 0.5, label = 'channel B')
plt.legend()
plt.show()"""

theta = np.radians(d)
mixing_matrix = [[np.cos(theta), -np.sin(theta)],
                 [np.sin(theta), np.cos(theta)]]

for i in np.arange(3):
    print("Channel ", i + 1)
    source_channel_i, mixture_channel_i = linear_mixture(
        image1[:, :, i], image2[:, :, i], mixing_matrix, False)
    if i == 0:
        mixture_channel_1 = mixture_channel_i
    if i == 1:
        mixture_channel_2 = mixture_channel_i
    if i == 2:
        mixture_channel_3 = mixture_channel_i

    X_i, W_i = whiten_projection(mixture_channel_i)
    B_i = np.dot(W_i, mixing_matrix)
    (sdr_ref, sir_ref, sar,
     perm) = mmetrics.bss_eval_sources(source_channel_i, X_i)
    print('The mean value of the reference SDR is: ', np.mean(sdr_ref), perm)
    if np.array_equal(perm, [[1], [0]]):
        permutation = True
all_kurtosis_mixtures = []
all_skewness_mixtures = []
all_kurtosis_estimated = []
all_skewness_estimated = []
all_rdc = []
all_sdr = []
all_sdr_improved = []

for i in range(15):
    print("Set = ", i + 1)
    source1, source2 = load_images('./images/set' + str(i + 1) + '_pic1.png',
                                   './images/set' + str(i + 1) + '_pic2.png',
                                   n,
                                   show_images=False)
    S, X = linear_mixture(source1,
                          source2,
                          mixing_matrix=mixing_matrix,
                          show_images=False)

    #Reference SDR
    (sdr_ref, sir_ref, sar,
     perm) = mmetrics.bss_eval_sources(np.asarray(S), np.asarray(X))
    print('The mean value of the reference SDR is: ', np.mean(sdr_ref))

    #RDC of sources
    rdc_i = rdc(S[0, :], S[1, :])
    all_rdc.append(rdc_i)
    print("rdc of sources = ", rdc_i)

    #Kurtosis of sources
    kurtosis_i = mean_kurtosis(S)
    all_kurtosis_sources.append(kurtosis_i)