the only good website on the internet
quaso.engineering
1module ImageProcessing
2
3using DitherPunk: dither, Bayer
4using FileIO: save, load
5using Images: Gray, imresize
6using VideoIO: openvideo, get_duration, read, seek, close
7
8export apply_dither, extract_video_frame
9
10function apply_dither(img::AbstractArray, scale::Float64=0.7)
11 # Handle video frames (which come as vectors) vs regular images
12 if img isa Vector
13 img = first(img) # Take the first frame from video
14 end
15
16 img_gray = Gray.(img) # Convert RGB to grayscale
17 dithered = dither(img_gray, Bayer())
18 new_size = trunc.(Int, size(dithered) .* scale)
19 return imresize(dithered, new_size)
20end
21
22function extract_video_frame(video_path::String, output_path::String, percentage_position::Float64=0.1)
23 duration = get_duration(video_path)
24 vid = openvideo(video_path)
25
26 target_time = duration * percentage_position
27 seek(vid, target_time)
28 frame = read(vid)
29 close(vid)
30
31 dithered_frame = apply_dither(frame)
32 save(output_path, dithered_frame)
33
34 @info "Extracted thumbnail" output_path
35end
36
37end # module