def gauss_filter(): header, y_cb_cr = bmp.readBmp(gauss_noise_filename) h, y_cb_cr_o = bmp.readBmp(original_file_y_cb_cr) sigmaRange = np.arange(0.0001, 1.1, 0.1) psnr = defaultdict(list) rRange = range(1, 10) legends = [] out_psnr = np.zeros((len(list(rRange)) + 1, (len(list(sigmaRange)) + 1))) out_psnr[1:, 0] = list(rRange) out_psnr[0, 1:] = list(sigmaRange) print('orig ', bmp.psnr(y_cb_cr_o[..., 0], y_cb_cr[..., 0])) for r in rRange: psnr = [] for i in sigmaRange: res = BmpFilters.BmpFilters.gauss_filter(y_cb_cr, r, i) ps = bmp.psnr(y_cb_cr_o[..., 0], res[..., 0]) res[..., 1] = res[..., 0] res[..., 2] = res[..., 0] bmp.writeBmp( gauss_filter_filename + "/gauss r = {0:.2f} d = {1:.2f}.bmp".format(r, i), header, res) psnr.append(ps) p = np.array(psnr) out_psnr[r, 1:] = p l, = plt.plot(list(sigmaRange), psnr, label=f'R = {r}') legends.append(l) plt.legend(handles=legends) plt.savefig(gauss_filter_filename + f"/psnr total.png") np.savetxt(gauss_filter_filename + '/psnr.csv', out_psnr, delimiter=',', fmt='%.2f')
def laplas(): header, rgb = bmp.readBmp(orig_filename) y_cb_cr = bmp.convertYCbCr(rgb) y_cb_cr_res = BmpFilters.BmpFilters.laplas_operator(y_cb_cr, 0) y_cb_cr_res += 128 np.putmask(y_cb_cr_res, y_cb_cr_res < 0, 0) np.putmask(y_cb_cr_res, y_cb_cr_res > 255, 255) y_cb_cr_res[..., 1] = y_cb_cr_res[..., 0] y_cb_cr_res[..., 2] = y_cb_cr_res[..., 0] y_cb_cr[..., 1] = y_cb_cr[..., 0] y_cb_cr[..., 2] = y_cb_cr[..., 0] bmp.writeBmp(laplas_folder + "/laplas.bmp", header, y_cb_cr_res) bmp.writeBmp(laplas_folder + "/orig.bmp", header, y_cb_cr)
def median(): header, y_cb_cr = bmp.readBmp(gauss_noise_filename) header_o, y_cb_cr_o = bmp.readBmp(original_file_y_cb_cr) psnr = [] print('orig', bmp.psnr(y_cb_cr_o[..., 0], y_cb_cr[..., 0])) x = range(1, 10) for r in x: res = BmpFilters.BmpFilters.median_filter(y_cb_cr, r * 2 + 1) res[..., 1] = res[..., 0] res[..., 2] = res[..., 0] psnr.append(bmp.psnr(y_cb_cr_o[..., 0], res[..., 0])) bmp.writeBmp(median_folder + f"/median r = {r}.bmp", header, res) np.savetxt(median_folder + "/psnr.csv", np.array(psnr).T, delimiter=',', fmt='%.2f') plt.plot(list(x), psnr) plt.savefig(median_folder + "/psnr.png")
header, rgb = bmp.readBmp(in_file) a = rgb[...][...][0] - rgb[...][...][1] print(np.max(a)) sys.exit(0) y_cb_cr = bmp.convertYCbCr(rgb) cbDecimated = bmp.decimationByDeletingEven(y_cb_cr[..., 1], 4) crDecimated = bmp.decimationByDeletingEven(y_cb_cr[..., 2], 4) cbRecovered = bmp.recoverDecimationByDeletingEven(cbDecimated, 4) crRecovered = bmp.recoverDecimationByDeletingEven(crDecimated, 4) y_cb_cr[..., 1] = cbRecovered y_cb_cr[..., 2] = crRecovered rgb2 = bmp.inverseConvertYCbCr(y_cb_cr) bmp.writeBmp(res_file_path + "testRec.bmp", header, rgb2) print(bmp.psnr(rgb[..., 0], rgb2[..., 0])) print(bmp.psnr(rgb[..., 1], rgb2[..., 1])) print(bmp.psnr(rgb[..., 2], rgb2[..., 2])) sys.stdout = open('console.txt', 'w') b = rgb[..., 0] g = rgb[..., 1] r = rgb[..., 2] # [4] b getAutoCor(r, "red") getAutoCor(g, "green") getAutoCor(b, "blue") # 7 [y_cb_cr] y_cb_cr = bmp.convertYCbCr(rgb)