# Get all the images for file in files: img = cv2.imread(os.sep.join([r, file])) if img is not None: images.append(img) height, width = img.shape[:2] else: print("%s not found." % (file)) images = np.array(images) images.shape ## # 2. Inital Watermark Detection ## gx, gy = estimate_watermark(images) est = poisson_reconstruct(gx, gy) gx_manual_crop = gx[(height-constants.wmY):height, (width-constants.wmX):width] gy_manual_crop = gy[(height-constants.wmY):height, (width-constants.wmX):width] est_manual_crop = poisson_reconstruct(gx_manual_crop, gy_manual_crop) cropped_gx, cropped_gy = crop_watermark(gx_manual_crop, gy_manual_crop) est_auto_crop = poisson_reconstruct(cropped_gx, cropped_gy) with open('cropped.npz', 'wb') as f: np.savez(f, cropped_gx=cropped_gx, cropped_gy=cropped_gy) img = cv2.imread('images/fotolia_processed/25_3_018.jpg') start, rect = watermark_detector(img, cropped_gx, cropped_gy)
# basics import numpy as np np.set_printoptions(threshold=np.nan) import matplotlib.pyplot as plt # customs from src.estimate_watermark import * from src.preprocess import * from src.image_crawler import * from src.watermark_reconstruct import * gx, gy, gxlist, gylist = estimate_watermark('ref_inputs') # est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0]) cropped_gx, cropped_gy = crop_watermark(gx, gy) W_m = poisson_reconstruct(cropped_gx, cropped_gy) # random photo img = cv2.imread('ref_inputs/fotolia_168668150.jpg') im, start, end = watermark_detector(img, cropped_gx, cropped_gy) plt.imshow(cv2.cvtColor(im, cv2.COLOR_BGR2RGB)) plt.show() # we don't need the others... exit() # We are done with watermark estimation # W_m is the cropped watermark num_images = len(gxlist)
return img[:, :, [2, 1, 0]] ''' Ground Truth values alpha -> coco_dataset/alpha.png copyright -> coco_dataset/copyright.png c = .45 Experiments: Threshold for estimating initial alpha -> 153, and then subtract 1 from alpha ''' if __name__ == "__main__": # watermark = cv2.imread('coco_dataset/watermark.png') # alpha = get_alpha_matte(watermark) foldername = os.path.join(IMAGE_FOLDER, IMG_PROCESSED_LOC) gx, gy, gxlist, gylist = estimate_watermark(foldername) # est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0]) cropped_gx, cropped_gy = crop_watermark(gx, gy) W_m = poisson_reconstruct(cropped_gx, cropped_gy, num_iters=5000) # random photo img = cv2.imread(os.path.join(foldername, '000000051008.jpg')) im, start, end = watermark_detector(img, cropped_gx, cropped_gy) num_images = len(gxlist) J, img_paths = get_cropped_images(foldername, num_images, start, end, cropped_gx.shape) # get a random subset of J idx = [ 389, 144, 147, 468, 423, 92, 3, 354, 196, 53, 470, 445, 314, 349, 105,
# ---------------------------------------------------------------------------------------------------------------------- # INITIAL WATERMARK ESTIMATE & DETECTION ------------------------------------------------------------------------------- # Thresholds ----------------------------------------------------------------------------------------------------------- wm_crop_trh = 0.03 wm_detector_wm_thr = 0.03 wm_detector_img_thr = 0.3 wm_detector_tr_thr = 0.01 # ---------------------------------------------------------------------------------------------------------------------- J = read_images(dir_images) for i in range(1): images = preprocess(J, image_size) # images.update(preprocess(J, image_size, 'constant')) Wm_x, Wm_y, num_images = estimate_watermark(images) # crop watermark area and get cropped gradient cropped_Wm_x, cropped_Wm_y = crop_watermark_ignore_borders( Wm_x, Wm_y, threshold=wm_crop_trh) # reconstruct watermark image with poisson W_m = poisson_reconstruct2(cropped_Wm_x, cropped_Wm_y) cv2.imwrite( (os.sep.join([os.path.abspath(res_dir), 'watermark_whole.jpg'])), poisson_reconstruct2(Wm_x, Wm_y)) # # detect watermark on random photo # img_sample = rnd.choice(images) # # img_sample = cv2.imread(os.path.join(dir_images, img_name)) # img_marked, wm_start, wm_end = watermark_detector(img_sample, cropped_Wm_x, cropped_Wm_y)
# basics import numpy as np np.set_printoptions(threshold=np.nan) import matplotlib.pyplot as plt # customs from src.estimate_watermark import * from src.preprocess import * from src.image_crawler import * from src.watermark_reconstruct import * gx, gy, gxlist, gylist = estimate_watermark( 'sources/paired_train-wmark_cifar10_wmark_32x32_tile_cifar10_transpair_noise_ResNet_l1_binary-cross-entropy_cross-entropy_64_30_0.01_0.001_0.001_0_0_2.0_1.0_1.0_10.0_1.0' ) # est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0]) cropped_gx, cropped_gy = crop_watermark(gx, gy) W_m = poisson_reconstruct(cropped_gx, cropped_gy) # random photo img = cv2.imread( ('sources/paired_train-wmark_cifar10_wmark_32x32_tile_cifar10_' 'transpair_noise_ResNet_l1_binary-cross-entropy_cross-entropy_' '64_30_0.01_0.001_0.001_0_0_2.0_1.0_1.0_10.0_1.0/0_4.png')) im, start, end = watermark_detector(img, cropped_gx, cropped_gy) # plot the watermarked area plt.imshow(cv2.cvtColor(im, cv2.COLOR_BGR2RGB)) plt.show() # we don't need the others
import cv2 import os from src.estimate_watermark import * from src.preprocess import * from src.image_crawler import * from src.watermark_reconstruct import * gx, gy, gxlist, gylist = estimate_watermark('./images/fotolia_processed/8023974513') # est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0]) cropped_gx, cropped_gy = crop_watermark(gx, gy) W_m = poisson_reconstruct(cropped_gx, cropped_gy) # random photo # img = cv2.imread('images/fotolia_processed/fotolia_137840668.jpg') img = cv2.imread('images/fotolia_processed/8023974513/ahdx_8024936287_14.jpg') im, start, end = watermark_detector(img, cropped_gx, cropped_gy) plt.imshow(im) plt.show() # We are done with watermark estimation # W_m is the cropped watermark num_images = len(gxlist) J, img_paths = get_cropped_images( 'images/fotolia_processed/8023974513', num_images, start, end, cropped_gx.shape) # get a random subset of J idx = [389, 144, 147, 468, 423, 92, 3, 354, 196, 53, 470, 445, 314, 349, 105, 366, 56, 168, 351, 15, 465, 368, 90, 96, 202, 54, 295, 137, 17, 79, 214, 413, 454, 305, 187, 4, 458, 330, 290, 73, 220, 118, 125, 180, 247, 243, 257, 194, 117, 320, 104, 252, 87, 95, 228, 324, 271, 398, 334, 148, 425, 190, 78, 151, 34, 310, 122, 376, 102, 260] idx = idx[:25] # Wm = (255*PlotImage(W_m)) Wm = W_m - W_m.min()
import cv2 from src.estimate_watermark import * from src.preprocess import * from src.image_crawler import * from src.watermark_reconstruct import * gx, gy, gxlist, gylist = estimate_watermark('./images/fotolia_processed') # est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0]) cropped_gx, cropped_gy = crop_watermark(gx, gy) W_m = poisson_reconstruct(cropped_gx, cropped_gy) # random photo img = cv2.imread('images/fotolia_processed/fotolia_137840668.jpg') im, start, end = watermark_detector(img, cropped_gx, cropped_gy) # plt.imshow(im) # plt.show() # We are done with watermark estimation # W_m is the cropped watermark num_images = len(gxlist) J, img_paths = get_cropped_images('images/fotolia_processed', num_images, start, end, cropped_gx.shape) # get a random subset of J idx = [ 389, 144, 147, 468, 423, 92, 3, 354, 196, 53, 470, 445, 314, 349, 105, 366, 56, 168, 351, 15, 465, 368, 90, 96, 202, 54, 295, 137, 17, 79, 214, 413, 454, 305, 187, 4, 458, 330, 290, 73, 220, 118, 125, 180, 247, 243, 257, 194, 117, 320, 104, 252, 87, 95, 228, 324, 271, 398, 334, 148, 425, 190, 78, 151, 34, 310, 122, 376, 102, 260