-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
The [image_processing library][image_processing] was created by [Nick 'Milchreis' Müller][Milchreis] and needs to be installed in your `~/.propane/libraries`, NB I use the convention of converting | ||
camelcase names to snakecase, I suggest you do the same for your propane libraries. | ||
|
||
[image_processing]:https://github.com/Milchreis/processing-imageprocessing | ||
[Milchreis]:https://milchreisjunkie.wordpress.com/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for basic image processing algorithms. | ||
# Use the mouse wheel to switch the different algorithms | ||
# and press the left mouse button to see the original image. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
class BasicImageProcessing < Propane::App | ||
|
||
load_library :image_processing | ||
|
||
include_package 'milchreis.imageprocessing' | ||
|
||
NUMBER_OF_ALGORITHMS = 11 | ||
attr_reader :current_algorithm, :processed_image, :my_image | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
|
||
def setup | ||
sketch_title 'Image Processing' | ||
@my_image = loadImage(data_path('example.jpg')) | ||
@current_algorithm = 0 | ||
end | ||
|
||
def draw | ||
return image(my_image, 0, 0) if mouse_pressed? | ||
|
||
# Grayscale converts the image in to 256 shades of gray | ||
case current_algorithm | ||
when 0 | ||
@processed_image = Grayscale.apply(my_image)# if current_algorithm == 0 | ||
|
||
# Threshold converts a pixel in bright or dark for a specific color value | ||
when 1 | ||
# automatic | ||
# @processed_image = Threshold.apply(my_image) | ||
# by mouseX | ||
@processed_image = Threshold.apply(my_image, map1d(mouse_x, 0..width, 0..255)) | ||
when 2, 3, 10 | ||
quant = map1d(mouse_x, 0..width, 1..10) | ||
if current_algorithm == 10 | ||
@processed_image = Quantization.apply(my_image, quant) | ||
else | ||
@processed_image = Threshold.apply(my_image) | ||
if current_algorithm == 2 | ||
# Dilation expands the white regions by a radius | ||
# works best with threshold/binary images | ||
@processed_image = Dilation.apply(processed_image, quant) | ||
else | ||
# Erosion expands the dark regions by a radius | ||
# works best with threshold/binary images | ||
@processed_image = Erosion.apply(processed_image, quant) | ||
end | ||
end | ||
# Brightness correction | ||
when 4 | ||
intensity = map1d(mouse_x, 0..width, -255..255) | ||
@processed_image = Brightness.apply(my_image, intensity) | ||
# AutoBalance for simple color correction | ||
when 5 | ||
@processed_image = AutoBalance.apply(my_image) | ||
|
||
# Pixelation | ||
when 6 | ||
pixelsize = map1d(mouse_x, 0..width, 0..100) | ||
@processed_image = Pixelation.apply(my_image, pixelsize) | ||
|
||
# Gaussian for blurred images | ||
when 7 | ||
@processed_image = Gaussian.apply(my_image, 7, 0.84089642) | ||
|
||
# Edge detection with Canny's algorithm | ||
when 8 | ||
@processed_image = CannyEdgeDetector.apply(my_image) | ||
|
||
# Edge detection with Sobel's algorithm | ||
when 9 | ||
# SobelEdgeDetector.apply(image, false) creates a colored image | ||
@processed_image = SobelEdgeDetector.apply(my_image) | ||
end | ||
# show image | ||
image(processed_image, 0, 0) | ||
end | ||
|
||
def mouseWheel(event) # keep camelcase poxy reflection | ||
@current_algorithm += event.getCount | ||
@current_algorithm = 0 if current_algorithm >= NUMBER_OF_ALGORITHMS | ||
@current_algorithm = NUMBER_OF_ALGORITHMS - 1 if current_algorithm < 0 | ||
end | ||
end | ||
|
||
BasicImageProcessing.new |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for dithering an image to get a retro look. | ||
# | ||
# Use the mouse wheel to change the dithering algorithm | ||
# and press spacebar to show it in gray scale for the perfect | ||
# retro look. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
class DitheringSketch < Propane::App | ||
load_library :image_processing | ||
java_import 'milchreis.imageprocessing.Dithering' | ||
java_import 'milchreis.imageprocessing.Grayscale' | ||
attr_reader :my_image, :processed, :label, :index | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
|
||
def setup | ||
sketch_title 'Dithering' | ||
@index = 0 | ||
@my_image = load_image(data_path('example.jpg')) | ||
end | ||
|
||
def draw | ||
@processed = my_image | ||
@label = '' | ||
if key_pressed? && key == ' ' | ||
@processed = Grayscale.apply(processed) | ||
end | ||
return image(my_image, 0, 0) if mouse_pressed? | ||
case index | ||
when -1 | ||
@processed = Dithering.apply(processed) | ||
@label = 'BAYER_4x4 on default' | ||
when 0 | ||
@processed = Dithering.apply(processed, Dithering::Algorithm::BAYER_2x2) | ||
@label = 'BAYER_2x2' | ||
when 1 | ||
@processed = Dithering.apply(processed, Dithering::Algorithm::BAYER_4x4) | ||
@label = 'BAYER_4x4' | ||
when 2 | ||
@processed = Dithering.apply(processed, Dithering::Algorithm::BAYER_8x8) | ||
@label = 'BAYER_8x8' | ||
end | ||
image(processed, 0, 0) | ||
fill(0) | ||
text(label, width / 2 - text_width(label) / 2, 30) | ||
end | ||
|
||
def mouseWheel(event) | ||
@index += event.get_count | ||
|
||
if index >= Dithering::Algorithm.values.length | ||
@index = -1 | ||
end | ||
end | ||
end | ||
|
||
DitheringSketch.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for an artificial glitch effect. | ||
# Move the mouse from left to right to see different intensity | ||
# or press the left mouse button to see the original image. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
# Translated to JRubyArt by Martin Prout | ||
class GlitchExample < Propane::App | ||
load_library :image_processing | ||
java_import 'milchreis.imageprocessing.Glitch' | ||
|
||
attr_reader :my_image | ||
|
||
def setup | ||
sketch_title 'Glitch' | ||
# Load image | ||
@my_image = load_image(data_path('example.jpg')) | ||
end | ||
|
||
def draw | ||
return image(my_image, 0, 0) if mouse_pressed? | ||
intensity = map1d(mouseX, 0..width, 0..4) | ||
image(Glitch.apply(my_image, intensity), 0, 0) | ||
# You can also use: | ||
# Glitch.apply(image) | ||
# Glitch.apply(image, intensity, scanlineHeight) | ||
end | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
end | ||
|
||
GlitchExample.new |
47 changes: 47 additions & 0 deletions
47
external_library/java/image_processing/halftone_example.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for halftone an image to get a old school print look. | ||
# | ||
# The dot size can be changed by moving the mouse left and right. | ||
# The spacing between the dots can be changed by moving the mouse up and down. | ||
# If you press the mouse button the dots will be shown in a grid. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
class HalfTone < Propane::App | ||
load_library :image_processing | ||
java_import 'milchreis.imageprocessing.Halftone' | ||
attr_reader :my_image | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
|
||
def setup | ||
sketch_title 'Half Tone' | ||
# Load image | ||
@my_image = load_image(data_path('example.jpg')) | ||
end | ||
|
||
def draw | ||
# Simple usage: | ||
# image = Halftone.apply(image, dotsize) | ||
|
||
# dotsize by mouseX | ||
dotsize = map1d(mouseX, 0..width, 3..10) | ||
|
||
# dots in grid or honeycomb style by mousePressed | ||
inGrid = mouse_pressed? | ||
|
||
# Foreground color | ||
foreground = '#335764' | ||
|
||
# Space between dots by mouseY | ||
space = map1d(mouseY, 0..height, 1..3) | ||
|
||
# Draw image | ||
image(Halftone.apply(my_image, dotsize, color(foreground), 255, space, inGrid), 0, 0) | ||
end | ||
end | ||
|
||
HalfTone.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for lookup tables (LUT). | ||
# Use the mouse wheel to switch the different tables/styles | ||
# and press the left mouse button to see the original image. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
# Translated to JRubyArt by Martin Prout | ||
class LUTExample < Propane::App | ||
load_library :image_processing | ||
java_import 'milchreis.imageprocessing.LUT' | ||
|
||
attr_reader :my_image, :lookuptables, :current_index, :enums | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
|
||
def setup | ||
sketch_title 'LUT Example' | ||
@current_index = 0 | ||
# Load image | ||
@my_image = load_image(data_path('example.jpg')) | ||
# Create an array with all lookup-tables | ||
# LUT Styles: | ||
# RETRO, CONTRAST, CONTRAST_STRONG, ANALOG1, WINTER, SPRING, SUMMER, AUTUMN | ||
@enums = LUT::STYLE.values | ||
@lookuptables = enums.map do |enum| | ||
LUT.load_lut(enum.java_object) | ||
end | ||
# Load one style: | ||
# LUT style = LUT.loadLut(LUT.STYLE.ANALOG1) | ||
end | ||
|
||
def draw | ||
return image(my_image, 0, 0) if mouse_pressed? | ||
image(LUT.apply(my_image, lookuptables[current_index]), 0, 0) | ||
fill(0) | ||
stylename = enums[current_index].name | ||
text(stylename, width / 2 - textWidth(stylename) / 2, 30) | ||
end | ||
|
||
def mouseWheel(event) # keep camelcase for poxy java reflection | ||
@current_index += 1 | ||
@current_index = 0 if current_index >= lookuptables.length | ||
end | ||
end | ||
|
||
LUTExample.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for sharpening an image to get a crunchy look. | ||
# The intensity of this effect increases slowly. | ||
# Press the left mouse button to see the original image. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
class Sharpening < Propane::App | ||
load_library :image_processing | ||
|
||
java_import 'milchreis.imageprocessing.Sharpen' | ||
|
||
attr_reader :my_image, :sharp_intensity | ||
|
||
def settings | ||
size(550, 550) | ||
end | ||
|
||
def setup | ||
sketch_title 'Sharpen' | ||
@sharp_intensity = 0 | ||
@my_image = load_image(data_path('example.jpg')) | ||
end | ||
|
||
def draw | ||
return image(my_image, 0, 0) if mouse_pressed? | ||
image(Sharpen.apply(my_image, sharp_intensity), 0, 0) | ||
# Reset the intensity or increase it | ||
@sharp_intensity = (sharp_intensity > 6) ? 0 : sharp_intensity + 0.05 | ||
end | ||
end | ||
|
||
Sharpening.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env jruby -v -W2 | ||
require 'propane' | ||
|
||
# Example for stacking images. | ||
# Generates an average face by 10 example faces. | ||
# Normally the median pixel is selected. | ||
# Use the mouse button to see the average mode. | ||
# | ||
# Author: Nick 'Milchreis' Müller | ||
class Stacking < Propane::App | ||
|
||
load_library :image_processing | ||
java_import 'milchreis.imageprocessing.Stacker' | ||
|
||
# Dimensions for each face | ||
GRID_WIDTH = 128 | ||
GRID_HEIGHT = 155 | ||
attr_reader :faces | ||
|
||
def settings | ||
size(128, 155) | ||
end | ||
|
||
def setup | ||
sketch_title 'Stacker' | ||
# Load faces grid | ||
yale_faces = load_image(data_path('yaleBfaces.jpg')) | ||
@faces = [] | ||
grid(yale_faces.width, yale_faces.height, GRID_WIDTH, GRID_HEIGHT) do |x, y| | ||
faces << yale_faces.get(x, y, GRID_WIDTH, GRID_HEIGHT) | ||
end | ||
end | ||
|
||
def draw | ||
faces_java = faces.to_java(Java::ProcessingCore::PImage) | ||
# Alternative algorithm is average | ||
return image(Stacker.apply(Stacker::ALGORITHM::AVERAGE, faces_java), 0, 0) if mouse_pressed? | ||
# Default algorithm is median | ||
image(Stacker.apply(faces_java), 0, 0) | ||
# The array is not essential. If you save your images in different variables use this: | ||
# Stacker.apply(image1, image2, image3) # works also | ||
end | ||
end | ||
|
||
Stacking.new |