def extract(self, watermarked_image): import cv2 # To array watermarked_array = misc.fromimage(watermarked_image) modifiedBlocks = [] # components for i in range(3): component = watermarked_array[:, :, i] m = self.extractFromComponent(component) modifiedBlocks += m modifiedBlocks = list(set(modifiedBlocks)) # Dividing in 32x32 blocks blocks32x32 = BlocksImage(watermarked_array, 32, 32) for item in modifiedBlocks: coord = blocks32x32.get_coord(item) for x in range(32): for y in range(32): watermarked_array[coord[0]+x, coord[1]+y] = [0, 255, 0] cv2.rectangle( watermarked_array, (coord[1], coord[0]), (coord[3], coord[2]), (0, 255, 0), 1) return Image.fromarray(watermarked_array)
def extract(self, watermarked_image): import cv2 # To array watermarked_array = np.asarray(watermarked_image) # Blue component blue_watermarked_array = watermarked_array[:, :, 2] blue_watermarked_array.setflags(write=1) blue_watermarked_array_noise = blue_watermarked_array.copy() # Dividing in 32x32 blocks blocks32x32 = BlocksImage(blue_watermarked_array_noise, 32, 32) # Touring each block 32x32 modifiedBlocks = [] for num_block in range(blocks32x32.max_num_blocks()): # Copying block 32x32 blockCopy32x32 = deepcopy(blocks32x32.get_block(num_block)) # Dividing in 16x16 blocks blocksCopy16x16 = BlocksImage(blockCopy32x32, 16, 16) # Get first block first_block = blocksCopy16x16.get_block(0) # Watermark w = '' # Pariar for i in range(16): for y in range(16): if (first_block[i, y] % 2) == 1: first_block[i, y] -= 1 w += '1' else: w += '0' # Hash of blocksCopy32x32 pareado blocksHash = utils.sha256Binary(blockCopy32x32.tolist()) if w != blocksHash: modifiedBlocks.append(num_block) print(modifiedBlocks) for item in modifiedBlocks: coord = blocks32x32.get_coord(item) cv2.rectangle(watermarked_array, (coord[1], coord[0]), (coord[3], coord[2]), (0, 255, 0), 1) return Image.fromarray(watermarked_array)
def extract(self, watermarked_image): import cv2 # To array watermarked_array = np.asarray(watermarked_image) modifiedBlocks = [] # components for i in range(3): component = watermarked_array[:, :, i] component.setflags(write=1) m = self.extractFromComponent(component) modifiedBlocks += m modifiedBlocks = list(set(modifiedBlocks)) print(modifiedBlocks) # Dividing in 32x32 blocks blocks32x32 = BlocksImage(watermarked_array, 32, 32) for item in modifiedBlocks: coord = blocks32x32.get_coord(item) cv2.rectangle(watermarked_array, (coord[1], coord[0]), (coord[3], coord[2]), (0, 255, 0), 1) return Image.fromarray(watermarked_array)