Skip to content

Instantly share code, notes, and snippets.

@guaracy
Created April 10, 2016 18:19
Show Gist options
  • Save guaracy/905d884b263e2b80050cc3f9051f86f9 to your computer and use it in GitHub Desktop.
Save guaracy/905d884b263e2b80050cc3f9051f86f9 to your computer and use it in GitHub Desktop.
Red [
Title: "Dessaturate"
Author: "Guaracy Monteiro"
Needs: 'View
Version: 0.1
]
desaturate: function [
image
/Lightness
/Luminosity
/RedChannel
/GreenChannel
/BlueChannel
/local img
][
img: copy image
case [
Lightness [
forall img [
t: img/1
t/1: t/2: t/3: ((max max (t/1) (t/2) (t/3)) + (min min (t/1) (t/2) (t/3))) / 2
img/1: t
]
]
Luminosity [
forall img [
t: img/1
t/1: t/2: t/3: to integer! ((t/1 * 0.21) + (t/2 * 0.72) + (t/3 * 0.07))
img/1: t
]
]
RedChannel [
forall img [
t: img/1
t/2: t/3: t/1
img/1: t
]
]
GreenChannel [
forall img [
t: img/1
t/1: t/3: t/2
img/1: t
]
]
BlueChannel [
forall img [
t: img/1
t/1: t/2: t/3
img/1: t
]
]
true [
forall img [
t: img/1
t/1: t/2: t/3: ((t/1 + t/2 + t/3) / 3)
img/1: t
]
]
]
return img
]
load-image: function [][
request-file/title/filter "Load Image" ["Images" "*.jpg;*.png;*.bmp"]
]
im: load-image
view [
title "Desaturate image"
text "Method:"
return
dd: drop-down
on-change [
im2/image:
switch dd/selected [
1 [desaturate/Lightness im1/image]
2 [desaturate/Luminosity im1/image]
3 [desaturate im1/image]
4 [desaturate/RedChannel im1/image]
5 [desaturate/GreenChannel im1/image]
6 [desaturate/BlueChannel im1/image]
]
]
data ["Lightness" "Luminosity" "Average" "Red Channel" "Green Channel" "Blue Channel"]
button "Load" [
im: load load-image
im1/image: im
im1/size: im/size
im2/image: im
im2/size: im/size
]
button "Quit" [unview]
return
im1: image im
im2: image im
]
quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment