def main(): # AvilaDomenech2019OQR Instances wm = AvilaDomenech2019OQR('password') try: # Load cover image root = Tk() root.filename = filedialog.askopenfilename( initialdir="static/", title="Select file", filetypes=(("png files", "*.jpg"), ("jpg files", "*.png"), ("all files", "*.*"))) cover_image = Image.open(root.filename).convert('RGB') root.destroy() watermarked_image = wm.insert(cover_image) watermarked_image.save("static/watermarked_image.png") # PSNR cover_image = Image.open(root.filename) stego_image = Image.open("static/watermarked_image.png").convert('RGB') print("Calculando PSNR") print(Evaluations().PSNR_RGB(cover_image, stego_image)) # Watermark extracting watermark_extracted = wm.extract(watermarked_image) # Save watermark image dir_water_im = "watermark_" + root.filename.split( "/")[-1][:-4] + ".bmp" watermark_extracted.save("static/" + dir_water_im) except Exception as e: root.destroy() print("Error: ", e) print("The image file was not loaded")
def main(): # Shivani2017F Instances wm = Shivani2017F() try: # Load cover image root = Tk() root.filename = filedialog.askopenfilename(initialdir="static/", title="Select file", filetypes=( ("all files", "*.*"), ("png files", "*.png"), ("jpg files", "*.jpg"), )) cover_image = Image.open(root.filename).convert('RGB') root.destroy() watermarked_image = wm.insert(cover_image) watermarked_image.save("static/watermarked_image.png") # PSNR cover_image = Image.open(root.filename) stego_image = Image.open("static/watermarked_image.png").convert('RGB') print("Calculando PSNR") print(Evaluations().PSNR_RGB(cover_image, stego_image)) except Exception as e: root.destroy() print("Error: ", e) print("The image file was not loaded")
def main(): eva = Evaluations() # Directory dir = "D:/DataSets" # Instance wm = Shivani2017R() try: # Load cover image root = Tk() root.filename = filedialog.askopenfilename( initialdir=dir + "/", title="Select file", filetypes=(("jpg files", "*.jpg"), ("png files", "*.png"), ("all files", "*.*"))) except Exception as e: print("Error: ", e) print("The image file was not loaded") root.destroy() path = root.filename cover_image = Image.open(path) # Insert watermarked_image = wm.insert(cover_image) # Save watermarked image dir_water_im = "watermarked_" + path.split("/")[-1][:-4] + ".bmp" watermarked_image.save("static/" + dir_water_im) # Show PSNR cover = Image.open(path) print(" ") print("PSNR: ", eva.PSNR_RGB(cover, watermarked_image)) # Watermark extracting watermark_extracted = wm.extract(watermarked_image) # Save watermark image dir_water_im = "watermark_" + path.split("/")[-1][:-4] + ".bmp" watermark_extracted.save("static/" + dir_water_im)
def procesar(block_path, watermark_bit, coef, delta): # Cargando imagen block_image = Image.open(block_path) # Convirtiendola a ndarray block_array = np.asarray(block_image) block_rgb_array = marcar(block_array, watermark_bit, coef, delta) watermarked_image_without_noise = Image.fromarray(block_rgb_array) # Calculando el PSNR psnr_img_watermarked_without_noise = Evaluations().PSNR_RGB( Image.open(block_path), watermarked_image_without_noise) # Extrayendo watermark bit # Convirtiendola a ndarray block_array = np.asarray(watermarked_image_without_noise) extract_without_noise = extraer(block_array, coef, delta) if watermark_bit == extract_without_noise: ber_without_noise = 1 else: ber_without_noise = 0 # Aplicando ruido watermarked_with_noise_path = block_path[:-4] + 'wnoised.jpg' watermarked_image_without_noise.save(watermarked_with_noise_path, quality=25, optimice=True) # Extrayendo watermark bit watermarked_image_with_noise = Image.open(watermarked_with_noise_path) # Convirtiendola a ndarray block_array = np.asarray(watermarked_image_with_noise) extract_with_noise = extraer(block_array, coef, delta) if watermark_bit == extract_with_noise: ber_with_noise = 1 else: ber_with_noise = 0 return { 'psnr_img_watermarked_without_noise': psnr_img_watermarked_without_noise, 'ber_without_noise': ber_without_noise, 'ber_with_noise': ber_with_noise }
def run_main(): eva = Evaluations() wm = Shivani2017R() image_paths = glob.glob('static/dataset/*.jpg') # Fichero a guardar resultados f_psnr = open("psnr.txt", "w") f_psnr.close() f_ber25 = open("ber25.txt", "w") f_ber25.close() f_ber50 = open("ber50.txt", "w") f_ber50.close() f_ber75 = open("ber75.txt", "w") f_ber75.close() f_berWithout = open("berWithout.txt", "w") f_berWithout.close() f_berGueztli = open("berGuetzli.txt", "w") f_berGueztli.close() for cover_image_url in image_paths: name = image_name(cover_image_url) f_psnr = open("psnr.txt", "a+") f_ber25 = open("ber25.txt", "a+") f_ber50 = open("ber50.txt", "a+") f_ber75 = open("ber75.txt", "a+") f_berWithout = open("berWithout.txt", "a+") f_berGuetzli = open("berGuetzli.txt", "a+") # Set print("Iniciando...") # Cargando imagen cover_image = Image.open(cover_image_url) # Insert watermarked_image_without_noise = wm.insert(cover_image) # Almacenando imagen marcada watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + "_without_noise.png") # Calculando PSNR print("Calculando PSNR...") watermarked_image_without_noise = Image.open( "static/experimento/watermarked_" + name + "_without_noise.png") cover_image = Image.open(cover_image_url) psnr_img_watermarked_without_noise = eva.PSNR_RGB( cover_image, watermarked_image_without_noise) f_psnr.write("%f," % (psnr_img_watermarked_without_noise)) # Aplicando ruido JPEG 25, 50, 75 % y Guetzli print("Aplicando ruido JPEG20, JPEG50 JPEG75 y Guetzli") watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + "_with_jpeg25.jpg", quality=25, optimice=True) watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + "_with_jpeg50.jpg", quality=50, optimice=True) watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + "_with_jpeg75.jpg", quality=75, optimice=True) # Falta guetzli ########################################################## # Extrayendo de Without print("Extrayendo de Without") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + "_without_noise.png") # Watermark extracting watermark_extracted = wm.extract(watermarked_image_with_noise) watermark_extracted.save( "static/experimento/watermark_" + name + "_without_noise.png") print("Calculando BER without noise") # Cargando watermark watermark = wm.watermark ber_without_noise= eva.BER_A( misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_berWithout.write("%f," % (ber_without_noise)) ########################################################## # Extrayendo de jpeg25 print("Extrayendo de JPEG25") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + "_with_jpeg25.jpg") # Watermark extracting watermark_extracted = wm.extract(watermarked_image_with_noise) watermark_extracted.save( "static/experimento/watermark_" + name + "_with_jpeg25.png") print("Calculando BER with noise JPEG25") # Cargando watermark watermark = wm.watermark ber_with_noise_jpeg25 = eva.BER_A( misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber25.write("%f," % (ber_with_noise_jpeg25)) ################################################################ # Extrayendo de jpeg50 print("Extrayendo de JPEG50") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + "_with_jpeg50.jpg") # Watermark extracting watermark_extracted = wm.extract(watermarked_image_with_noise) watermark_extracted.save( "static/experimento/watermark_" + name + "_with_jpeg50.png") print("Calculando BER with noise JPEG50") # Cargando watermark watermark = wm.watermark ber_with_noise_jpeg50 = eva.BER_A( misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber50.write("%f," % (ber_with_noise_jpeg50)) ############################################################# # Extrayendo de jpeg75 print("Extrayendo de JPEG75") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + "_with_jpeg75.jpg") # Watermark extracting watermark_extracted = wm.extract(watermarked_image_with_noise) watermark_extracted.save( "static/experimento/watermark_" + name + "_with_jpeg75.png") print("Calculando BER with noise JPEG75") # Cargando watermark watermark = wm.watermark ber_with_noise_jpeg75 = eva.BER_A( misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber75.write("%f," % (ber_with_noise_jpeg75)) print('******************************************************') f_psnr.close() f_ber25.close() f_ber50.close() f_ber75.close() f_berWithout.close() f_berGuetzli.close()
def run_main(): eva = Evaluations() path = 'static/csg562-003.jpg' cover_image = Image.open(path).convert('RGB') name = image_name(path) watermark = Image.open("static/Watermarking.png").convert("1") size_to_evaluate = [8, 16, 32, 64, 128, 256] # Fichero a guardar resultados f_psnr = open("psnr.txt", "w") f_psnr.close() f_ber25 = open("ber25.txt", "w") f_ber25.close() f_ber50 = open("ber50.txt", "w") f_ber50.close() f_ber75 = open("ber75.txt", "w") f_ber75.close() f_berWithout = open("berWithout.txt", "w") f_berWithout.close() f_berGueztli = open("berGuetzli.txt", "w") f_berGueztli.close() for w_size in size_to_evaluate: # Instancias wmr = Liu2018Ra('password', watermark.resize((w_size, w_size))) wmf = Liu2018F('password') f_psnr = open("psnr.txt", "a+") f_ber25 = open("ber25.txt", "a+") f_ber50 = open("ber50.txt", "a+") f_ber75 = open("ber75.txt", "a+") f_berWithout = open("berWithout.txt", "a+") f_berGuetzli = open("berGuetzli.txt", "a+") # Set print("Iniciando...") # Insert watermarked_image_without_noise = wmr.insert(cover_image) watermarked_image_without_noise = wmf.insert( watermarked_image_without_noise) # Almacenando imagen marcada watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + str(w_size) + "_without_noise.png") # Calculando PSNR print("Calculando PSNR...") watermarked_image_without_noise = Image.open( "static/experimento/watermarked_" + name + str(w_size) + "_without_noise.png") cover_image = Image.open(path) psnr_img_watermarked_without_noise = eva.PSNR_RGB( cover_image, watermarked_image_without_noise) f_psnr.write("%f," % (psnr_img_watermarked_without_noise)) # Aplicando ruido JPEG 25, 50, 75 % y Guetzli print("Aplicando ruido JPEG20, JPEG50 JPEG75 y Guetzli") watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg25.jpg", quality=25, optimice=True) watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg50.jpg", quality=50, optimice=True) watermarked_image_without_noise.save( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg75.jpg", quality=75, optimice=True) # Falta guetzli ########################################################## # Extrayendo de Without print("Extrayendo de Without") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + str(w_size) + "_without_noise.png") # Watermark extracting watermark_extracted = wmr.extract(watermarked_image_with_noise) watermark_extracted.save("static/experimento/watermark_" + name + str(w_size) + "_without_noise.png") print("Calculando BER without noise") # Cargando watermark watermark = Image.open("static/Watermarking.png").resize( (w_size, w_size)).convert("1") ber_without_noise = eva.BER_A(misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_berWithout.write("%f," % (ber_without_noise)) ########################################################## # Extrayendo de jpeg25 print("Extrayendo de JPEG25") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg25.jpg") # Watermark extracting watermark_extracted = wmr.extract(watermarked_image_with_noise) watermark_extracted.save("static/experimento/watermark_" + name + str(w_size) + "_with_jpeg25.png") print("Calculando BER with noise JPEG25") # Cargando watermark watermark = Image.open("static/Watermarking.png").resize( (w_size, w_size)).convert("1") ber_with_noise_jpeg25 = eva.BER_A(misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber25.write("%f," % (ber_with_noise_jpeg25)) ################################################################ # Extrayendo de jpeg50 print("Extrayendo de JPEG50") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg50.jpg") # Watermark extracting watermark_extracted = wmr.extract(watermarked_image_with_noise) watermark_extracted.save("static/experimento/watermark_" + name + str(w_size) + "_with_jpeg50.png") print("Calculando BER with noise JPEG50") # Cargando watermark watermark = Image.open("static/Watermarking.png").resize( (w_size, w_size)).convert("1") ber_with_noise_jpeg50 = eva.BER_A(misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber50.write("%f," % (ber_with_noise_jpeg50)) ############################################################# # Extrayendo de jpeg75 print("Extrayendo de JPEG75") watermarked_image_with_noise = Image.open( "static/experimento/watermarked_" + name + str(w_size) + "_with_jpeg75.jpg") # Watermark extracting watermark_extracted = wmr.extract(watermarked_image_with_noise) watermark_extracted.save("static/experimento/watermark_" + name + str(w_size) + "_with_jpeg75.png") print("Calculando BER with noise JPEG75") # Cargando watermark watermark = Image.open("static/Watermarking.png").resize( (w_size, w_size)).convert("1") ber_with_noise_jpeg75 = eva.BER_A(misc.fromimage(watermark), misc.fromimage(watermark_extracted)) f_ber75.write("%f," % (ber_with_noise_jpeg75)) print('******************************************************') f_psnr.close() f_ber25.close() f_ber50.close() f_ber75.close() f_berWithout.close() f_berGuetzli.close()