Skip to content

Commit

Permalink
updated watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
guillbertrand committed Jan 20, 2025
1 parent 64853e1 commit fabc33f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
21 changes: 17 additions & 4 deletions app/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def add_watermark(image: Image.Image, observer: str) -> Image.Image:
draw = ImageDraw.Draw(image)

font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Baumans-Regular.ttf", 40) # Use a specific font if available
draw.text(get_text_position(image, 126), 'SUNSCAN', fill="white", font=font)
font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Roboto-Thin.ttf", 30) # Use a specific font if available
draw.text(get_text_position(image, 84), observer, fill="white", font=font)
draw.text(get_text_position(image, 115), 'SUNSCAN', fill="white", font=font)
font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Roboto-Regular.ttf", 20) # Use a specific font if available
draw.text(get_text_position(image, 73), observer, fill="white", font=font)
return image

def resize_frame(image: Image.Image) -> Image.Image:
Expand Down Expand Up @@ -113,7 +113,20 @@ def create_gif(image_paths: List[Path], watermark: bool, observer: str,output_pa


# Check if the output path contains "clahe" and create a preview gif
if "clahe" in str(output_path).lower():
if "helium_cont" in str(output_path).lower():
# Resize the frames to 250px width and height
preview_frames = [frame.resize((250, 250), Image.Resampling.LANCZOS) for frame in frames]
preview_output_path = os.path.join(os.path.dirname(output_path), "animated_preview.gif")
preview_frames[0].save(
preview_output_path,
save_all=True,
append_images=preview_frames[1:],
duration=frame_duration, # Frame duration in ms
loop=0, # Infinite loop
dither=True
)
print(f"Preview GIF saved at {preview_output_path}")
elif "clahe" in str(output_path).lower():
# Resize the frames to 250px width and height
preview_frames = [frame.resize((250, 250), Image.Resampling.LANCZOS) for frame in frames]
preview_output_path = os.path.join(os.path.dirname(output_path), "animated_preview.gif")
Expand Down
30 changes: 17 additions & 13 deletions app/dedistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ def correct_image_png(input_name, dx_map, dy_map):


def stack(paths, status, observer):
if not status['clahe']:
if not status['clahe'] and not status['helium']:
return

clahe_basefilename = 'sunscan_clahe.png'
cont_basefilename = 'sunscan_cont.png'
clahe_basefilename = 'sunscan_clahe.png' if not status['helium'] else 'sunscan_helium.png'
cont_basefilename = 'sunscan_cont.png' if not status['helium'] else 'sunscan_helium_cont.png'

deformed_root = os.path.join(os.path.dirname(paths[0]) ,clahe_basefilename)
sum_image = imageio.v2.imread(deformed_root )
sum_image = sum_image.astype(np.uint32)

if status['cont']:
if status['cont'] or status['helium_cont']:
cont_deformed_root = os.path.join(os.path.dirname(paths[0]) ,cont_basefilename)
cont_sum_image = imageio.v2.imread(cont_deformed_root )
cont_sum_image = cont_sum_image.astype(np.uint32)
Expand Down Expand Up @@ -234,14 +234,14 @@ def stack(paths, status, observer):
# Correction des distorsions dans la s�quence principale (format PNG en entr�e)
corrected_image = correct_image_png(deformed_name, dx_map, dy_map)

if status['cont']:
if status['cont'] or status['helium_cont']:
cont_deformed_name = os.path.join(os.path.dirname(p) ,cont_basefilename)
corrected_cont_image = correct_image_png(cont_deformed_name, dx_map, dy_map)

# Sommation (stacking)
if i>1:
sum_image = sum_image + corrected_image.astype(np.uint32)
if status['cont']:
if status['cont'] or status['helium_cont']:
cont_sum_image = cont_sum_image + corrected_cont_image.astype(np.uint32)

print('Scan #' + p)
Expand All @@ -264,14 +264,18 @@ def stack(paths, status, observer):
os.mkdir(work_dir)

watermark_txt = str(i-1)+' stacked images - '+formatted_avg_datetime
watermark_txt_t = watermark_txt
if tag:
watermark_txt += ' - '+ tag
watermark_txt_t += ' - '+ tag

write_images(work_dir, sum_image, 'clahe', i-1, watermark_txt, observer)
if status['cont']:
write_images(work_dir, sum_image, 'clahe', i-1, watermark_txt_t, observer)

if status['helium_cont']:
write_images(work_dir, cont_sum_image, 'cont', i-1, watermark_txt_t, observer)
elif status['cont']:
write_images(work_dir, cont_sum_image, 'cont', i-1, watermark_txt, observer)


def apply_watermark_if_enable(frame, text, observer):
print('watermark', observer)
if not observer:
Expand All @@ -287,9 +291,9 @@ def apply_watermark_if_enable(frame, text, observer):
draw.text(text_position, text, fill="white", font=font)

font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Baumans-Regular.ttf", 40) # Use a specific font if available
draw.text(get_text_position(image, 126), 'SUNSCAN', fill="white", font=font)
font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Roboto-Thin.ttf", 30) # Use a specific font if available
draw.text(get_text_position(image, 84), observer, fill="white", font=font)
draw.text(get_text_position(image, 115), 'SUNSCAN', fill="white", font=font)
font = ImageFont.truetype("/var/www/sunscan-backend/app/fonts/Roboto-Regular.ttf", 20) # Use a specific font if available
draw.text(get_text_position(image, 73), observer, fill="white", font=font)
return np.array(image)


Expand Down
8 changes: 5 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ async def processScan(scan:Scan, background_tasks: BackgroundTasks):

@app.post("/sunscan/process/stack/")
def process_stack(request: PostProcessRequest):
required_files = {"clahe": False, "protus": False, "cont": False}
required_files = {"clahe": False, "protus": False, "cont": False, "color":False, "helium":False, "helium_cont":False}
for required_file, status in required_files.items():
matching_paths = []
for path_str in request.paths:
Expand All @@ -724,9 +724,11 @@ def process_stack(request: PostProcessRequest):
@app.post("/sunscan/process/animate/")
def process_animate(request: PostProcessRequest):
# Supported filenames and output GIF names
required_files = ["sunscan_clahe.png", "sunscan_protus.png", "sunscan_cont.png"]

gif_names = {
"sunscan_clahe.png": "animated_clahe.gif",
"sunscan_helium.png": "animated_helium.gif",
"sunscan_helium_cont.png": "animated_helium_cont.gif",
"sunscan_protus.png": "animated_protus.gif",
"sunscan_cont.png": "animated_cont.gif",
}
Expand All @@ -743,7 +745,7 @@ def process_animate(request: PostProcessRequest):
os.mkdir(work_dir)

# Check for each required file type and generate GIFs if possible
for required_file in required_files:
for required_file in gif_names.keys():
matching_paths = []

for path_str in request.paths:
Expand Down

0 comments on commit fabc33f

Please sign in to comment.