Skip to content

Commit 92b98e4

Browse files
committed
Update 2020 🎉
1 parent 10f134d commit 92b98e4

32 files changed

+359
-142
lines changed

README.md

Lines changed: 0 additions & 89 deletions
This file was deleted.

Readme.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# How to find if an image is bright or dark?
2+
### Concept
3+
4+
- Input image is resized to `10x10` pixel, to reduce the computation.
5+
- Convert it to `LAB` color space to access the luminous channel which is independent of colors.
6+
- Normalize pixel values to be in range of `0 - 1`.
7+
- Compare the `mean` value of pixels with an `threshold` value.
8+
9+
### External modules
10+
11+
```
12+
>> pip install opencv-python
13+
>> pip install numpy
14+
```
15+
### How to run
16+
17+
- **Demo**: [Colab Notebook](https://colab.research.google.com/github/imneonizer/How-to-find-if-an-image-is-bright-or-dark/blob/master/demo.ipynb)
18+
19+
- **Execute program**
20+
21+
````
22+
python run.py
23+
````
24+
25+
- It will read images from `images` directory and classify it as bright or dark.
26+
- It will separate and save images to `output/bright` directory and `output/dark` directory accordingly.
27+
28+
- **Sample Dark Images**
29+
30+
<table>
31+
<tr>
32+
<img src="images/c76f1.jpg", height=220>
33+
<img src="images/c2e07.jpg", height=220>
34+
</tr>
35+
</table>
36+
37+
- **Sample Bright Images**
38+
39+
<table>
40+
<tr>
41+
<img src="images/0acbf.jpg", height=220>
42+
<img src="images/2d37f.jpg", height=220>
43+
</tr>
44+
</table>
45+
46+
- The function calculate brightness level in range of 0-1, hence you can decide on a threshold to treat images either as bright or dark.
47+
48+
````python
49+
def isbright(image, dim=10, thresh=0.5):
50+
# Resize image to 10x10
51+
image = cv2.resize(image, (dim, dim))
52+
# Convert color space to LAB format and extract L channel
53+
L, A, B = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2LAB))
54+
# Normalize L channel by dividing all pixel values with maximum pixel value
55+
L = L/np.max(L)
56+
# Return True if mean is greater than thresh else False
57+
return np.mean(L) > thresh
58+
````
59+
60+
- For a better result you can tweak with `dim` parameter, it will preserve more pixels while calculating brightness levels.
61+
62+
- Don't forget to star the repository.
63+

assets/1.jpg

-358 KB
Binary file not shown.

assets/2.jpg

-578 KB
Binary file not shown.

assets/3.jpg

-339 KB
Binary file not shown.

assets/4.jpg

-410 KB
Binary file not shown.

assets/bright.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
https://cdn.wallpapersafari.com/72/78/IWXnua.jpg
2+
https://d2halst20r4hcy.cloudfront.net/wallpapers2/…6/467/200/original/740186awesomebluewallpaper.jpg
3+
https://img3.goodfon.com/original/9380x6016/a/97/sunbeam-landscape.jpg
4+
https://courses.cs.washington.edu/courses/csep557/16au/projects/impressionist/artifacts/12/photo.png
5+
https://i.pinimg.com/736x/fd/27/48/fd27484cff7eeabbd1874eb3b4460a65--background-images-gallerie.jpg
6+
https://image.winudf.com/v2/image/Y29tLmNvbG9yZnVs…MzM5NDQyMDVfMDg2/screen-9.jpg?fakeurl=1&type=.jpg
7+
https://www.filepicker.io/api/file/6sXRgCMTQyqVw2xPSw7X
8+
https://pro-photos.net/img/pictures/nature_field/big/43.jpg
9+
https://hd-wallpapersfd.info/wp-content/uploads/HTML/Mountain-Sunrise/Mountain-Sunrise41.jpg
10+
https://wallpapercave.com/wp/wp2912624.jpg
11+
https://e.piclect.com/o200110_2961c.jpg
12+
https://img1.goodfon.com/original/2560x1440/5/87/yarkie-raznocvetnye-volny.jpg
13+
https://i.ytimg.com/vi/Sk9XYQMRiLY/maxresdefault.jpg
14+
https://cutewallpaper.org/21/hd-skies/Background-Nature-Hd-Sky-Green-Grass-And-Blue-Sky-Free-.jpg
15+
https://img.wallpapersafari.com/desktop/1600/900/26/6/OPySdV.jpg
16+
https://staceyebryan.files.wordpress.com/2019/02/the-bright-sun-blue-sky-clouds.jpg
17+
https://cdn.wallpapersafari.com/98/51/I8yAl0.jpg
18+
https://hd-wallpapersfd.info/wp-content/uploads/HTML/Wallpaper-colors/Wallpaper-colors35.jpg
19+
https://hdblackwallpaper.com/wallpaper/2015/09/bla…d-yellow-abstract-wallpaper-18-free-wallpaper.jpg
20+
https://img3.goodfon.com/original/1920x1200/a/4f/sprey-cveta-raznocvetnyy.jpg
21+
https://anband.spb.ru/images/600/DSC100651539.jpg
22+
https://cdn.wallpapersafari.com/52/85/uqGdmr.jpg
23+
https://st.depositphotos.com/1025323/4100/i/950/de…photos_41007721-stock-photo-colorful-dynamics.jpg
24+
https://million-wallpapers.com/wallpapers/4/30/15104296249737558007/explosion-of-colors.jpg
25+
http://images4.fanpop.com/image/photos/20000000/A-…nbow-of-Color-bright-colors-20035250-1024-768.jpg
26+
https://artsdot.com/ADC/Photos-ImgScreen.nsf/O/P-A…FILE/Abstract_-_surrealism-bright_stains_228_.Jpg
27+
https://bgfons.com/uploads/light/light_texture2285.jpg
28+
https://wallpapercave.com/wp/wp2112254.jpg
29+
https://inn.spb.ru/images/000/DSC100086482.jpg
30+
https://www.desktopbackground.org/download/o/2011/…_bright-color-backgrounds-1438692_1920x1080_h.jpg
31+
https://nnimgt-a.akamaihd.net/transform/v1/crop/fr…f57e69f550.jpg/r0_25_1100_647_w1200_h678_fmax.jpg
32+
https://cdn.discordapp.com/attachments/615266262628696067/666077531648294917/triumph-19.jpg
33+
https://i.imgur.com/QNS2062.jpg
34+
https://betterifyouknow.com/wp-content/uploads/2020/06/birth-color.jpg
35+
https://i.pinimg.com/originals/7e/72/98/7e7298aa365d776e7ca34f11c9298ee9.jpg
36+
https://cdn.wallpapersafari.com/43/58/Z2m5D8.jpg
37+
https://1.bp.blogspot.com/-vUFPNZ0KNKw/UEzVfqA36eI…lourful+flowers+Hd+background+wallpapers.+(2).jpg
38+
https://momsincharge.files.wordpress.com/2012/03/spring2.jpg
39+
https://f.fbchatcodemaker.com/uploads/2015/03/Colourful-Balls-1366-x-768-HDTV.jpeg
40+
https://wallpapertag.com/wallpaper/full/e/f/2/374451-bubble-background-2560x1440-1080p.jpg
41+
http://cdn.mos.cms.futurecdn.net/6ACuquHv6sxtPY3Za9nUK7.jpg
42+
https://cdn.hipwallpaper.com/i/42/6/tHyl6N.jpg
43+
https://oren-m7.ru/images/600/DSC100652460.jpg
44+
https://watchmanofthelowerlights.files.wordpress.com/2018/01/glory-of-god.jpg?w=2200
45+
https://img.wallpapersafari.com/desktop/1680/1050/30/13/eiTbA3.jpg
46+
https://get.wallhere.com/photo/sunlight-landscape-…ronomical-object-grass-family-brassica-226070.jpg
47+
http://st.gde-fon.com/wallpapers_original/77535_pr…va_nebo_solnce_svet_2080x1441_www.Gde-Fon.com.jpg
48+
http://www.datsuncarsandparts.com/data/archive/img/2433536476.jpeg
49+
http://thegoodheart.net/wp-content/uploads/2019/03/Be-Brave-1170x780.jpg
50+
https://cutewallpaper.org/21/hd-sky-backgrounds/64-Blue-Sky-Wallpapers-on-WallpaperPlay.jpg

assets/dark.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
https://million-wallpapers.com/wallpapers/0/80/331689577664439/white-autumn-night.jpg
2+
https://cdn.wallpapersafari.com/2/25/1kCghX.jpg
3+
https://cdn.wallpapersafari.com/38/73/EqvkJx.jpg
4+
https://i.pinimg.com/originals/ce/2b/13/ce2b1371e720ba8bc7d04cae444869e4.jpg
5+
https://cdn.wallpapersafari.com/1/31/yGtZxa.jpg
6+
https://images-wixmp-ed30a86b8c4ca887773594c2.wixm…MiXX0.VpjiLvERgLgmWONMOcYIfsQBn6kVspLn8HAtGsKX8SU
7+
https://dodskypict.com/D/Dark-Forest-Wallpaper-On-Wallpaper-Hd-1.jpg
8+
https://i.ytimg.com/vi/eoQ9ahjH-qY/maxresdefault.jpg
9+
http://wp.widewallpapers.net/2k/roads/1920x1080/road-1920x1080-081.jpg
10+
https://i.imgur.com/wwANrcC.jpg
11+
https://cdn.wallpapersafari.com/65/16/eLTp0o.jpg
12+
https://cutewallpaper.org/21/dark-wallpapers-and-b…Wallpapers-and-Backgrounds-on-WallpaperSafari.jpg
13+
https://animation.adni18.com/data/thumbnails/1/Forest.jpg
14+
http://getwallpapers.com/wallpaper/full/7/e/b/266172.jpg
15+
https://wallpapercave.com/wp/wp2260607.jpg
16+
https://static.pexels.com/photos/4241/cold-snow-black-and-white-road.jpg
17+
https://cdn.wallpapersafari.com/85/79/P0T98m.jpg
18+
https://www.fotosdelanaturaleza.es/wp-content/uplo…wallpapers-fotosdelanaturaleza.es-19-1024x640.jpg
19+
https://cdn.wallpapersafari.com/84/83/tEem56.jpg
20+
https://wallpapertag.com/wallpaper/full/4/3/d/236382-full-size-wizard-wallpaper-1920x1080-photo.jpg
21+
https://cdn.wallpapersafari.com/66/28/InlShD.jpg
22+
https://get.wallhere.com/photo/fantasy-art-dark-sp…hot-computer-wallpaper-macro-photography-2508.jpg
23+
https://oren-m7.ru/images/100/DSC100164613.jpeg
24+
https://cdn.wallpapersafari.com/74/6/jLEoA8.jpg
25+
https://wallpapertag.com/wallpaper/full/c/6/8/437795-gorgerous-dark-clouds-wallpaper-3000x2000.jpg
26+
https://i.imgur.com/lBijg9n.jpg
27+
https://i.pinimg.com/736x/84/73/bc/8473bcbc4b3a9944bbaa7f4183e49e10.jpg
28+
https://cdn.wallpapersafari.com/87/17/KQun0h.jpg
29+
https://wallup.net/wp-content/uploads/2017/11/22/3…tle-cathedral-bridge-Moon-screen_shot-village.jpg
30+
http://lh5.ggpht.com/-cMV85A1VP0w/UuzCHLFonGI/AAAA…0/IfCFHrf_i_8/s72-c/LOOK-UP_thumb5.jpg?imgmax=800
31+
http://s4.favim.com/orig/140402/foggy-forest-girl-misty-Favim.com-1597804.jpg
32+
https://www.pixel-creation.com/wp-content/uploads/…creen-hd-images-3-hd-wallpapers-welcome-to-my.jpg
33+
https://yt3.ggpht.com/a/AATXAJyB6Q2Pr7QTxX8hHyFTLm_VQqiaFUywM_cgbEPh=s900-c-k-c0xffffffff-no-rj-mo
34+
https://wallpapertag.com/wallpaper/full/a/e/7/7833…3-hd-wallpapers-1080p-1920x1080-for-iphone-5s.jpg
35+
https://wallpapertag.com/wallpaper/full/5/e/8/470734-top-hd-wolf-wallpapers-1920x1080-for-mac.jpg
36+
https://i.imgur.com/ZmWmlfd.jpg
37+
https://i.pinimg.com/736x/93/f2/f2/93f2f2c76e83f77dc507cd4a95d6fa76--scary-costumes-lost-soul.jpg
38+
https://wallpaper-mania.com/wp-content/uploads/201…esolution_wallpaper_background_ID_77701041754.jpg
39+
https://img.wallpapersafari.com/desktop/1680/1050/68/36/JKYg89.jpg
40+
https://i.pinimg.com/736x/1f/67/a2/1f67a21008fa310c6b20e9b41833fe52--magical-forest-dark-forest.jpg
41+
http://pm1.narvii.com/7270/710de74edbcb21058ce4b79f2676d6a4cf9f44aar1-800-600v2_uhq.jpg
42+
https://scene360.com/wp-content/uploads/2014/07/federico-bebber-08.jpg
43+
https://www.wallpapermaiden.com/wallpaper/1335/dow…2880x1800/alone-in-the-dark-thriller-building.jpg
44+
https://wallup.net/wp-content/uploads/2018/10/01/6…178-dark-creepy-scary-horror-evil-art-artwork.jpg
45+
https://img.wallpapersafari.com/desktop/1920/1080/70/86/ByQ2vr.jpg
46+
https://avante.biz/wp-content/uploads/Dark-Image-Wallpapers/Dark-Image-Wallpapers-021.jpg
47+
https://upload.wikimedia.org/wikipedia/commons/0/0a/Dark_Moon_Max_Frear_2008.JPG
48+
https://hdwallpaperim.com/wp-content/uploads/2017/08/24/101673-forest-mist-spooky.jpg
49+
https://i.imgur.com/74uBLJR.jpg
50+
https://wallup.net/wp-content/uploads/2018/10/03/9…lic-horror-evil-creepy-scary-spooky-halloween.jpg

calculate_brightness.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

demo.ipynb

Lines changed: 138 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)