Skip to content

Commit 2352c7b

Browse files
committed
Image Processing
1 parent e1e2812 commit 2352c7b

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Example for basic image processing algorithms.
2+
# Use the mouse wheel to switch the different algorithms
3+
# and press the left mouse button to see the original image.
4+
#
5+
# Author: Nick 'Milchreis' Müller
6+
7+
load_library :ImageProcessing
8+
9+
include_package 'milchreis.imageprocessing'
10+
11+
NUMBER_OF_ALGORITHMS = 11
12+
attr_reader :current_algorithm, :processed_image, :my_image
13+
14+
def settings
15+
size(550, 550)
16+
end
17+
18+
def setup
19+
sketch_title 'Image Processing'
20+
@my_image = loadImage(data_path('example.jpg'))
21+
@current_algorithm = 0
22+
end
23+
24+
def draw
25+
return image(my_image, 0, 0) if mouse_pressed?
26+
27+
# Grayscale converts the image in to 256 shades of gray
28+
case current_algorithm
29+
when 0
30+
@processed_image = Grayscale.apply(my_image)# if current_algorithm == 0
31+
32+
# Threshold converts a pixel in bright or dark for a specific color value
33+
when 1
34+
# automatic
35+
# @processed_image = Threshold.apply(my_image)
36+
37+
# by mouseX
38+
@processed_image = Threshold.apply(my_image, map1d(mouse_x, 0..width, 0..255))
39+
40+
# Dilation expands the white regions by a radius
41+
# works best with threshold/binary images
42+
when 2, 3, 10
43+
quant = map1d(mouse_x, 0..width, 1..10)
44+
return @processed_image = Quantization.apply(
45+
my_image, quant
46+
) if current_algorithm == 10
47+
@processed_image = Threshold.apply(my_image)
48+
if current_algorithm == 2
49+
@processed_image = Dilation.apply(processed_image, quant)
50+
else
51+
# Erosion expands the dark regions by a radius
52+
# works best with threshold/binary images
53+
@processed_image = Erosion.apply(processed_image, quant)
54+
end
55+
56+
# Brightness correction
57+
when 4
58+
intensity = map1d(mouse_x, 0..width, -255..255)
59+
@processed_image = Brightness.apply(my_image, intensity)
60+
61+
# AutoBalance for simple color correction
62+
when 5
63+
@processed_image = AutoBalance.apply(my_image)
64+
65+
# Pixelation
66+
when 6
67+
pixelsize = map1d(mouse_x, 0..width, 0..100)
68+
@processed_image = Pixelation.apply(my_image, pixelsize)
69+
70+
# Gaussian for blurred images
71+
when 7
72+
@processed_image = Gaussian.apply(my_image, 7, 0.84089642)
73+
74+
# Edge detection with Canny's algorithm
75+
when 8
76+
@processed_image = CannyEdgeDetector.apply(my_image)
77+
78+
# Edge detection with Sobel's algorithm
79+
when 9
80+
# SobelEdgeDetector.apply(image, false) creates a colored image
81+
@processed_image = SobelEdgeDetector.apply(my_image)
82+
end
83+
# show image
84+
image(processed_image, 0, 0)
85+
end
86+
87+
def mouseWheel(event) # keep camelcase poxy reflection
88+
@current_algorithm += event.getCount
89+
@current_algorithm = 0 if current_algorithm >= NUMBER_OF_ALGORITHMS
90+
@current_algorithm = NUMBER_OF_ALGORITHMS - 1 if current_algorithm < 0
91+
end
378 KB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Example for halftone an image to get a old school print look.
2+
#
3+
# The dot size can be changed by moving the mouse left and right.
4+
# The spacing between the dots can be changed by moving the mouse up and down.
5+
# If you press the mouse button the dots will be shown in a grid.
6+
#
7+
# Author: Nick 'Milchreis' Müller
8+
9+
load_library :ImageProcessing
10+
java_import 'milchreis.imageprocessing.Halftone'
11+
attr_reader :my_image
12+
13+
def settings
14+
size(550, 550)
15+
end
16+
17+
def setup
18+
sketch_title 'Half Tone'
19+
# Load image
20+
@my_image = load_image(data_path('example.jpg'))
21+
end
22+
23+
def draw
24+
# Simple usage:
25+
# image = Halftone.apply(image, dotsize)
26+
27+
# dotsize by mouseX
28+
dotsize = map1d(mouseX, 0..width, 3..10)
29+
30+
# dots in grid or honeycomb style by mousePressed
31+
inGrid = mouse_pressed?
32+
33+
# Foreground color
34+
foreground = '#335764'
35+
36+
# Space between dots by mouseY
37+
space = map1d(mouseY, 0..height, 1..3)
38+
39+
# Draw image
40+
image(Halftone.apply(my_image, dotsize, color(foreground), 255, space, inGrid), 0, 0)
41+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Example for lookup tables (LUT).
2+
# Use the mouse wheel to switch the different tables/styles
3+
# and press the left mouse button to see the original image.
4+
#
5+
# Author: Nick 'Milchreis' Müller
6+
# Translated to JRubyArt by Martin Prout
7+
8+
load_library :ImageProcessing
9+
java_import 'milchreis.imageprocessing.LUT'
10+
11+
attr_reader :my_image, :lookuptables, :current_index, :enums
12+
13+
def settings
14+
size(550, 550)
15+
end
16+
17+
def setup
18+
sketch_title 'LUT Example'
19+
@current_index = 0
20+
# Load image
21+
@my_image = load_image(data_path('example.jpg'))
22+
# Create an array with all lookup-tables
23+
# LUT Styles:
24+
# RETRO, CONTRAST, CONTRAST_STRONG, ANALOG1, WINTER, SPRING, SUMMER, AUTUMN
25+
@enums = LUT::STYLE.values
26+
@lookuptables = enums.map do |enum|
27+
LUT.load_lut(enum.java_object)
28+
end
29+
# Load one style:
30+
# LUT style = LUT.loadLut(LUT.STYLE.ANALOG1)
31+
end
32+
33+
def draw
34+
return image(my_image, 0, 0) if mouse_pressed?
35+
image(LUT.apply(my_image, lookuptables[current_index]), 0, 0)
36+
fill(0)
37+
stylename = enums[current_index].name
38+
text(stylename, width / 2 - textWidth(stylename) / 2, 30)
39+
end
40+
41+
def mouseWheel(event) # keep camelcase for poxy java reflection
42+
@current_index += 1
43+
@current_index = 0 if current_index >= lookuptables.length
44+
end

0 commit comments

Comments
 (0)