From: Ivan Stefanov Date: Tue, 18 Jan 2022 01:05:42 +0000 (+0200) Subject: Upload Gamma correction code and color space and LED pictures X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=c96aa08afc2e5e77aeaa82c38676d7e132ac966c;p=vmks.git Upload Gamma correction code and color space and LED pictures --- diff --git a/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino b/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino new file mode 100644 index 0000000..061f7cf --- /dev/null +++ b/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino @@ -0,0 +1,24 @@ +// Generate an LED gamma-correction table for Arduino sketches. +// Copy-and-paste the program's output into an Arduino sketch. + +float gamma = 2.2; // Correction factor +uint8_t max_in = 255; // Top end of INPUT range +uint8_t max_out = 255; // Top end of OUTPUT range + +uint8_t temp = 0; + +void setup() { + Serial.begin(9600); + Serial.print("const uint8_t PROGMEM gamma[] = {"); + for (int i = 0; i <= max_in; i++) { + if (i > 0) Serial.print(','); + if ((i & 15) == 0) Serial.print("\n "); + temp = (uint8_t)(pow((float)i / (float)max_in, gamma) * max_out + 0.5); + Serial.print(temp); + } + Serial.println("\n };"); +} + +void loop() { + +} diff --git a/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino b/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino new file mode 100644 index 0000000..bbac89c --- /dev/null +++ b/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino @@ -0,0 +1,21 @@ +#define LED 9 +uint32_t br = 0; +void setup() { + pinMode(LED, OUTPUT); +} +void loop() { + for (uint32_t x = 0; x < 100; x++) { + //br = (x*250)/100; // Gamma - NO + //br = (x*x)/40; // Gamma - 2 + br = (x*x*x)/4000; // Gamma - 3 + analogWrite(LED,br); + delay(20); + } + for (uint32_t x = 100; x > 0; x--) { + //br = (x*250)/100; // Gamma - NO + //br = (x*x)/40; // Gamma - 2 + br = (x*x*x)/4000; // Gamma - 3 + analogWrite(LED,br); + delay(20); + } +} diff --git a/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino b/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino new file mode 100644 index 0000000..ce8837f --- /dev/null +++ b/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino @@ -0,0 +1,34 @@ +#include +#define LED_PIN 6 +#define LED_ROW 8 +#define LED_COL 8 +#define LED_COUNT (LED_ROW * LED_COL) + +Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); + +uint32_t brightness = 0; + +void setup() { + matrix.begin(); + matrix.show(); + matrix.setBrightness(255); +} + +void loop() { + for (uint32_t x = 0; x < 100; x++) { + //brightness = (x*250)/100; // Gamma - NO + //brightness = (x*x)/40; // Gamma - 2 + brightness = (x*x*x)/4000; // Gamma - 3 + matrix.setPixelColor(0, (uint8_t)brightness, 0, 0); + matrix.show(); + delay(20); + } + for (uint32_t x = 100; x > 0; x--) { + //brightness = (x*250)/100; // Gamma - NO + //brightness = (x*x)/40; // Gamma - 2 + brightness = (x*x*x)/4000; // Gamma - 3 + matrix.setPixelColor(0, (uint8_t)brightness, 0, 0); + matrix.show(); + delay(20); + } +} diff --git a/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino b/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino new file mode 100644 index 0000000..d278296 --- /dev/null +++ b/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino @@ -0,0 +1,124 @@ +#include +#define LED_PIN 6 +#define LED_ROW 8 +#define LED_COL 8 +#define LED_COUNT (LED_ROW * LED_COL) + +Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); + +uint32_t brightness = 0; + +// This way the LUT can be at the bottom of the code +extern const uint8_t gamma[]; + +// L - emitted light by the LED +// B - perceived brightness by the EYE + +// Single color +// B=L^(1/gamma) +// L=B^(gamma) + +// RGB MultiColor +// B=(Red^gamma+Green^gamma+Blue^gamma)^(1/gamma) + +void setup() { + matrix.begin(); + matrix.show(); + matrix.setBrightness(255); +} + +void loop() { + for (uint8_t x = 0; x < 100; x++) { + setRGB(0, 100, x, 0); + matrix.show(); + delay(20); + } + for (uint8_t x = 100; x > 0; x--) { + setRGB(0, x, 100, 0); + matrix.show(); + delay(20); + } + for (uint8_t x = 0; x < 100; x++) { + setRGB(0, x, 100, 0); + matrix.show(); + delay(20); + } + for (uint8_t x = 100; x > 0; x--) { + setRGB(0, 100, x, 0); + matrix.show(); + delay(20); + } +} + +void setRGB(uint8_t pixelNumber, uint8_t red, uint8_t green, uint8_t blue) { + matrix.setPixelColor(pixelNumber, + pgm_read_byte(&gamma[red]), + pgm_read_byte(&gamma[green]), + pgm_read_byte(&gamma[blue])); +} + +// Gamma 2.2 + +const uint8_t PROGMEM gamma[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, + 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, + 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, + 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, + 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, + 42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90, + 91, 93, 94, 95, 97, 98, 99, 100, 102, 103, 105, 106, 107, 109, 110, 111, + 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, + 137, 138, 140, 141, 143, 145, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161, + 163, 165, 166, 168, 170, 172, 173, 175, 177, 179, 181, 182, 184, 186, 188, 190, + 192, 194, 196, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, + 223, 225, 227, 229, 231, 234, 236, 238, 240, 242, 244, 246, 248, 251, 253, 255 +}; + + +// Gamma 1.8 +/* + const uint8_t PROGMEM gamma[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, + 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, + 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 21, + 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, + 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 43, + 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, + 91, 92, 93, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 107, 108, 109, + 110, 111, 113, 114, 115, 116, 118, 119, 120, 122, 123, 124, 126, 127, 128, 129, + 131, 132, 134, 135, 136, 138, 139, 140, 142, 143, 145, 146, 147, 149, 150, 152, + 153, 154, 156, 157, 159, 160, 162, 163, 165, 166, 168, 169, 171, 172, 174, 175, + 177, 178, 180, 181, 183, 184, 186, 188, 189, 191, 192, 194, 195, 197, 199, 200, + 202, 204, 205, 207, 208, 210, 212, 213, 215, 217, 218, 220, 222, 224, 225, 227, + 229, 230, 232, 234, 236, 237, 239, 241, 243, 244, 246, 248, 250, 251, 253, 255 + }; +*/ + +// Gamma 2.8 +/* + const uint8_t PROGMEM gamma[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, + 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, + 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, + 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, + 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, + 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, + 90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114, + 115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142, + 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175, + 177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213, + 215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255 + }; +*/ diff --git a/Other Useful Files/Fade_Gamma_Graph.m b/Other Useful Files/Fade_Gamma_Graph.m new file mode 100644 index 0000000..c06df2f --- /dev/null +++ b/Other Useful Files/Fade_Gamma_Graph.m @@ -0,0 +1,42 @@ +clc; +clear all; +close all; + +% Mono +% L=B^(gamma) +% B=L^(1/gamma) + +% Color +% L=Red^gamma+Green^gamma+Blue^gamma +% B=(Red^gamma+Green^gamma+Blue^gamma)^(1/gamma) + +%% Plot Perceived Brightness and Hue +% of Red-Yellow-Green LED Fade +% with gamma correction on each R,G,B channel +% Gamma correction can be made also as RGB LUT instead of individual +% channel + +L = 0:1:100; +L_inv = 100-(0:1:100); +Gamma = 2.2; + +Red = L_inv.^(1./Gamma); +Green = L.^(1./Gamma); +Blue = zeros(1,101); + +RGB_L = (Red.^Gamma)+(Green.^Gamma)+(Blue.^Gamma); +B = RGB_L.^(1./Gamma); +hue = atand((sqrt(3).*(Green-Blue))./(2.*Red-Green-Blue)); +hue = mod(hue,180); + +Bmax = max(B); +B = B.*(100./Bmax); + +figure % new figure +[hAx,hLine1,hLine2] = plotyy(L,B,L,hue); +ylim([0 200]); + +ylabel(hAx(1),'Perceived Brightness [%]'); +ylabel(hAx(2),'Hue [°]'); +xlabel({'Light Intensity [%]'}); +title({'Perceived Brightness vs Light Intensity'}); \ No newline at end of file diff --git a/Other Useful Files/Gamma_Graph.m b/Other Useful Files/Gamma_Graph.m new file mode 100644 index 0000000..e50e573 --- /dev/null +++ b/Other Useful Files/Gamma_Graph.m @@ -0,0 +1,14 @@ +clc; +clear all; +close all; + +L = 0:1:100; +Gamma = 2.2; +B = L.^(1./Gamma); +Bmax = 100.^(1./Gamma); +B = B.*(100./Bmax); + +plot(L,B); +ylabel({'Perceived Brightness [%]'}); +xlabel({'Light Intensity [%]'}); +title({'Perceived Brightness vs Light Intensity'}); \ No newline at end of file diff --git a/Useful Pictures/7-segm_1-digit_standard_pinout_schematic.jpg b/Useful Pictures/7-segm_1-digit_standard_pinout_schematic.jpg new file mode 100644 index 0000000..40d27b1 Binary files /dev/null and b/Useful Pictures/7-segm_1-digit_standard_pinout_schematic.jpg differ diff --git a/Useful Pictures/Color Models/02-rgb-cmyk-1920.jpg b/Useful Pictures/Color Models/02-rgb-cmyk-1920.jpg new file mode 100644 index 0000000..a858f7e Binary files /dev/null and b/Useful Pictures/Color Models/02-rgb-cmyk-1920.jpg differ diff --git a/Useful Pictures/Color Models/1200px-Hsl-hsv_models.svg.png b/Useful Pictures/Color Models/1200px-Hsl-hsv_models.svg.png new file mode 100644 index 0000000..04e74e8 Binary files /dev/null and b/Useful Pictures/Color Models/1200px-Hsl-hsv_models.svg.png differ diff --git a/Useful Pictures/Color Models/MIIVG.png b/Useful Pictures/Color Models/MIIVG.png new file mode 100644 index 0000000..f486362 Binary files /dev/null and b/Useful Pictures/Color Models/MIIVG.png differ diff --git a/Useful Pictures/Color Models/RGB_Cube_Show_lowgamma_cutout_b.png b/Useful Pictures/Color Models/RGB_Cube_Show_lowgamma_cutout_b.png new file mode 100644 index 0000000..cd998fd Binary files /dev/null and b/Useful Pictures/Color Models/RGB_Cube_Show_lowgamma_cutout_b.png differ diff --git a/Useful Pictures/Color Models/hsv_cone.jpg b/Useful Pictures/Color Models/hsv_cone.jpg new file mode 100644 index 0000000..2c7a483 Binary files /dev/null and b/Useful Pictures/Color Models/hsv_cone.jpg differ diff --git a/Useful Pictures/Color Models/rgb-color-model-rgb-color-space-png-favpng-T9xNuwh3WYxhmywckEdbww2Z2.jpg b/Useful Pictures/Color Models/rgb-color-model-rgb-color-space-png-favpng-T9xNuwh3WYxhmywckEdbww2Z2.jpg new file mode 100644 index 0000000..62b29a7 Binary files /dev/null and b/Useful Pictures/Color Models/rgb-color-model-rgb-color-space-png-favpng-T9xNuwh3WYxhmywckEdbww2Z2.jpg differ diff --git a/Useful Pictures/Color Models/rgb-vs-cmyk.jpg b/Useful Pictures/Color Models/rgb-vs-cmyk.jpg new file mode 100644 index 0000000..69f9956 Binary files /dev/null and b/Useful Pictures/Color Models/rgb-vs-cmyk.jpg differ diff --git a/Useful Pictures/Color Models/rgb_121.png b/Useful Pictures/Color Models/rgb_121.png new file mode 100644 index 0000000..de99b67 Binary files /dev/null and b/Useful Pictures/Color Models/rgb_121.png differ diff --git a/Useful Pictures/LED/Fig-S5-Energy-band-diagram-during-operation-of-a-pn-junction-diode-in-the-dark-showing.png b/Useful Pictures/LED/Fig-S5-Energy-band-diagram-during-operation-of-a-pn-junction-diode-in-the-dark-showing.png new file mode 100644 index 0000000..3cd1ae9 Binary files /dev/null and b/Useful Pictures/LED/Fig-S5-Energy-band-diagram-during-operation-of-a-pn-junction-diode-in-the-dark-showing.png differ diff --git a/Useful Pictures/LED/IV_Curve_of_different_color_LEDs.png b/Useful Pictures/LED/IV_Curve_of_different_color_LEDs.png new file mode 100644 index 0000000..23e3c76 Binary files /dev/null and b/Useful Pictures/LED/IV_Curve_of_different_color_LEDs.png differ diff --git a/Useful Pictures/LED/LED_Color_Voltage_Material_Table.jpg b/Useful Pictures/LED/LED_Color_Voltage_Material_Table.jpg new file mode 100644 index 0000000..710c9db Binary files /dev/null and b/Useful Pictures/LED/LED_Color_Voltage_Material_Table.jpg differ diff --git a/Useful Pictures/LED/LED_Voltages.png b/Useful Pictures/LED/LED_Voltages.png new file mode 100644 index 0000000..47b612a Binary files /dev/null and b/Useful Pictures/LED/LED_Voltages.png differ diff --git a/Useful Pictures/LED/RGBAW_Color_Mixing_Chart.png b/Useful Pictures/LED/RGBAW_Color_Mixing_Chart.png new file mode 100644 index 0000000..ca685df Binary files /dev/null and b/Useful Pictures/LED/RGBAW_Color_Mixing_Chart.png differ diff --git a/Useful Pictures/LED/Simple_LED_Color_Voltage_Table.jpg b/Useful Pictures/LED/Simple_LED_Color_Voltage_Table.jpg new file mode 100644 index 0000000..2ca900d Binary files /dev/null and b/Useful Pictures/LED/Simple_LED_Color_Voltage_Table.jpg differ diff --git a/Useful Pictures/Perceived_Brightness_vs_Hue_change_graph.png b/Useful Pictures/Perceived_Brightness_vs_Hue_change_graph.png new file mode 100644 index 0000000..c13b009 Binary files /dev/null and b/Useful Pictures/Perceived_Brightness_vs_Hue_change_graph.png differ diff --git a/Useful Pictures/Perceived_Brightness_vs_Light_Intensity_graph.png b/Useful Pictures/Perceived_Brightness_vs_Light_Intensity_graph.png new file mode 100644 index 0000000..60c5998 Binary files /dev/null and b/Useful Pictures/Perceived_Brightness_vs_Light_Intensity_graph.png differ