Skip to content

Commit

Permalink
Added source files
Browse files Browse the repository at this point in the history
  • Loading branch information
kahkeng committed Jun 14, 2010
1 parent 9190960 commit 2523153
Show file tree
Hide file tree
Showing 19 changed files with 2,623 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2008 Kah Keng Tay. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
OPTIONS_SAMPLING=-D SAMPLING_SIZE=100 -D SAMPLING_WIN_X=11 -D SAMPLING_WIN_Y=11 -D SAMPLING_LUMINANCE_WEIGHTING
OPTIONS_FIB=-D FH_STATS
OPTIONS_A=-D CACHE_SIZE=100 $(OPTIONS_SAMPLING) $(OPTIONS_FIB)
OPTIONS_B=-D CACHE_SIZE=20 $(OPTIONS_SAMPLING) $(OPTIONS_FIB)
OPTIONS_D=-D CACHE_SIZE=100 $(OPTIONS_SAMPLING)
OPTIONS_DR=-D CACHE_SIZE=100 $(OPTIONS_SAMPLING)
OPTIONS_L=-D CACHE_SIZE=100 $(OPTIONS_SAMPLING)

all: pkg vqatsA vqatsB vqatsD vqatsDR vqatsL fib

pkg:
@PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
@export PKG_CONFIG_PATH

fib:
@gcc -Wall $(OPTIONS_FIB) -I. -c fib.c -o fib.o

vqats%: fib
@$(MAKE) -s _$@ ID=$(subst vqats,,$@)

_vqats%:
gcc -Wall $(OPTIONS_$(ID)) vqats.cc algo$(ID).cc tool.cc fib.o `pkg-config --cflags opencv` `pkg-config --libs opencv` -o vqats$(ID)x
gcc -Wall -g -D DEBUG $(OPTIONS_$(ID)) vqats.cc algo$(ID).cc tool.cc fib.o `pkg-config --cflags opencv` `pkg-config --libs opencv` -o vqats$(ID)d
47 changes: 47 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Video Quality Assessment Tool using SSIM (VQATS).
Written by Kah Keng Tay, kahkeng AT gmail DOT com, 2008.

This tool computes VSSIM*, a similarity score between two videos, when given
their image sequences as input. When comparing any two frames, we average the
RGB SSIM values and use that as the overall video SSIM index for the frames.

Features:
- accomodates frame skips and stalls in input videos.
- performs such alignment automatically and quickly.
- minimize computation to keep things fast.

Credit goes to:
- Zhou Wang for the SSIM metric. http://www.ece.uwaterloo.ca/~z70wang/research/ssim/
- Rabah Mehdi for original SSIM OpenCV code. http://mehdi.rabah.free.fr/
- John-Mark Gurney for fib package. http://resnet.uoregon.edu/~gurney_j/jmpc/fib.html


Setup:

1. Install some pre-requisites (if using Fedora Core):
yum install pkgconfig libpng zlib libjpeg libtiff libjasper

2. Download and install OpenCV. Reference: http://opencvlibrary.sourceforge.net/InstallGuide_Linux
wget http://downloads.sourceforge.net/opencvlibrary/opencv-1.0.0.tar.gz
tar xzvf opencv-1.0.0.tar.gz
cd opencv-1.0.0
PKG_CONFIG=/usr/bin/pkg-config PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ ./configure --without-ffmpeg --enable-static
make
make install
ldconfig -v

3. Download and install FFmpeg.
svn checkout -r 10489 svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-pp
make
make install

4. Build VQATS.
make

5. Update eval.py with paths to ffmpeg and the VQATS executable.

6. Compute VSSIM* using eval.py.
eval.py <refvideo> <testvideo>

174 changes: 174 additions & 0 deletions algoA.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Video Quality Assessment Tool using SSIM (VQATS).
* Written by Kah Keng Tay, kahkeng AT gmail DOT com, 2008.
*
* A* algorithm.
*/

#include "vqats.hh"
#include "dtable.hh"
#include "fib.h"

enum state_t
{
NONE = 0,
OPEN,
CLOSED
};

struct QueueElement
{
QueueElement(frame_t i1, frame_t i2): _i1(i1), _i2(i2), _estimate(0), _sum(0), _length(0) { }
frame_t _i1, _i2;
score_t _estimate; // estimated score
score_t _sum; // cumulative score
uint16_t _length; // path length
};

static inline int element_comparator(void* x, void* y)
{
QueueElement* a = (QueueElement*)x;
QueueElement* b = (QueueElement*)y;
if (a->_estimate < b->_estimate) return -1;
else if (a->_estimate > b->_estimate) return 1;
else return 0;
}

static inline score_t element_heuristic(frame_t i1, frame_t i2, frame_t j1, frame_t j2)
{
frame_t a1 = abs(i1 - j1);
frame_t a2 = abs(i2 - j2);
if (a1 > a2) return (a1 - a2) * (1.0 - DELETED_FRAME);
else return (a2 - a1) * (1.0 - INSERTED_FRAME);
}

score_t compute_video_score(VQATS& v, const video_t& video1, const video_t& video2)
{
frame_t n1 = v._video_map[video1]._frames.size();
frame_t n2 = v._video_map[video2]._frames.size();
void*** start_he = new_table<void*>(n1 + 1, n2 + 1, NULL); // heap elements
QueueElement*** start_qe = new_table<QueueElement*>(n1 + 1, n2 + 1, NULL); // queue elements
state_t** start_state = new_table<state_t>(n1 + 1, n2 + 1, NONE); // node states

// initial values
start_qe[0][0] = new QueueElement(0, 0);
start_state[0][0] = OPEN;

// initial queues
struct fibheap* start_heap = fh_makeheap();
fh_setcmp(start_heap, element_comparator);
start_he[0][0] = fh_insert(start_heap, (void*)start_qe[0][0]);

score_t sum = 0;
uint16_t length = 0;
int ninserts = 0;
#ifdef FH_STATS
printf("maxinserts = %d\n", (n1+1)*(n2+1)); fflush(stdout);
#endif

while (true)
{
QueueElement *qs, *qe;
int i1, i2;
score_t s;

// check start frontier
qs = (QueueElement*)fh_extractmin(start_heap);
assert(qs); // there is always a path
assert(start_state[qs->_i1][qs->_i2] == OPEN); // this node should be open
#ifdef DEBUG
printf("extract from start: (%d,%d) est=%.4f sum=%.4f len=%d\n", qs->_i1, qs->_i2, qs->_estimate, qs->_sum, qs->_length);
#endif
start_state[qs->_i1][qs->_i2] = CLOSED;
if (qs->_i1 == n1 && qs->_i2 == n2) // we have found an optimal path
{
sum = qs->_sum;
length = qs->_length;
break;
}
// expand this node outward
for (int dir = 0; dir < 3; dir++)
{
switch (dir)
{
case 0: i1 = qs->_i1 + 1; i2 = qs->_i2 + 1; break;
case 1: i1 = qs->_i1; i2 = qs->_i2 + 1; break; // insert frame
case 2: i1 = qs->_i1 + 1; i2 = qs->_i2; break; // delete frame
}
if (i1 <= n1 && i2 <= n2 && start_state[i1][i2] != CLOSED)
{
switch (dir)
{
case 0: s = 1.0 - v.compute_frame_score(video1, video2, i1 - 1, i2 - 1); break;
case 1: s = 1.0 - INSERTED_FRAME; break;
case 2: s = 1.0 - DELETED_FRAME; break;
}
qe = new QueueElement(i1, i2);
qe->_sum = qs->_sum + s;
qe->_length = qs->_length + 1;
qe->_estimate = qe->_sum + element_heuristic(i1, i2, n1, n2);
switch (start_state[i1][i2])
{
case NONE:
#ifdef DEBUG
printf("expanding start: (%d,%d) est=%.4f sum=%.4f len=%d\n", i1, i2, qe->_estimate, qe->_sum, qe->_length);
#endif
#ifdef FH_STATS
ninserts = fh_ninserts(start_heap);
if (ninserts % 10000 == 0) { printf("%d %d %d\n", ninserts, fh_nextracts(start_heap), fh_maxn(start_heap)); fflush(stdout); }
#endif
assert(start_qe[i1][i2] == NULL);
start_he[i1][i2] = fh_insert(start_heap, (void*)qe);
start_qe[i1][i2] = qe;
start_state[i1][i2] = OPEN;
break;
case OPEN:
#ifdef DEBUG
printf("updating start: (%d,%d) est=%.4f sum=%.4f len=%d\n", i1, i2, qe->_estimate, qe->_sum, qe->_length);
#endif
assert(start_qe[i1][i2] != NULL);
if (qe->_estimate < start_qe[i1][i2]->_estimate)
{
start_qe[i1][i2] = qe;
qe = (QueueElement*)fh_replacedata(start_heap, (struct fibheap_el*)start_he[i1][i2], (void*)qe);
}
delete qe;
break;
default:
assert(false); // should not reach here
break;
}
}
}
}
assert(length > 0);

#ifdef DEBUG
printf("Sum = %f\n", sum);
printf("Length = %d\n", length);
#endif
#ifdef FH_STATS
printf("MaxN = %d\n", fh_maxn(start_heap));
printf("Inserts = %d\n", fh_ninserts(start_heap));
printf("Extracts = %d\n", fh_nextracts(start_heap));
#endif
fflush(stdout);

// clean up
fh_deleteheap(start_heap);
for (uint16_t i1 = 0; i1 <= n1; i1++)
{
for (uint16_t i2 = 0; i2 <= n2; i2++)
{
if (start_qe[i1][i2])
delete start_qe[i1][i2];
}
}
delete_table(start_he, n1 + 1, n2 + 1);
delete_table(start_qe, n1 + 1, n2 + 1);
delete_table(start_state, n1 + 1, n2 + 1);

return 1.0 - sum / length;
}


Loading

0 comments on commit 2523153

Please sign in to comment.