Skip to content

Commit

Permalink
Float funque plus (#10)
Browse files Browse the repository at this point in the history
* Added funque plus float code
* Added strred files
* Renamed filters
* Fix syntax errors
* Added name of filters
* Fixes for width and height that caused memory allocation error in fex
* Fixes to match level 3 scores
* Added fixes for memory leaks
* Remove unwanted code
* Fixed warnings
* Revert adm feature
  • Loading branch information
MallikarjunKamble authored Feb 1, 2024
1 parent 7a98684 commit e1c9754
Show file tree
Hide file tree
Showing 17 changed files with 1,324 additions and 109 deletions.
562 changes: 512 additions & 50 deletions libvmaf/src/feature/third_party/funque/float_funque.c

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@

#define DEFAULT_ADM_LEVELS 4
#define MAX_ADM_LEVELS 4
#define MIN_ADM_LEVELS 1
#define MIN_ADM_LEVELS 0

#endif /* ADM_OPTIONS_H_ */
78 changes: 53 additions & 25 deletions libvmaf/src/feature/third_party/funque/funque_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ void funque_vifdwt2_band0(float *src, float *band_a, ptrdiff_t dst_stride, int w
aligned_free(tmplo);
}

//Convolution using coefficients from python workspace
void spatial_filter(float *src, float *dst, int width, int height)
{
//Copied the coefficients from python coefficients
float filter_coeffs[21] = {
const float nadeanu_filter_coeffs[5] = {0.0253133196, 0.2310067710, 0.4759767950, 0.2310067710,
0.0253133196 };

const float ngan_filter_coeffs[21] = {
-0.01373463642215844680849 ,
-0.01608514932055564797264 ,
-0.01890698454168517061991 ,
Expand All @@ -132,58 +131,63 @@ void spatial_filter(float *src, float *dst, int width, int height)
-0.02215701978091480159327 ,
-0.01890698454168517061991 ,
-0.01608514932055564797264 ,
-0.01373463642215844680849
};
-0.01373463642215844680849 };

void spatial_csfs(float *src, float *dst, int width, int height, float *tmp_buf, char *spatial_csf_filter)
{
const float *filter_coeffs;
int filter_size;
if(strcmp(spatial_csf_filter, "nadenau_spat") == 0) {
/*coefficients for 5 tap nadeanu_spat filter */
filter_coeffs = nadeanu_filter_coeffs;
filter_size = 5;
} else if (strcmp(spatial_csf_filter, "ngan_spat") == 0) {
filter_coeffs = ngan_filter_coeffs;
filter_size = 21;
}
int src_px_stride = width;
int dst_px_stride = width;

float *tmp = aligned_malloc(ALIGN_CEIL(src_px_stride * sizeof(float)), MAX_ALIGN);
float fcoeff, imgcoeff;

int i, j, fi, fj, ii, jj;
int fwidth = 21;
for (i = 0; i < height; ++i) {

for(i = 0; i < height; ++i) {
/* Vertical pass. */
for (j = 0; j < width; ++j) {
for(j = 0; j < width; ++j) {
double accum = 0;

for (fi = 0; fi < fwidth; ++fi) {
for(fi = 0; fi < filter_size; ++fi) {
fcoeff = filter_coeffs[fi];
ii = i - fwidth / 2 + fi;
ii = ii < 0 ? -(ii+1) : (ii >= height ? 2 * height - ii - 1 : ii);

ii = i - filter_size / 2 + fi;
ii = ii < 0 ? -(ii + 1) : (ii >= height ? 2 * height - ii - 1 : ii);

imgcoeff = src[ii * src_px_stride + j];

accum += (double) fcoeff * imgcoeff;
}

tmp[j] = accum;
tmp_buf[j] = accum;
}

/* Horizontal pass. */
for (j = 0; j < width; ++j) {
for(j = 0; j < width; ++j) {
double accum = 0;

for (fj = 0; fj < fwidth; ++fj) {
for(fj = 0; fj < filter_size; ++fj) {
fcoeff = filter_coeffs[fj];

jj = j - fwidth / 2 + fj;
jj = jj < 0 ? -(jj+1) : (jj >= width ? 2 * width - jj - 1 : jj);
jj = j - filter_size / 2 + fj;
jj = jj < 0 ? -(jj + 1) : (jj >= width ? 2 * width - jj - 1 : jj);

imgcoeff = tmp[jj];
imgcoeff = tmp_buf[jj];

accum += (double) fcoeff * imgcoeff;
}

dst[i * dst_px_stride + j] = accum;
}
}

aligned_free(tmp);

return;
}

Expand All @@ -199,6 +203,30 @@ void normalize_bitdepth(float *src, float *dst, int scaler, ptrdiff_t dst_stride
return;
}

void reflect_pad_for_input(const float *src, float *dst, int width, int height, int reflect_width, int reflect_height)
{
size_t out_width = width + 2 * reflect_width;
size_t out_height = height + 2 * reflect_height;

for (size_t i = reflect_height; i != (out_height - reflect_height); i++) {

for (int j = 0; j != reflect_width; j++)
{
dst[i * out_width + (reflect_width - 1 - j)] = src[(i - reflect_height) * width + j + 1];
}

memcpy(&dst[i * out_width + reflect_width], &src[(i - reflect_height) * width], sizeof(float) * width);

for (int j = 0; j != reflect_width; j++)
dst[i * out_width + out_width - reflect_width + j] = dst[i * out_width + out_width - reflect_width - 2 - j];
}

for (int i = 0; i != reflect_height; i++) {
memcpy(&dst[(reflect_height - 1) * out_width - i * out_width], &dst[reflect_height * out_width + (i + 1) * out_width], sizeof(float) * out_width);
memcpy(&dst[(out_height - reflect_height) * out_width + i * out_width], &dst[(out_height - reflect_height - 1) * out_width - (i + 1) * out_width], sizeof(float) * out_width);
}
}

void funque_dwt2_inplace_csf(const dwt2buffers *src, float factors[4], int min_theta, int max_theta)
{
float *src_ptr;
Expand Down
57 changes: 56 additions & 1 deletion libvmaf/src/feature/third_party/funque/funque_filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
#include <math.h>
#include "macros.h"

// Spatial Filters
#define NGAN_21_TAP_FILTER 21
#define NADENAU_SPAT_5_TAP_FILTER 5

// Wavelet Filters
#define NADENAU_WEIGHT_FILTER 1 // Default set to nadenau_weight
#define LI_FILTER 2
#define HILL_FILTER 3
#define WATSON_FILTER 4
#define MANNOS_WEIGHT_FILTER 5

struct funque_dwt_model_params {
float a;
float k;
Expand Down Expand Up @@ -72,7 +83,49 @@ typedef struct dwt2buffers {
ptrdiff_t stride;
}dwt2buffers;

void spatial_filter(float *src, float *dst, int width, int height);
/* filter format where 0 = approx, 1 = vertical, 2 = diagonal, 3 = horizontal as in
* funque_dwt2_inplace_csf */
static const float nadenau_weight_coeffs[4][4] = {
{1, 0.04299846, 0.00556257, 0.04299846},
{1, 0.42474743, 0.18536903, 0.42474743},
{1, 0.79592083, 0.63707782, 0.79592083},
{1, 0.94104990, 0.88686180, 0.94104990},
/*{ 1, 0.98396102, 0.96855064, 0.98396102},*/
};

static const float li_coeffs[4][4] = {
{1, 0.00544585178, 0.00023055401, 0.00544585178},
{1, 0.16683506215, 0.04074566701, 0.16683506215},
{1, 0.66786346496, 0.38921962529, 0.66786346496},
{1, 0.98626459244, 0.87735995465, 0.98626459244},
/*{ 1, 0.91608864363, 0.91608864363, 0.98675189575},*/
};

static const float hill_coeffs[4][4] = {
{1, 0.08655904, 0.03830355, 0.08655904},
{1, -0.33820268, 0.10885236, -0.33820268},
{1, -0.06836095, -0.20426743, -0.06836095},
{1, -0.04262307, -0.0619592, -0.04262307},
/*{ -0.03159788, -0.03394834, -0.03394834, -0.04074054},*/
};

static const float watson_coeffs[4][4] = {
{1, 0.01738153, 0.00589069, 0.01738153},
{1, 0.03198481, 0.01429907, 0.03198481},
{1, 0.04337266, 0.02439691, 0.04337266},
{1, 0.04567341, 0.03131274, 0.04567341},
/*{ 0.03669688, 0.03867382, 0.03867382, 0.03187392},*/
};

static const float mannos_weight_coeffs[4][4] = {
{1, 7.11828321e-03, 2.43358422e-04, 7.11828321e-03},
{1, 2.25003123e-01, 5.62679733e-02, 2.25003123e-01},
{1, 7.82068784e-01, 4.94193706e-01, 7.82068784e-01},
{1, 9.81000000e-01, 9.81000000e-01, 9.81000000e-01},
/*{ 9.81000000e-01, 9.81000000e-01, 9.81000000e-01, 9.81000000e-01},*/
};

void spatial_csfs(float *src, float *dst, int width, int height, float *tmp_buf, char *spatial_csf_filter);

void funque_dwt2(float *src, dwt2buffers *dwt2_dst, int width, int height);

Expand All @@ -82,4 +135,6 @@ void normalize_bitdepth(float *src, float *dst, int scaler, ptrdiff_t dst_stride

void funque_dwt2_inplace_csf(const dwt2buffers *src, float factors[4], int min_theta, int max_theta);

void reflect_pad_for_input(const float *src, float *dst, int width, int height, int reflect_width, int reflect_height);

#endif /* FILTERS_FUNQUE_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define DEFAULT_REF_DISPLAY_HEIGHT (1080)

#define MAX_LEVELS 4
#define MIN_LEVELS 1
#define MIN_LEVELS 0


#endif //VMAF_FUNQUE_GLOBAL_OPTIONS_H
14 changes: 7 additions & 7 deletions libvmaf/src/feature/third_party/funque/funque_picture_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#include "funque_filters.h"

void funque_picture_copy_hbd(float *dst, ptrdiff_t dst_stride,
VmafPicture *src, int offset)
VmafPicture *src, int offset, int width, int height)
{
float *float_data = dst;
uint16_t *data = src->data[0];

for (unsigned i = 0; i < src->h[0]; i++) {
for (unsigned j = 0; j < src->w[0]; j++) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
float_data[j] = (float) data[j] + offset;
}
float_data += dst_stride / sizeof(float);
Expand All @@ -39,16 +39,16 @@ void funque_picture_copy_hbd(float *dst, ptrdiff_t dst_stride,
}

void funque_picture_copy(float *dst, ptrdiff_t dst_stride,
VmafPicture *src, int offset, unsigned bpc)
VmafPicture *src, int offset, unsigned bpc, int width, int height)
{
if (bpc > 8)
return funque_picture_copy_hbd(dst, dst_stride, src, offset);
return funque_picture_copy_hbd(dst, dst_stride, src, offset, width, height);

float *float_data = dst;
uint8_t *data = src->data[0];

for (unsigned i = 0; i < src->h[0]; i++) {
for (unsigned j = 0; j < src->w[0]; j++) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
float_data[j] = (float) data[j] + offset;
}
float_data += dst_stride / sizeof(float);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
#include <stddef.h>

void funque_picture_copy(float *dst, ptrdiff_t dst_stride, VmafPicture *src,
int offset, unsigned bpc);
int offset, unsigned bpc, int width, int height);
Loading

0 comments on commit e1c9754

Please sign in to comment.