Skip to content

Commit 0321542

Browse files
committed
more examples
1 parent 5ba49e7 commit 0321542

File tree

4 files changed

+76
-15
lines changed

4 files changed

+76
-15
lines changed

external_library/java/image_processing/basics.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,28 @@ def draw
3333
when 1
3434
# automatic
3535
# @processed_image = Threshold.apply(my_image)
36-
3736
# by mouseX
3837
@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
4238
when 2, 3, 10
4339
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)
40+
if current_algorithm == 10
41+
@processed_image = Quantization.apply(my_image, quant)
5042
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)
43+
@processed_image = Threshold.apply(my_image)
44+
if current_algorithm == 2
45+
# Dilation expands the white regions by a radius
46+
# works best with threshold/binary images
47+
@processed_image = Dilation.apply(processed_image, quant)
48+
else
49+
# Erosion expands the dark regions by a radius
50+
# works best with threshold/binary images
51+
@processed_image = Erosion.apply(processed_image, quant)
52+
end
5453
end
55-
5654
# Brightness correction
5755
when 4
5856
intensity = map1d(mouse_x, 0..width, -255..255)
5957
@processed_image = Brightness.apply(my_image, intensity)
60-
6158
# AutoBalance for simple color correction
6259
when 5
6360
@processed_image = AutoBalance.apply(my_image)
70.6 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Example for sharpening an image to get a crunchy look.
2+
# The intensity of this effect increases slowly.
3+
# Press the left mouse button to see the original image.
4+
#
5+
# Author: Nick 'Milchreis' Müller
6+
load_library :ImageProcessing
7+
java_import 'milchreis.imageprocessing.Sharpen'
8+
9+
attr_reader :my_image, :sharp_intensity
10+
11+
def settings
12+
size(550, 550)
13+
end
14+
15+
def setup
16+
sketch_title 'Sharpen'
17+
@sharp_intensity = 0
18+
@my_image = load_image(data_path('example.jpg'))
19+
end
20+
21+
def draw
22+
return image(my_image, 0, 0) if mouse_pressed?
23+
image(Sharpen.apply(my_image, sharp_intensity), 0, 0)
24+
# Reset the intensity or increase it
25+
@sharp_intensity = (sharp_intensity > 6) ? 0 : sharp_intensity + 0.05
26+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# /* Example for stacking images.
2+
# * Generates an average face by 10 example faces.
3+
# * Normally the median pixel is selected.
4+
# * Use the mouse button to see the average mode.
5+
# *
6+
# * Author: Nick 'Milchreis' Müller
7+
# */
8+
load_library :ImageProcessing
9+
java_import 'milchreis.imageprocessing.Stacker'
10+
11+
# Dimensions for each face
12+
GRID_WIDTH = 128
13+
GRID_HEIGHT = 155
14+
attr_reader :faces
15+
16+
def settings
17+
size(128, 155)
18+
end
19+
20+
def setup
21+
sketch_title 'Stacker'
22+
# Load faces grid
23+
yale_faces = load_image(data_path('yaleBfaces.jpg'))
24+
@faces = []
25+
grid(yale_faces.width, yale_faces.height, GRID_WIDTH, GRID_HEIGHT) do |x, y|
26+
faces << yale_faces.get(x, y, GRID_WIDTH, GRID_HEIGHT)
27+
end
28+
end
29+
30+
def draw
31+
faces_java = faces.to_java(Java::ProcessingCore::PImage)
32+
# Alternative algorithm is average
33+
return image(Stacker.apply(Stacker::ALGORITHM::AVERAGE, faces_java), 0, 0) if mouse_pressed?
34+
# Default algorithm is median
35+
image(Stacker.apply(faces_java), 0, 0)
36+
# The array is not essential. If you save your images in different variables use this:
37+
# Stacker.apply(image1, image2, image3) # works also
38+
end

0 commit comments

Comments
 (0)