Add fake EXIF
Browse files
image_postprocess/image_postprocess_with_camera_pipeline.py
CHANGED
|
@@ -11,13 +11,48 @@ import argparse
|
|
| 11 |
import os
|
| 12 |
from PIL import Image
|
| 13 |
import numpy as np
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
from .camera_pipeline import simulate_camera_pipeline
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def process_image(path_in, path_out, args):
|
| 19 |
img = Image.open(path_in).convert('RGB')
|
| 20 |
-
img = remove_exif_pil(img)
|
|
|
|
| 21 |
arr = np.array(img)
|
| 22 |
|
| 23 |
arr = clahe_color_correction(arr, clip_limit=args.clahe_clip, tile_grid_size=(args.tile, args.tile))
|
|
@@ -52,7 +87,10 @@ def process_image(path_in, path_out, args):
|
|
| 52 |
seed=args.seed)
|
| 53 |
|
| 54 |
out_img = Image.fromarray(arr)
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def build_argparser():
|
| 58 |
p = argparse.ArgumentParser(description="Image postprocessing pipeline with camera simulation")
|
|
|
|
| 11 |
import os
|
| 12 |
from PIL import Image
|
| 13 |
import numpy as np
|
| 14 |
+
import piexif
|
| 15 |
+
from datetime import datetime
|
| 16 |
|
| 17 |
+
|
| 18 |
+
from .utils import add_gaussian_noise, clahe_color_correction, randomized_perturbation, fourier_match_spectrum
|
| 19 |
from .camera_pipeline import simulate_camera_pipeline
|
| 20 |
|
| 21 |
+
def add_fake_exif():
|
| 22 |
+
"""
|
| 23 |
+
Generates a plausible set of fake EXIF data.
|
| 24 |
+
Returns:
|
| 25 |
+
bytes: The EXIF data as a byte string, ready for insertion.
|
| 26 |
+
"""
|
| 27 |
+
# Get current time for timestamp
|
| 28 |
+
now = datetime.now()
|
| 29 |
+
datestamp = now.strftime("%Y:%m:%d %H:%M:%S")
|
| 30 |
+
|
| 31 |
+
# Define some plausible fake EXIF tags
|
| 32 |
+
zeroth_ifd = {
|
| 33 |
+
piexif.ImageIFD.Make: b"PurinCamera",
|
| 34 |
+
piexif.ImageIFD.Model: b"Model420X",
|
| 35 |
+
piexif.ImageIFD.Software: b"NovaImageProcessor",
|
| 36 |
+
piexif.ImageIFD.DateTime: datestamp.encode('utf-8'),
|
| 37 |
+
}
|
| 38 |
+
exif_ifd = {
|
| 39 |
+
piexif.ExifIFD.DateTimeOriginal: datestamp.encode('utf-8'),
|
| 40 |
+
piexif.ExifIFD.DateTimeDigitized: datestamp.encode('utf-8'),
|
| 41 |
+
piexif.ExifIFD.ExposureTime: (1, 125), # 1/125s
|
| 42 |
+
piexif.ExifIFD.FNumber: (28, 10), # F/2.8
|
| 43 |
+
piexif.ExifIFD.ISOSpeedRatings: 200,
|
| 44 |
+
piexif.ExifIFD.FocalLength: (50, 1), # 50mm
|
| 45 |
+
}
|
| 46 |
+
gps_ifd = {} # Empty GPS info
|
| 47 |
+
|
| 48 |
+
exif_dict = {"0th": zeroth_ifd, "Exif": exif_ifd, "GPS": gps_ifd, "1st": {}, "thumbnail": None}
|
| 49 |
+
exif_bytes = piexif.dump(exif_dict)
|
| 50 |
+
return exif_bytes
|
| 51 |
+
|
| 52 |
def process_image(path_in, path_out, args):
|
| 53 |
img = Image.open(path_in).convert('RGB')
|
| 54 |
+
# img = remove_exif_pil(img) # <-- This line is removed
|
| 55 |
+
|
| 56 |
arr = np.array(img)
|
| 57 |
|
| 58 |
arr = clahe_color_correction(arr, clip_limit=args.clahe_clip, tile_grid_size=(args.tile, args.tile))
|
|
|
|
| 87 |
seed=args.seed)
|
| 88 |
|
| 89 |
out_img = Image.fromarray(arr)
|
| 90 |
+
|
| 91 |
+
# Generate fake EXIF data and save it with the image
|
| 92 |
+
fake_exif_bytes = add_fake_exif()
|
| 93 |
+
out_img.save(path_out, exif=fake_exif_bytes)
|
| 94 |
|
| 95 |
def build_argparser():
|
| 96 |
p = argparse.ArgumentParser(description="Image postprocessing pipeline with camera simulation")
|