History

avfilter/vf_chromanr: improve filtering results

Paul B Mahol committed 5 years ago

Commit bf995041 parent 2171f972 files · +22 −18Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −4
  2. libavfilter/vf_chromanr.c +18 −14
doc/filters.texi+4−4
@@ -8048,7 +8048,7 @@ Set threshold for averaging chrominance values. · 8047 unmodified lines
8048Sum of absolute difference of Y, U and V pixel components of current8048Sum of absolute difference of Y, U and V pixel components of current
8049pixel and neighbour pixels lower than this threshold will be used in8049pixel and neighbour pixels lower than this threshold will be used in
8050averaging. Luma component is left unchanged and is copied to output.8050averaging. Luma component is left unchanged and is copied to output.
8051Default value is 30. Allowed range is from 1 to 5000.8051Default value is 30. Allowed range is from 1 to 200.
8052 8052
8053@item sizew8053@item sizew
8054Set horizontal radius of rectangle used for averaging.8054Set horizontal radius of rectangle used for averaging.
@@ -8072,19 +8072,19 @@ Mostly useful to speed-up filtering. · 17 unmodified lines
8072Set Y threshold for averaging chrominance values.8072Set Y threshold for averaging chrominance values.
8073Set finer control for max allowed difference between Y components8073Set finer control for max allowed difference between Y components
8074of current pixel and neigbour pixels.8074of current pixel and neigbour pixels.
8075Default value is 5000. Allowed range is from 1 to 5000.8075Default value is 200. Allowed range is from 1 to 200.
8076 8076
8077@item threu8077@item threu
8078Set U threshold for averaging chrominance values.8078Set U threshold for averaging chrominance values.
8079Set finer control for max allowed difference between U components8079Set finer control for max allowed difference between U components
8080of current pixel and neigbour pixels.8080of current pixel and neigbour pixels.
8081Default value is 5000. Allowed range is from 1 to 5000.8081Default value is 200. Allowed range is from 1 to 200.
8082 8082
8083@item threv8083@item threv
8084Set V threshold for averaging chrominance values.8084Set V threshold for averaging chrominance values.
8085Set finer control for max allowed difference between V components8085Set finer control for max allowed difference between V components
8086of current pixel and neigbour pixels.8086of current pixel and neigbour pixels.
8087Default value is 5000. Allowed range is from 1 to 5000.8087Default value is 200. Allowed range is from 1 to 200.
8088 8088
8089@item distance8089@item distance
8090Set distance type used in calculations.8090Set distance type used in calculations.
libavfilter/vf_chromanr.c+18−14
@@ -72,7 +72,8 @@ static const enum AVPixelFormat pix_fmts[] = { · 71 unmodified lines
72 AV_PIX_FMT_NONE72 AV_PIX_FMT_NONE
73};73};
74 74
75#define SQR(x) ((x)*(x))75#define MANHATTAN_DISTANCE(x, y, z) ((x) + (y) + (z))
76#define EUCLIDEAN_DISTANCE(x, y, z) (sqrtf((x)*(x) + (y)*(y) + (z)*(z)))
76 77
77#define FILTER_FUNC(distance, name, ctype, type, fun) \78#define FILTER_FUNC(distance, name, ctype, type, fun) \
78static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \79static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \
@@ -136,19 +137,22 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 57 unmodified lines
136 int sv = cv; \137 int sv = cv; \
137 int cn = 1; \138 int cn = 1; \
138 \139 \
139 for (int yy = FFMAX(0, y - sizeh); yy < FFMIN(y + sizeh, h); yy += steph) { \140 for (int yy = FFMAX(0, y - sizeh); yy <= FFMIN(y + sizeh, h - 1); yy += steph) { \
140 const type *in_yptr = (const type *)(in->data[0] + yy * chroma_h * in_ylinesize); \141 const type *in_yptr = (const type *)(in->data[0] + yy * chroma_h * in_ylinesize); \
141 const type *in_uptr = (const type *)(in->data[1] + yy * in_ulinesize); \142 const type *in_uptr = (const type *)(in->data[1] + yy * in_ulinesize); \
142 const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \143 const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \
143 \144 \
144 for (int xx = FFMAX(0, x - sizew); xx < FFMIN(x + sizew, w); xx += stepw) { \145 for (int xx = FFMAX(0, x - sizew); xx <= FFMIN(x + sizew, w - 1); xx += stepw) { \
145 const ctype Y = in_yptr[xx * chroma_w]; \146 const ctype Y = in_yptr[xx * chroma_w]; \
146 const ctype U = in_uptr[xx]; \147 const ctype U = in_uptr[xx]; \
147 const ctype V = in_vptr[xx]; \148 const ctype V = in_vptr[xx]; \
149 const ctype cyY = FFABS(cy - Y); \
150 const ctype cuU = FFABS(cu - U); \
151 const ctype cvV = FFABS(cv - V); \
148 \152 \
149 if (fun(cu - U) + fun(cv - V) + fun(cy - Y) < thres && \153 if (fun(cyY, cuU, cvV) < thres && \
150 fun(cu - U) < thres_u && fun(cv - V) < thres_v && \154 cuU < thres_u && cvV < thres_v && \
151 fun(cy - Y) < thres_y && \155 cyY < thres_y && \
152 xx != x && yy != y) { \156 xx != x && yy != y) { \
153 su += U; \157 su += U; \
154 sv += V; \158 sv += V; \
@@ -168,11 +172,11 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 13 unmodified lines
168 return 0; \172 return 0; \
169}173}
170 174
171FILTER_FUNC(manhattan, 8, int, uint8_t, FFABS)175FILTER_FUNC(manhattan, 8, int, uint8_t, MANHATTAN_DISTANCE)
172FILTER_FUNC(manhattan, 16, int, uint16_t, FFABS)176FILTER_FUNC(manhattan, 16, int, uint16_t, MANHATTAN_DISTANCE)
173 177
174FILTER_FUNC(euclidean, 8, int, uint8_t, SQR)178FILTER_FUNC(euclidean, 8, int, uint8_t, EUCLIDEAN_DISTANCE)
175FILTER_FUNC(euclidean, 16, int64_t, uint16_t, SQR)179FILTER_FUNC(euclidean, 16, int64_t, uint16_t, EUCLIDEAN_DISTANCE)
176 180
177static int filter_frame(AVFilterLink *inlink, AVFrame *in)181static int filter_frame(AVFilterLink *inlink, AVFrame *in)
178{182{
@@ -238,14 +242,14 @@ static int config_input(AVFilterLink *inlink) · 59 unmodified lines
238#define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM242#define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
239 243
240static const AVOption chromanr_options[] = {244static const AVOption chromanr_options[] = {
241 { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 5000, VF },245 { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 200, VF },
242 { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },246 { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },
243 { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },247 { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },
244 { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF },248 { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF },
245 { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF },249 { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF },
246 { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF },250 { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF },
247 { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF },251 { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF },
248 { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF },252 { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF },
249 { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" },253 { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" },
250 { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" },254 { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" },
251 { "euclidean", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VF, "distance" },255 { "euclidean", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VF, "distance" },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t