Commit 94dc0ada authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'issue-5-remove-io-dependency' into 'master'

[conda] make bob.io. packages test requirements

Closes #5

See merge request !14
parents 14a830cb 36db28f9
Pipeline #41162 passed with stages
in 14 minutes and 14 seconds
......@@ -2,23 +2,19 @@
# vim: set fileencoding=utf-8 :
import sys
import argparse
import bob.io.base
import bob.io.video
import bob.ip.color
import numpy as np
from bob.ip.qualitymeasure import galbally_iqm_features as iqm
from bob.ip.qualitymeasure import msu_iqa_features as iqa
def computeVideoIQM(video4d):
'''computes image-quality features for a set of frames comprising a video.
"""computes image-quality features for a set of frames comprising a video.
@param video4d: a '4d' video (N frames, each frame representing an r-g-b
image). returns a set of feature-vectors, 1 vector per frame of
video4d
'''
"""
from bob.ip.qualitymeasure import galbally_iqm_features as iqm
from bob.ip.qualitymeasure import msu_iqa_features as iqa
import numpy as np
numframes = video4d.shape[0]
numframes = 3
# print(numframes)
......@@ -26,7 +22,7 @@ def computeVideoIQM(video4d):
# process first frame separately, to get the no. of iqm features
f = 0
rgbFrame = video4d[f]
print('processing frame #: %d' % f)
print("processing frame #: %d" % f)
# iqmSet = iqm.compute_quality_features(grayFrame)
iqmSet = iqm.compute_quality_features(rgbFrame)
numIQM = len(iqmSet)
......@@ -40,9 +36,9 @@ def computeVideoIQM(video4d):
msufset[f] = iqaSet
for f in range(1, numframes):
print('processing frame #: %d' % f)
print("processing frame #: %d" % f)
rgbFrame = video4d[f]
# print(rgbFrame.shape)
# print(rgbFrame.shape)
bobQFeats = iqm.compute_quality_features(rgbFrame)
msuQFeats = iqa.compute_msu_iqa_features(rgbFrame)
bobfset[f] = bobQFeats
......@@ -56,6 +52,8 @@ def computeIQM_1video(vidPath):
feature-family. Each array contains one feature-vector per frame
"""
# 1. load video from input path
import bob.io.video
inputVideo = bob.io.video.reader(vidPath)
vin = inputVideo.load()
# 2. compute and return feature-sets
......@@ -67,29 +65,31 @@ def main(command_line_parameters=None):
feature-arrays in specified output hdf5 file"""
argParser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
argParser.add_argument(
'-i',
'--input_videofile',
dest='inpVidFile',
"-i",
"--input_videofile",
dest="inpVidFile",
default=None,
help='filename of video to be processed (including complete path). ')
help="filename of video to be processed (including complete path). ",
)
argParser.add_argument(
'-o',
'--output_featurefile',
dest='outFile',
"-o",
"--output_featurefile",
dest="outFile",
default=None,
help='filename where computed features will be stored. Output file '
'will be in hdf5 format.')
help="filename where computed features will be stored. Output file "
"will be in hdf5 format.",
)
args = argParser.parse_args(command_line_parameters)
# make sure the user specifies a folder where feature-files exist
if not args.inpVidFile:
argParser.error('Specify parameter --input_videofile')
argParser.error("Specify parameter --input_videofile")
if not args.outFile:
argParser.error('Specify parameter --output_featurefile')
argParser.error("Specify parameter --output_featurefile")
# 1. compute features, 1 vector per frame of input video, per
# feature-family (galbally,msu).
......@@ -98,12 +98,16 @@ def main(command_line_parameters=None):
# 2. save features in file
outfile = args.outFile
print("Saving features in output file: %s" % outfile)
ohf = bob.io.base.HDF5File(outfile, 'w')
ohf.set('bobiqm', bobIqmFeats)
ohf.set('msuiqa', msuIqaFeats)
import bob.io.base
ohf = bob.io.base.HDF5File(outfile, "w")
ohf.set("bobiqm", bobIqmFeats)
ohf.set("msuiqa", msuIqaFeats)
del ohf
print('Done')
print("Done")
if __name__ == "__main__":
import sys
if __name__ == '__main__':
main(sys.argv[1:])
......@@ -2,15 +2,8 @@
# vim: set fileencoding=utf-8 :
import sys
import argparse
import time
import bob.io.base
import bob.io.image
import numpy as np
from bob.ip.qualitymeasure import remove_highlights
def main(command_line_parameters=None):
"""Remove the specular component of the input image and write result to
......@@ -18,42 +11,50 @@ def main(command_line_parameters=None):
"""
argParser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
argParser.add_argument(
'-i',
'--input',
dest='inpImg',
"-i",
"--input",
dest="inpImg",
default=None,
help='filename of image to be processed (including complete path). ')
help="filename of image to be processed (including complete path). ",
)
argParser.add_argument(
'-o',
'--output',
dest='outImg',
"-o",
"--output",
dest="outImg",
default=None,
help='filename of specular free image.')
help="filename of specular free image.",
)
argParser.add_argument(
'-r',
'--residue',
dest='resImg',
"-r",
"--residue",
dest="resImg",
default=None,
help='filename of specular residue image.')
help="filename of specular residue image.",
)
argParser.add_argument(
'-e',
'--epsilon',
dest='epsilon',
"-e",
"--epsilon",
dest="epsilon",
default=0.5,
help='value of epsilon parameter.')
help="value of epsilon parameter.",
)
args = argParser.parse_args(command_line_parameters)
if not args.inpImg:
argParser.error('Specify parameter --input')
argParser.error("Specify parameter --input")
if not args.outImg:
argParser.error('Specify parameter --output')
argParser.error("Specify parameter --output")
import bob.io.image
import numpy as np
from bob.ip.qualitymeasure import remove_highlights
# 1. open input image
print("Opening file: %s" % args.inpImg)
......@@ -66,14 +67,16 @@ def main(command_line_parameters=None):
# 1. save output image
print("Saving output file: %s" % args.outImg)
bob.io.base.save(diff.astype('uint8'), args.outImg)
bob.io.base.save(diff.astype("uint8"), args.outImg)
if args.resImg:
print("Saving residue file: %s" % args.resImg)
bob.io.base.save(residue.astype('uint8'), args.resImg)
bob.io.base.save(residue.astype("uint8"), args.resImg)
print("Done")
print('Done')
if __name__ == "__main__":
import sys
if __name__ == '__main__':
main(sys.argv[1:])
......@@ -30,9 +30,6 @@ requirements:
- setuptools {{ setuptools }}
- bob.extension
- bob.blitz
- bob.io.base
- bob.io.image
- bob.io.video
- bob.ip.base
- bob.ip.draw
- bob.ip.color
......@@ -60,6 +57,9 @@ test:
- coverage
- sphinx
- sphinx_rtd_theme
- bob.io.base
- bob.io.image
- bob.io.video
about:
home: https://www.idiap.ch/software/bob/
......
......@@ -7,7 +7,6 @@
import os, sys
import argparse
import bob.io.image #remove this if possible
import bob.io.base
import bob.io.video
import bob.ip.color
......@@ -33,7 +32,7 @@ Two sets of quality-features are implemented in this package:
2. The image-quality features proposed by Wen et al. (IEEE TIFS 2015).
The package includes separate modules for implementing the two feature-sets.
The module ``galbally_iqm_features`` implements the features proposed by Gabally et al., and the module ``msu_iqa_features`` implements the features proposed by Wen et al.
The module ``galbally_iqm_features`` implements the features proposed by Gabally et al., and the module ``msu_iqa_features`` implements the features proposed by Wen et al.
In each module, a single function needs to be called, to retrieve all the features implemented in the module.
The examples below show how to use the functions in the two modules.
......@@ -45,9 +44,9 @@ Note also, that in the examples below, the input to the feature-extraction funct
Computing Galbally's image-quality measures
-------------------------------------------
The function ``compute_quality_features()`` (in the module galbally_iqm_features) can be used to compute 18 image-quality measures
The function ``compute_quality_features()`` (in the module galbally_iqm_features) can be used to compute 18 image-quality measures
proposed by Galbally et al. Note that Galbally et al. proposed 25 features in their paper. This package implements the following
18 features from their paper, namely:
18 features from their paper, namely:
[mse, psnr, ad, sc, nk, md, lmse, nae, snrv, ramdv, mas, mams, sme, gme, gpe, ssim, vif, hlfi].
The function ``galbally_iqm_features::compute_quality_features()`` returns a 1D numpy array of length 18, containing the feature-values in the order listed above.
......@@ -71,7 +70,7 @@ or a gray-level image.
When the input image is 3-dimensional, the first dimension being '3' (as is the case in the example above), the input
is assumed to represent a color RGB image, and is first converted to a gray-level image.
If the input is 2-dimensional (say, a numpy array of shape [480, 720]), then it is assumed to represent a gray-level
image, and the RGB-to-gray conversion step is skipped.
image, and the RGB-to-gray conversion step is skipped.
Computing Wen's (MSU) image-quality measures
......@@ -92,5 +91,5 @@ The function ``compute_msu_iqa_features()`` (from the module ``msu_iqa_features`
121
.. _Bob: https://www.idiap.ch/software/bob/
.. _Bob: https://www.idiap.ch/software/bob/
.. _documentation: https://menpofit.readthedocs.io/en/stable/
Markdown is supported
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