This repository has been archived by the owner on Mar 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
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
0 parents
commit 830db47
Showing
4 changed files
with
318 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,2 @@ | ||
data/ | ||
venv/ |
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,54 @@ | ||
#coding: utf-8 | ||
|
||
from PIL import Image | ||
|
||
SIZE = 150, 150 | ||
THRESHOLD = 0.5 | ||
|
||
|
||
def prepare_image(image): | ||
if not image.mode == 'RGB': | ||
image = image.convert(mode='RGB') | ||
image.thumbnail(SIZE, Image.ANTIALIAS) | ||
return image | ||
|
||
|
||
def get_ycbcr(image): | ||
ret = [] | ||
|
||
def rgb2ycbcr(r, g, b): | ||
return ( | ||
16 + (65.738 * r + 129.057 * g + 25.064 * b) / 256, | ||
128 + (-37.945 * r - 74.494 * g + 112.439 * b) / 256, | ||
128 + (112.439 * r - 94.154 * g - 18.285 * b) / 256 | ||
) | ||
|
||
x, y = image.size | ||
for i in range(0, x): | ||
for j in range(0, y): | ||
ret.append(rgb2ycbcr(*image.getpixel((i, j)))) | ||
|
||
return ret | ||
|
||
|
||
def detect(image): | ||
|
||
def judge(sample): | ||
y, cb, cr = sample | ||
|
||
return 80 <= cb <= 120 and 133 <= cr <= 173 | ||
|
||
image = prepare_image(image) | ||
ycbcr = get_ycbcr(image) | ||
|
||
judged = map(judge, ycbcr) | ||
|
||
rating = float(judged.count(True)) / len(judged) | ||
return rating > THRESHOLD, rating | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
print sys.argv[-1] | ||
image = Image.open(sys.argv[-1]) | ||
print detect(image) |
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,240 @@ | ||
data/postive/00048.png | ||
(True, 0.6235119047619048) | ||
data/postive/00106.png | ||
(True, 0.5876190476190476) | ||
data/postive/00064.png | ||
(True, 0.6466666666666666) | ||
data/postive/00031.png | ||
(True, 0.7152380952380952) | ||
data/postive/00071.png | ||
(True, 0.5908928571428571) | ||
data/postive/00101.png | ||
(True, 0.589047619047619) | ||
data/postive/00068.png | ||
(True, 0.6064285714285714) | ||
data/postive/00047.png | ||
(True, 0.6116666666666667) | ||
data/postive/00021.png | ||
(True, 0.5545238095238095) | ||
data/postive/00077.png | ||
(True, 0.5882142857142857) | ||
data/postive/00002.png | ||
(True, 0.6288690476190476) | ||
data/postive/00027.png | ||
(True, 0.6269047619047619) | ||
data/postive/00073.png | ||
(True, 0.6463095238095238) | ||
data/postive/00014.png | ||
(True, 0.554047619047619) | ||
data/postive/00062.png | ||
(True, 0.6133928571428572) | ||
data/postive/00081.png | ||
(True, 0.6083928571428572) | ||
data/postive/00039.png | ||
(True, 0.6042261904761905) | ||
data/postive/00087.png | ||
(True, 0.6113690476190476) | ||
data/postive/00096.png | ||
(True, 0.5958333333333333) | ||
data/postive/00094.png | ||
(True, 0.6581547619047619) | ||
data/postive/00022.png | ||
(True, 0.5251785714285714) | ||
data/postive/00063.png | ||
(True, 0.6993452380952381) | ||
data/postive/00095.png | ||
(True, 0.6039880952380953) | ||
data/postive/00009.png | ||
(True, 0.5471428571428572) | ||
data/postive/00015.png | ||
(True, 0.5661904761904762) | ||
data/postive/00029.png | ||
(True, 0.6114880952380952) | ||
data/postive/00072.png | ||
(True, 0.644702380952381) | ||
data/postive/00043.png | ||
(True, 0.64875) | ||
data/postive/00000.png | ||
(True, 0.6039285714285715) | ||
data/postive/00033.png | ||
(True, 0.7180357142857143) | ||
data/postive/00008.png | ||
(True, 0.5373809523809524) | ||
data/postive/00057.png | ||
(True, 0.56375) | ||
data/postive/00085.png | ||
(True, 0.633452380952381) | ||
data/postive/00054.png | ||
(True, 0.5672619047619047) | ||
data/postive/00098.png | ||
(True, 0.6000595238095238) | ||
data/postive/00089.png | ||
(True, 0.6322023809523809) | ||
data/postive/00024.png | ||
(True, 0.6479166666666667) | ||
data/postive/00007.png | ||
(True, 0.6205357142857143) | ||
data/postive/00040.png | ||
(True, 0.6130952380952381) | ||
data/postive/00013.png | ||
(True, 0.5686309523809524) | ||
data/postive/00025.png | ||
(True, 0.6668452380952381) | ||
data/postive/00076.png | ||
(True, 0.5938095238095238) | ||
data/postive/00103.png | ||
(True, 0.6061309523809524) | ||
data/postive/00090.png | ||
(True, 0.6117857142857143) | ||
data/postive/00074.png | ||
(True, 0.6151190476190476) | ||
data/postive/00032.png | ||
(True, 0.6975) | ||
data/postive/00086.png | ||
(True, 0.6021428571428571) | ||
data/postive/00079.png | ||
(True, 0.6120238095238095) | ||
data/postive/00020.png | ||
(True, 0.5838690476190476) | ||
data/postive/00049.png | ||
(True, 0.6299404761904762) | ||
data/postive/00067.png | ||
(True, 0.645952380952381) | ||
data/postive/00001.png | ||
(True, 0.6116071428571429) | ||
data/postive/00091.png | ||
(True, 0.6043452380952381) | ||
data/postive/00035.png | ||
(True, 0.6308928571428571) | ||
data/postive/00017.png | ||
(True, 0.6097619047619047) | ||
data/postive/00092.png | ||
(True, 0.6195238095238095) | ||
data/postive/00075.png | ||
(True, 0.5994642857142857) | ||
data/postive/00082.png | ||
(True, 0.5964285714285714) | ||
data/postive/00051.png | ||
(True, 0.5653571428571429) | ||
data/postive/00030.png | ||
(True, 0.692202380952381) | ||
data/postive/00036.png | ||
(True, 0.6426190476190476) | ||
data/postive/00046.png | ||
(True, 0.6521428571428571) | ||
data/postive/00053.png | ||
(True, 0.5578571428571428) | ||
data/postive/00065.png | ||
(True, 0.6366666666666667) | ||
data/postive/00012.png | ||
(True, 0.5616071428571429) | ||
data/postive/00019.png | ||
(True, 0.6168452380952381) | ||
data/postive/00050.png | ||
(True, 0.5573214285714285) | ||
data/postive/00006.png | ||
(True, 0.6714285714285714) | ||
data/postive/00045.png | ||
(True, 0.6432142857142857) | ||
data/postive/00003.png | ||
(True, 0.6649404761904761) | ||
data/postive/00055.png | ||
(True, 0.5667261904761904) | ||
data/postive/00005.png | ||
(True, 0.6779166666666666) | ||
data/postive/00066.png | ||
(True, 0.659047619047619) | ||
data/postive/00108.png | ||
(True, 0.5617857142857143) | ||
data/postive/00026.png | ||
(True, 0.6560119047619047) | ||
data/postive/00060.png | ||
(True, 0.555952380952381) | ||
data/postive/00041.png | ||
(True, 0.5967857142857143) | ||
data/postive/00107.png | ||
(True, 0.6043452380952381) | ||
data/postive/00088.png | ||
(True, 0.6160714285714286) | ||
data/postive/00100.png | ||
(True, 0.5979761904761904) | ||
data/postive/00056.png | ||
(True, 0.5644642857142858) | ||
data/postive/00069.png | ||
(True, 0.5889285714285715) | ||
data/postive/00070.png | ||
(True, 0.5879166666666666) | ||
data/postive/00038.png | ||
(True, 0.5899404761904762) | ||
data/postive/00037.png | ||
(True, 0.5929166666666666) | ||
data/postive/00023.png | ||
(True, 0.5734523809523809) | ||
data/postive/00034.png | ||
(True, 0.5686904761904762) | ||
data/postive/00052.png | ||
(True, 0.5663095238095238) | ||
data/postive/00061.png | ||
(True, 0.5467857142857143) | ||
data/postive/00099.png | ||
(True, 0.601547619047619) | ||
data/postive/00058.png | ||
(True, 0.5482738095238096) | ||
data/postive/00080.png | ||
(True, 0.5936309523809524) | ||
data/postive/00084.png | ||
(True, 0.6533333333333333) | ||
data/postive/00010.png | ||
(True, 0.5229166666666667) | ||
data/postive/00093.png | ||
(True, 0.6169642857142857) | ||
data/postive/00018.png | ||
(True, 0.6216071428571428) | ||
data/postive/00044.png | ||
(True, 0.6166666666666667) | ||
data/postive/00004.png | ||
(True, 0.6763690476190476) | ||
data/postive/00042.png | ||
(True, 0.5750595238095239) | ||
data/postive/00104.png | ||
(True, 0.5960714285714286) | ||
data/postive/00011.png | ||
(True, 0.539047619047619) | ||
data/postive/00097.png | ||
(True, 0.6188095238095238) | ||
data/postive/00105.png | ||
(True, 0.5352380952380953) | ||
data/postive/00016.png | ||
(True, 0.6145238095238095) | ||
data/postive/00059.png | ||
(True, 0.5429761904761905) | ||
data/postive/00028.png | ||
(True, 0.6192857142857143) | ||
data/postive/00102.png | ||
(True, 0.6073214285714286) | ||
data/postive/00078.png | ||
(True, 0.59375) | ||
data/postive/00083.png | ||
(True, 0.626547619047619) | ||
data/negative/00002.png | ||
(False, 0.03357142857142857) | ||
data/negative/00009.png | ||
(False, 0.02) | ||
data/negative/00000.png | ||
(False, 0.0) | ||
data/negative/00008.png | ||
(False, 0.06246031746031746) | ||
data/negative/00007.png | ||
(False, 0.01) | ||
data/negative/00001.png | ||
(False, 0.008015873015873016) | ||
data/negative/00006.png | ||
(False, 0.02761904761904762) | ||
data/negative/00003.png | ||
(False, 0.010714285714285714) | ||
data/negative/00005.png | ||
(False, 0.0002380952380952381) | ||
data/negative/00010.png | ||
(False, 0.06587301587301587) | ||
data/negative/00004.png | ||
(False, 0.0) |
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,22 @@ | ||
#coding: utf-8 | ||
|
||
from PIL import Image | ||
|
||
from detect import get_ycbcr | ||
|
||
|
||
def main(name): | ||
image = Image.open(name) | ||
ycbcr_image = Image.new('RGB', image.size, 'black') | ||
ycbcr, pixels = get_ycbcr(image), ycbcr_image.load() | ||
|
||
for i in range(0, image.size[0]): | ||
for j in range(0, image.size[1]): | ||
pixels[i, j] = tuple(map(int, ycbcr[i * image.size[1] + j])) | ||
|
||
ycbcr_image.show() | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
main(sys.argv[-1]) |