Commit 036fcd5c authored by Niels-Oliver Walkowski's avatar Niels-Oliver Walkowski
Browse files

change luminance calculation to future approach

external function calculates contrast value and returns Image with
contrast values instead of channel value (3>1). This is calcualted with
np.histogram
parent c8e8d779
......@@ -123,15 +123,17 @@ class VHistStack(View):
for frm_nr in range(self._frames.start, self._frames.end, self._frame_step):
pwd = self._frames.folder + self._frames.prefix + str(frm_nr) + '.png'
img = cv2.imread(pwd)
img = cv2.imread(pwd) # BGR
if self._contrast == 2:
_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
luminances = luminance(_img)
hist_value, _ = np.histogram(luminances, bins=self._bins, range=(0, 255))
# TODO Dictionary um Parameter auf Kontrast Funktion zu mappen
# so wie hier für 2 das ist die Referznimplementierung
# luminances gibt ein Bild mit den luminanz werten in der
# 3. Dimension zurück
if self._contrast == 2:
luminances = luminance(img)
hist_value, _ = np.histogram(luminances.flatten(), bins=self._bins, range=(0, 256))
else:
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
hist_value = cv2.calcHist([img_hsv], [self._contrast], None, [16], [0, 256])
......
......@@ -9,18 +9,19 @@ def timelabels(val, pos):
timelabel = "{0}:{1:02d}".format(min, sec)
return timelabel
# In[6]:
def luminance(img):
"""Creates an array of luminance value for each pixel of an image
The array has the same dimensions as the image. However the third
does only have the size 1 which contains the luminance value
"""
# Luminance Faktoren nach http://introcs.cs.princeton.edu/python/31datatype/luminance.py.html
luminance_factors = np.array([.299, .587, .114])
# Erzeugung eines eindimensionalen Arrays für die effizientere Berechnung
_img = img.reshape((img.shape[0]*img.shape[1]), img.shape[2])
_img = np.multiply(_img, luminance_factors)
img = np.multiply(img, luminance_factors)
# addiert alle Werte auf einer bestimmten Achse
luminances = np.sum(_img, axis=1)
luminances = np.sum(img, axis=2)
return luminances
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment