-
-
Save basicfeatures/df555f88da5effde6f68b0806f0e55c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# | |
# ELSAMUKO FILM GRAIN | |
# | |
# gem install --user-install ruby-vips | |
# gem install --user-install pry | |
require "vips" | |
require "pry" | |
INPUT_IMAGE_PATH = "input.jpg" | |
OUTPUT_IMAGE_PATH = "output.jpg" | |
HOLDNESS = 2 | |
VALUE = 100 | |
STRENGTH = 128 | |
GRAIN_BLUR = 1 | |
BLACK_WHITE = false | |
def elsamuko_grain(image_path, output_path) | |
image = Vips::Image.new_from_file(image_path) | |
drawable = image.get("drawable") | |
bw_layer = drawable.copy(interpolate: true) | |
grain_layer = Vips::Image.grey(1, 1) | |
floatingsel = nil | |
bw_layer.desaturate(:desaturate_lightness) | |
grain_layer = grain_layer | |
.draw_rect([128], fill: true) | |
.add_noise(:hsv, 2, 0, 0, 100) | |
.gaussblur(1, precision: :float) | |
.paste(drawable.copy_buffer, true) | |
floatingsel.anchor | |
grain_layer.mask(curves: [:histogram_value, [0, 128, 255, 0, 255, 0], 6]) | |
image.insert(bw_layer, 0) | |
image.insert(grain_layer, 0) | |
image.write_to_file(output_path) | |
end | |
elsamuko_grain(INPUT_IMAGE_PATH, OUTPUT_IMAGE_PATH) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# | |
# ELSAMUKO LOMOGRAPHY | |
# | |
# gem install --user-install ruby-vips | |
# gem install --user-install pry | |
require "vips" | |
require "pry" | |
INPUT_IMAGE_PATH = "input.jpg" | |
OUTPUT_IMAGE_PATH = "output.jpg" | |
BRIGHTNESS = 0.5 | |
CONTRAST = 1.0 | |
SATURATION = 1.0 | |
GRAIN = 0.05 | |
VIGNETTE_BLUR_RADIUS = 200 | |
VIGNETTE_OPACITY = 0.5 | |
DISTORTION = 0.1 | |
GAUSS_BLUR_RADIUS = 1 | |
MOTION_BLUR_LENGTH = 20 | |
MOTION_BLUR_ANGLE = 30 | |
COLOR_PROFILE = "Vintage" | |
# Color Profiles | |
COLOR_PROFILES = { | |
"Neutral" => [0, 0, 32, 16, 128, 192, 192, 228, 255, 255], | |
"Old Red" => [0, 0, 0, 0, 128, 128, 128, 192, 255, 255], | |
"XPro Green" => [0, 16, 64, 64, 128, 128, 192, 192, 255, 255], | |
"Blue" => [255, 128, 64, 32, 0, 0, 0, 0, 0, 0], | |
"XPro Autumn" => [255, 0, 0, 0, 255, 255, 255, 255, 255, 255], | |
"Movie" => [16, 32, 64, 128, 192, 192, 192, 224, 255, 255], | |
"Vintage" => [0, 20, 40, 80, 160, 200, 220, 240, 255, 255], | |
"Xpro LAB" => [0, 0, 64, 128, 192, 228, 228, 255, 255, 255], | |
"Light Blue" => [0, 32, 64, 128, 192, 192, 192, 224, 255, 255], | |
"Pink Shadow" => [0, 16, 32, 64, 128, 192, 192, 224, 255, 255], | |
"Redscale" => [0, 0, 16, 32, 128, 192, 192, 224, 255, 255], | |
"Retro B/W" => [0, 32, 64, 96, 128, 160, 192, 224, 255, 255], | |
"Paynes B/W" => [0, 16, 32, 64, 128, 192, 224, 240, 255, 255], | |
"Sepia" => [0, 16, 32, 64, 128, 192, 224, 240, 255, 255] | |
} | |
def lomo( | |
image, | |
brightness, | |
contrast, | |
saturation, | |
grain, | |
vignette_blur_radius, | |
vignette_opacity, | |
distortion, | |
gauss_blur_radius, | |
motion_blur_length, | |
motion_blur_angle, | |
color_profile | |
) | |
image = image | |
.linear(brightness, 0, contrast) | |
.maplut(COLOR_PROFILES[color_profile]) | |
.colourspace("srgb") | |
.linear(saturation, 20, 235) | |
.gaussnoise(grain) | |
.bandjoin(Vips::Image.black(image.width, image.height).gaussblur(vignette_blur_radius).linear(0, vignette_opacity)) | |
.composite(0, 0, composite_mode: :multiply) | |
.distort("barrel", distortion) | |
.gaussblur(gauss_blur_radius) | |
.rot(angle: -motion_blur_angle) | |
.similarity(angle: motion_blur_angle, scale: 1.0) | |
.crop(motion_blur_length, 0, image.width, image.height) | |
end | |
# Load input image | |
input_image = Vips::Image.new_from_file(INPUT_IMAGE_PATH) | |
# Apply lomo effect | |
output_image = lomo( | |
input_image, | |
BRIGHTNESS, | |
CONTRAST, | |
SATURATION, | |
GRAIN, | |
VIGNETTE_BLUR_RADIUS, | |
VIGNETTE_OPACITY, | |
DISTORTION, | |
GAUSS_BLUR_RADIUS, | |
MOTION_BLUR_LENGTH, | |
MOTION_BLUR_ANGLE, | |
COLOR_PROFILE | |
) | |
# Save output image | |
output_image.write_to_file(OUTPUT_IMAGE_PATH) | |
Author
basicfeatures
commented
May 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment