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
scienceopen
committed
Aug 18, 2016
1 parent
ca70c6e
commit dd296e5
Showing
2 changed files
with
101 additions
and
101 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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
#!/usr/bin/env python | ||
""" | ||
read an AVI and do LBP on it | ||
""" | ||
from pyimagevideo import Path | ||
import cv2 #used to read AVI and for high-speed display | ||
from skimage.feature import local_binary_pattern | ||
# | ||
#from cvutils.getaviprop import getaviprop | ||
|
||
def demoLBP(fn): | ||
fn = Path(fn).expanduser() | ||
vid = cv2.VideoCapture(str(fn)) | ||
# vidparam = getaviprop(vid) | ||
|
||
while True: | ||
ret,img = vid.read() | ||
if not ret: | ||
break | ||
if img.ndim==3: | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
lbp = local_binary_pattern(img,8,3,'default') | ||
cv2.imshow('lbp',lbp) | ||
cv2.waitKey(delay=1) | ||
|
||
if __name__ == '__main__': | ||
from argparse import ArgumentParser | ||
p= ArgumentParser(description='load avi and demo LBP alg.') | ||
p.add_argument('avifn',help='.avi file to process') | ||
p = p.parse_args() | ||
|
||
demoLBP(p.avifn) | ||
#!/usr/bin/env python | ||
""" | ||
read an AVI and do LBP on it | ||
""" | ||
from pyimagevideo import Path | ||
import cv2 #used to read AVI and for high-speed display | ||
from skimage.feature import local_binary_pattern | ||
# | ||
#from cvutils.getaviprop import getaviprop | ||
|
||
def demoLBP(fn): | ||
fn = Path(fn).expanduser() | ||
vid = cv2.VideoCapture(str(fn)) | ||
# vidparam = getaviprop(vid) | ||
|
||
while True: | ||
ret,img = vid.read() | ||
if not ret: | ||
break | ||
if img.ndim==3: | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
lbp = local_binary_pattern(img,8,3,'default') | ||
cv2.imshow('lbp',lbp) | ||
cv2.waitKey(delay=1) | ||
|
||
if __name__ == '__main__': | ||
from argparse import ArgumentParser | ||
p= ArgumentParser(description='load avi and demo LBP alg.') | ||
p.add_argument('avifn',help='.avi file to process') | ||
p = p.parse_args() | ||
|
||
demoLBP(p.avifn) |
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 |
---|---|---|
@@ -1,69 +1,69 @@ | ||
#!/usr/bin/env python | ||
from __future__ import division | ||
|
||
def wavelength_to_rgb(wavelength, gamma=0.8): | ||
|
||
''' | ||
noah.org | ||
http://www.noah.org/wiki/Wavelength_to_RGB_in_Python | ||
This converts a given wavelength into an approximate RGB value. | ||
The given wavelength is in nanometers. | ||
The range of wavelength is 380 nm through 750 nm. | ||
Based on code by Dan Bruton | ||
http://www.physics.sfasu.edu/astro/color/spectra.html | ||
''' | ||
|
||
wavelength = float(wavelength) | ||
if 440. >= wavelength >= 380.: | ||
attenuation = 0.3 + 0.7 * (wavelength - 380) / (440 - 380) | ||
R = ((-(wavelength - 440) / (440 - 380)) * attenuation) ** gamma | ||
G = 0. | ||
B = (1. * attenuation) ** gamma | ||
elif wavelength >= 440 and wavelength <= 490: | ||
R = 0.0 | ||
G = ((wavelength - 440) / (490 - 440)) ** gamma | ||
B = 1. | ||
elif wavelength >= 490 and wavelength <= 510: | ||
R = 0. | ||
G = 1. | ||
B = (-(wavelength - 510) / (510 - 490)) ** gamma | ||
elif wavelength >= 510 and wavelength <= 580: | ||
R = ((wavelength - 510) / (580 - 510)) ** gamma | ||
G = 1. | ||
B = 0. | ||
elif wavelength >= 580 and wavelength <= 645: | ||
R = 1.0 | ||
G = (-(wavelength - 645) / (645 - 580)) ** gamma | ||
B = 0. | ||
elif wavelength >= 645 and wavelength <= 750: | ||
attenuation = 0.3 + 0.7 * (750 - wavelength) / (750 - 645) | ||
R = (1.0 * attenuation) ** gamma | ||
G = 0. | ||
B = 0. | ||
else: | ||
R = 0. | ||
G = 0. | ||
B = 0. | ||
|
||
R = int(R*255) | ||
G = int(G*255) | ||
B = int(B*255) | ||
|
||
assert 255>=R>=0 and 255>=G>=0 and 255>=B>=0 | ||
|
||
return R,G,B | ||
|
||
if __name__ == '__main__': | ||
from argparse import ArgumentParser | ||
p = ArgumentParser() | ||
p.add_argument('wavelength_nm',help='wavelength in nm',type=float) | ||
p.add_argument('--gamma',type=float,default=0.8) | ||
p = p.parse_args() | ||
|
||
R,G,B = wavelength_to_rgb(p.wavelength_nm,p.gamma) | ||
|
||
print(R) | ||
print(G) | ||
print(B) | ||
#!/usr/bin/env python | ||
from __future__ import division | ||
|
||
def wavelength_to_rgb(wavelength, gamma=0.8): | ||
|
||
''' | ||
noah.org | ||
http://www.noah.org/wiki/Wavelength_to_RGB_in_Python | ||
This converts a given wavelength into an approximate RGB value. | ||
The given wavelength is in nanometers. | ||
The range of wavelength is 380 nm through 750 nm. | ||
Based on code by Dan Bruton | ||
http://www.physics.sfasu.edu/astro/color/spectra.html | ||
''' | ||
|
||
wavelength = float(wavelength) | ||
if 440. >= wavelength >= 380.: | ||
attenuation = 0.3 + 0.7 * (wavelength - 380) / (440 - 380) | ||
R = ((-(wavelength - 440) / (440 - 380)) * attenuation) ** gamma | ||
G = 0. | ||
B = (1. * attenuation) ** gamma | ||
elif wavelength >= 440 and wavelength <= 490: | ||
R = 0.0 | ||
G = ((wavelength - 440) / (490 - 440)) ** gamma | ||
B = 1. | ||
elif wavelength >= 490 and wavelength <= 510: | ||
R = 0. | ||
G = 1. | ||
B = (-(wavelength - 510) / (510 - 490)) ** gamma | ||
elif wavelength >= 510 and wavelength <= 580: | ||
R = ((wavelength - 510) / (580 - 510)) ** gamma | ||
G = 1. | ||
B = 0. | ||
elif wavelength >= 580 and wavelength <= 645: | ||
R = 1.0 | ||
G = (-(wavelength - 645) / (645 - 580)) ** gamma | ||
B = 0. | ||
elif wavelength >= 645 and wavelength <= 750: | ||
attenuation = 0.3 + 0.7 * (750 - wavelength) / (750 - 645) | ||
R = (1.0 * attenuation) ** gamma | ||
G = 0. | ||
B = 0. | ||
else: | ||
R = 0. | ||
G = 0. | ||
B = 0. | ||
|
||
R = int(R*255) | ||
G = int(G*255) | ||
B = int(B*255) | ||
|
||
assert 255>=R>=0 and 255>=G>=0 and 255>=B>=0 | ||
|
||
return R,G,B | ||
|
||
if __name__ == '__main__': | ||
from argparse import ArgumentParser | ||
p = ArgumentParser() | ||
p.add_argument('wavelength_nm',help='wavelength in nm',type=float) | ||
p.add_argument('--gamma',type=float,default=0.8) | ||
p = p.parse_args() | ||
|
||
R,G,B = wavelength_to_rgb(p.wavelength_nm,p.gamma) | ||
|
||
print(R) | ||
print(G) | ||
print(B) |