Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th October 2021, 07:13   #1  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Is there a filter for autolevels?

I have a grayscale clip that only has visible area between brightness of 50-100, so I'm looking for a filter that can do autolevels to make the image more visible. Is there any?
lansing is offline   Reply With Quote
Old 18th October 2021, 15:27   #2  |  Link
Julek
Registered User
 
Julek's Avatar
 
Join Date: Dec 2020
Posts: 88
Is this for mask? You can try retinex.
Julek is offline   Reply With Quote
Old 18th October 2021, 15:54   #3  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by Julek View Post
Is this for mask? You can try retinex.
This is for previewing UV plane in vseditor2. I just need to map the levels to a wider range so they're more visible. Retinex is too much for the job.
lansing is offline   Reply With Quote
Old 18th October 2021, 16:36   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,377
if you know the min/max levels (maybe using planestats ?) - can't you just plug those into values into levels filter programmatically ?
poisondeathray is offline   Reply With Quote
Old 18th October 2021, 16:49   #5  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by poisondeathray View Post
if you know the min/max levels (maybe using planestats ?) - can't you just plug those into values into levels filter programmatically ?
Yes that is what's I was thinking, but I just don't know how to get the max and min value of the levels. I'll try Planestats now.
lansing is offline   Reply With Quote
Old 18th October 2021, 16:52   #6  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,377
You might have to blur or process image with something - because of "stray" pixels (maybe less of an issue for U, V planes than Y) - but the absolute min/max will probably give you not ideal results

(Another less favorable option would be loading an avs plugin...)
poisondeathray is offline   Reply With Quote
Old 18th October 2021, 17:04   #7  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,555
Quote:
Originally Posted by poisondeathray View Post
You might have to blur or process image with something - because of "stray" pixels (maybe less of an issue for U, V planes than Y) - but the absolute min/max will probably give you not ideal results

(Another less favorable option would be loading an avs plugin...)
"Stray pixels" => median filter it like crazy before getting max and min
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 18th October 2021, 19:51   #8  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
I run into a problem with the invoking sequence. The normal order for invoking multiple filters would be like:

Code:
output_node -> invoke_function1 -> invoke_function2 -> get_frame -> display
But for this, I'll need to get the frame twice:
Code:
output_node -> invoke_PlaneStats -> get_frame -> get_frame_prop -> invoke_Levels -> get_frame -> display
Can this be simplified?
lansing is offline   Reply With Quote
Old 19th October 2021, 03:29   #9  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 162
with builtins
Code:
def f(n, f, clip=src):
    min_in = f.props["PlaneStatsMin"]
    max_in = f.props["PlaneStatsMax"]
    return clip.std.Levels(min_in, max_in, min_out=0, max_out=255, planes=[0])

stats = core.std.PlaneStats(src, plane=0)
flt = core.std.FrameEval(src, f, stats)
with Akarin's Expr
Code:
stats = core.std.PlaneStats(src, plane=0)
expr = "x {min_in} - {max_in} {min_in} - / {max_out} {min_out} - * {min_out} +".format(min_in="x.PlaneStatsMin", max_in="x.PlaneStatsMax", min_out=0, max_out=255)
flt = core.akarin.Expr(stats, [expr, ""])
WolframRhodium is offline   Reply With Quote
Old 19th October 2021, 08:21   #10  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by WolframRhodium View Post
with builtins
Code:
def f(n, f, clip=src):
    min_in = f.props["PlaneStatsMin"]
    max_in = f.props["PlaneStatsMax"]
    return clip.std.Levels(min_in, max_in, min_out=0, max_out=255, planes=[0])

stats = core.std.PlaneStats(src, plane=0)
flt = core.std.FrameEval(src, f, stats)
with Akarin's Expr
Code:
stats = core.std.PlaneStats(src, plane=0)
expr = "x {min_in} - {max_in} {min_in} - / {max_out} {min_out} - * {min_out} +".format(min_in="x.PlaneStatsMin", max_in="x.PlaneStatsMax", min_out=0, max_out=255)
flt = core.akarin.Expr(stats, [expr, ""])
I don't know how to turn the first one into c++. Like how do I set a function as argument?

Code:
VSPlugin * pStdPlugin = m_cpVSAPI->getPluginByID("com.vapoursynth.std", m_pCore);

m_cpVSAPI->mapConsumeNode(pArgumentMap, "clip", a_pVideoNode, maReplace);
m_cpVSAPI->mapSetFunction(pArgumentMap, "eval", "???", maReplace);

VSMap * pResultMap = m_cpVSAPI->invoke(pStdPlugin, "FrameEval", pArgumentMap);
For the second one, how do I convert the entire expr line into a string?
lansing is offline   Reply With Quote
Old 19th October 2021, 11:04   #11  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 162
For the second one,
Code:
#include <sstream>

auto min_in = "x.PlaneStatsMin";
auto max_in = "x.PlaneStatsMax";
auto min_out = 0;
auto max_out = 255;

std::ostringstream expr_stream {};
expr_stream << "x " << min_in << " - " << max_in << " " << min_in << " - / " << max_out - min_out << " * " << min_out << " +";
auto expr = expr_stream.str();

vsapi->mapSetData(args, "expr", expr, std::size(expr), dtBinary, maReplace); // Y plane
vsapi->mapSetData(args, "expr", "", 0, dtBinary, maAppend); // U plane
vsapi->mapSetData(args, "expr", "", 0, dtBinary, maAppend); // V plane
WolframRhodium is offline   Reply With Quote
Old 20th October 2021, 18:55   #12  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by WolframRhodium View Post
For the second one,
Thanks it works. I modified the string a little because the vsapi function was looking for "const * char" instead of string.

Code:
std::ostringstream expr_stream {};
expr_stream << "x " << min_in << " - " << max_in << " " << min_in << " - / " << max_out - min_out << " * " << min_out << " +";
auto expr = _strdup(expr_stream.str().c_str());

vsapi->mapSetData(args, "expr", expr, strlen(expr), dtBinary, maReplace); // Y plane

Last edited by lansing; 20th October 2021 at 18:58.
lansing is offline   Reply With Quote
Reply

Tags
autolevels


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:26.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.