Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DIRECTORY.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,6 +75,7 @@

## Cellular Automata
* [Conways Game Of Life](cellular_automata/conways_game_of_life.py)
* [Elementary Cellular Automaton](cellular_automata/elementary_cellular_automaton.py)
* [Game Of Life](cellular_automata/game_of_life.py)
* [Langtons Ant](cellular_automata/langtons_ant.py)
* [Nagel Schrekenberg](cellular_automata/nagel_schrekenberg.py)
Expand DownExpand Up@@ -294,6 +295,7 @@
* [Dijkstras Two Stack Algorithm](data_structures/stacks/dijkstras_two_stack_algorithm.py)
* [Infix To Postfix Conversion](data_structures/stacks/infix_to_postfix_conversion.py)
* [Infix To Prefix Conversion](data_structures/stacks/infix_to_prefix_conversion.py)
* [Kth Next Greater Element](data_structures/stacks/kth_next_greater_element.py)
* [Largest Rectangle Histogram](data_structures/stacks/largest_rectangle_histogram.py)
* [Lexicographical Numbers](data_structures/stacks/lexicographical_numbers.py)
* [Next Greater Element](data_structures/stacks/next_greater_element.py)
Expand DownExpand Up@@ -426,6 +428,8 @@
* [Electric Conductivity](electronics/electric_conductivity.py)
* [Electric Power](electronics/electric_power.py)
* [Electrical Impedance](electronics/electrical_impedance.py)
* [Full Wave Rectifier](electronics/full_wave_rectifier.py)
* [Half Wave Rectifier](electronics/half_wave_rectifier.py)
* [Ic 555 Timer](electronics/ic_555_timer.py)
* [Ind Reactance](electronics/ind_reactance.py)
* [Ohms Law](electronics/ohms_law.py)
Expand DownExpand Up@@ -766,6 +770,7 @@
* [Quadratic Equations Complex Numbers](maths/quadratic_equations_complex_numbers.py)
* [Radians](maths/radians.py)
* [Radix2 Fft](maths/radix2_fft.py)
* [Recursive Digit Sum](maths/recursive_digit_sum.py)
* [Remove Digit](maths/remove_digit.py)
* [Segmented Sieve](maths/segmented_sieve.py)
* Series
Expand DownExpand Up@@ -1389,6 +1394,9 @@
* [Word Patterns](strings/word_patterns.py)
* [Z Function](strings/z_function.py)

## Tests
* [Test Sorts](tests/test_sorts.py)

## Web Programming
* [Co2 Emission](web_programming/co2_emission.py)
* [Covid Stats Via Xpath](web_programming/covid_stats_via_xpath.py)
Expand Down
27 changes: 27 additions & 0 deletions digital_image_processing/change_brightness.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,33 @@
def change_brightness(img: Image, level: float) -> Image:
"""
Change the brightness of a PIL Image to a given level.

Args:
img: PIL Image to adjust
level: Brightness level adjustment (-255.0 to 255.0)
Negative values darken, positive values brighten

Returns:
New PIL Image with adjusted brightness

Raises:
ValueError: If level is not in range [-255.0, 255.0]

>>> from PIL import Image
>>> import numpy as np
>>> img = Image.new('RGB', (2, 2), color=(100, 100, 100))
>>> bright = change_brightness(img, 50)
>>> px = bright.load()
>>> px[0, 0]
(150, 150, 150)
>>> dark = change_brightness(img, -50)
>>> px_dark = dark.load()
>>> px_dark[0, 0]
(50, 50, 50)
>>> change_brightness(img, 300)
Traceback (most recent call last):
...
ValueError: level must be between -255.0 (black) and 255.0 (white)
"""

def brightness(c: int) -> float:
Expand Down
Loading