コード例 #1
0
def iqa_results(im1, im2):
    print('The MSE is: {:.2f}'.format(
        dip.MSE(cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY),
                cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY))))
    print('The PSNR is: {:.2f}'.format(
        dip.PSNR(cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY),
                 cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY),
                 np.amax(cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)))))
コード例 #2
0
def get_motion(img, previous_frame, substractor):
    """This function determines whether there is movement or not based on the previous frame and current image."""

    motion = substractor.apply(img)
    previous_motion = substractor.apply(previous_frame)

    motion_measure = (dip.MSE(previous_motion, motion) * 1000)

    if motion_measure > 20:
        is_moving = True
    else:
        is_moving = False

    return is_moving
コード例 #3
0
            denominator = denominator + h(k, l)
    result = nominator / denominator
    return result


#Gaussian Filter
sigma1 = 1
L = 3
h1 = lambda k, l: np.exp(-(k * k + l * l) / (2 * sigma1 * sigma1))
gext = np.pad(g, (L, L), mode='symmetric')
output1 = np.zeros(g.shape)
for m in range(output1.shape[1]):
    for n in range(output1.shape[0]):
        output1[n, m] = filter(h1, gext, m, n, L)
print('MSE1')
print(dip.MSE(f, output1))
#Range (or Sigma) Filter
rho1 = 40
L = 3
output2 = np.zeros(g.shape)
gext = np.pad(g, (L, L), mode='symmetric')
for m in range(output2.shape[1]):
    for n in range(output2.shape[0]):
        nominator = 0
        denominator = 0
        for k in range(-L, L + 1):
            for l in range(-L, L + 1):
                nkl = float(gext[n + L - k, m + L - l])
                nnm = float(gext[n + L, m + L])
                nominator = nominator + np.exp(-1 / 2 *
                                               (((nkl - nnm) / rho1)**2)) * nkl
コード例 #4
0
im_DCT_reconstructed = dip.block_process(im_DCT_quantized_reconstructed,
                                         dequantize, block_size)

# STEP 13: Inverse DCT
# ============================ EDIT THIS PART =================================
im_reconstructed = dip.block_process(im_DCT_reconstructed, dip.idct_2d,
                                     block_size)

# STEP 14: Add 127 to every pixel
# ============================ EDIT THIS PART =================================
im_reconstructed = im_reconstructed + 127

# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
dip.subplot(2, 2, 2)
dip.imshow(im_reconstructed, 'gray')
dip.title('Reconstructed image')

# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
im = im + 127

# STEP 15: Calculating MSE and PSNR
# ============================ EDIT THIS PART =================================
MSE = dip.MSE(im, im_reconstructed)
PSNR = dip.PSNR(im, im_reconstructed, np.max(im))

# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
print("MSE = {:.2f}".format(MSE))
print("PSNR = {:.2f} dB".format(PSNR))

dip.show()
コード例 #5
0
dip.title('k = 24')

dip.figure(2)
dip.subplot(1, 3, 1)
dip.imshow(diff_1, 'gray')
dip.colorbar()
dip.title('k = 1')
dip.subplot(1, 3, 2)
dip.imshow(diff_12, 'gray')
dip.colorbar()
dip.title('k = 12')
dip.subplot(1, 3, 3)
dip.imshow(diff_24, 'gray')
dip.colorbar()
dip.title('k = 24')

plt.figure(3)
x = []
y = []
M, N = X.shape
for i in range(64):
    print(i)
    x.append(i)
    X_hat = KLT_blocks(X, i + 1, 10)
    MSE = dip.MSE(X, X_hat)
    y.append(MSE)
plt.plot(x, y)
plt.xlabel('k')
plt.ylabel('MSE')
plt.show()
dip.show()