History

avfilter/vf_chromanr: improve filtering results

Paul B Mahol committed 5 years ago

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

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_chromanr.c+18−14
@@ -72,7 +72,8 @@ static const enum AVPixelFormat pix_fmts[] = { · 71 unmodified lines
7272 AV_PIX_FMT_NONE
7373 };
7474
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)))
7677
7778 #define FILTER_FUNC(distance, name, ctype, type, fun) \
7879 static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \
@@ -136,19 +137,22 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 57 unmodified lines
136137 int sv = cv; \
137138 int cn = 1; \
138139 \
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) { \
140141 const type *in_yptr = (const type *)(in->data[0] + yy * chroma_h * in_ylinesize); \
141142 const type *in_uptr = (const type *)(in->data[1] + yy * in_ulinesize); \
142143 const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \
143144 \
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) { \
145146 const ctype Y = in_yptr[xx * chroma_w]; \
146147 const ctype U = in_uptr[xx]; \
147148 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); \
148152 \
149− if (fun(cu - U) + fun(cv - V) + fun(cy - Y) < thres && \
150− fun(cu - U) < thres_u && fun(cv - V) < thres_v && \
151− fun(cy - Y) < thres_y && \
153+ if (fun(cyY, cuU, cvV) < thres && \
154+ cuU < thres_u && cvV < thres_v && \
155+ cyY < thres_y && \
152156 xx != x && yy != y) { \
153157 su += U; \
154158 sv += V; \
@@ -168,11 +172,11 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 13 unmodified lines
168172 return 0; \
169173 }
170174
171−FILTER_FUNC(manhattan, 8, int, uint8_t, FFABS)
172−FILTER_FUNC(manhattan, 16, int, uint16_t, FFABS)
175+FILTER_FUNC(manhattan, 8, int, uint8_t, MANHATTAN_DISTANCE)
176+FILTER_FUNC(manhattan, 16, int, uint16_t, MANHATTAN_DISTANCE)
173177
174−FILTER_FUNC(euclidean, 8, int, uint8_t, SQR)
175−FILTER_FUNC(euclidean, 16, int64_t, uint16_t, SQR)
178+FILTER_FUNC(euclidean, 8, int, uint8_t, EUCLIDEAN_DISTANCE)
179+FILTER_FUNC(euclidean, 16, int64_t, uint16_t, EUCLIDEAN_DISTANCE)
176180
177181 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
178182 {
@@ -238,14 +242,14 @@ static int config_input(AVFilterLink *inlink) · 59 unmodified lines
238242 #define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
239243
240244 static 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 },
242246 { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },
243247 { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF },
244248 { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF },
245249 { "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 },
247− { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF },
248− { "threv", "set v threshold", OFFSET(threshold_v), 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 },
251+ { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF },
252+ { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF },
249253 { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" },
250254 { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" },
251255 { "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