Welcome Guest ( Log In | Register )


Important

The forums will be closing permanently the weekend of March 15th. Please see the notice in the announcements forum for details.

 
No Success With Irregular Red Color, Special filter needed but not found
« Next Oldest | Next Newest » Track this topic | Email this topic | Print this topic
maruli
  Posted: Apr 11 2014, 03:27 AM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



I am new to video editing, and I am new to this forum.
I have been capturing videos from a VCR and I have a problem with irregular lacking of the color red.
In some frames it is completely there, even too bright, in other frames it is partly insufficient and there are only some spots and lines in correct red while the rest is brown instead of red. The change between these frames is abrupt.
I checked a dozen filters but I could not find anything to solve this.
I need a filter, in which I can determine a threshold of the intensity, brightness or saturation of red, above which the red is not changed, while I can enhance the red below.
Is there any method to do this?
 
     Top
raffriff42
Posted: Apr 11 2014, 06:15 PM


Advanced Member


Group: Members
Posts: 384
Member No.: 35081
Joined: 25-June 12



1.
Make sure you are using the best available VCR and the heads are clean.
(because it sounds like your heads are clogging)
2.
Verify the capture process is working correctly with known good sources.
(because you might have a bad cable or something)
3.
Look around for "Virtualdub temporal chroma smoothing filters" and "VHS filters." You say you have done this, so I'll assume you tried everything. I searched a bit myself and did not find anything that looked like it would work for you.
4.
Finally, try Avisynth. If you aren't familiar with Avisynth, here's a quick start:
** download & install it.
** copy the code below into your text editor
** change "your video.avi" to the full path to your video
** save as plain text with .avs extension
** open .avs in Virtualdub with File, Open video file, just as if it was an AVI file
CODE
AviSource("your video.avi")
Subtitle("hello,\n maruli!", size=Height/4, align=5, lsp=0)
5.
Now that you have run a basic Avisynth script, try this more advanced one. It seems to work OK, except for two problems: there is a mis-registration when the previous frames' Red is used on rapidly moving video; and when there is a a Red dropout immediately followed by a scene change, there will be a frame with the Red coming from the previous scene.
CODE
AviSource("your video.avi")

## uncomment this line for dropout test clip!
#Red_Channel_Dropout_Generator(interval=4)

YUV=Last.ConvertToYV12
RGB=Last.ConvertToRGB24

R = RGB.ShowRed("YV12")
G = RGB.ShowGreen("YV12")
B = RGB.ShowBlue("YV12")

global RP = R.Trim(0,-1)+R ## red channel, previous frame
global RC = R              ## red channel, current frame

## replace the red channel with the one from the previous frame,
## if red seems to be missing ("< 10"; you can adjust this)
Rf = ConditionalSelect(R,
   \ """AverageLuma(Last) < 10 ? 0 : 1""",
   \  RP, RC)

fixedYUV=MergeRGB(Rf, G, B).ConvertToYV12

## uncomment this line for demonstration!
#return StackHorizontal(YUV, fixedYUV)

return  fixedYUV

##### red dropout test clip #####
function Red_Channel_Dropout_Generator(clip C, int "interval")
{
   global gint = Max(1, Default(interval, 4))

   global gRGB = C.ConvertToRGB24
   R = gRGB.ShowRed("YV12")
   G = gRGB.ShowGreen("YV12")
   B = gRGB.ShowBlue("YV12")

   ## Red-less version:
   global gGB = MergeRGB(R.ColorYUV(gain_y=-256), G, B).ConvertToRGB24

   return ScriptClip(gRGB, """
       ConditionalSelect(gRGB, "(current_frame%gint>0)?0:1", gRGB, gGB)
   """)
}


Related: see here
 
     Top
maruli
Posted: Apr 11 2014, 09:57 PM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



Thanks very much.
I am doing my experimenting with a good quality video. When I connect the VCR to a tv and play it, there are no color distortions at all.
It seems that the grabber (Aver TV Volar) is causing the effect. But this is the forth grabber, which I bought for cheap on Ebay, three already not doing the job. I am still hoping to be able to adjust the videos without buying grabber no. five, because the color error is systematic and not haphazard. As far as I have observed, the same frames were ok and the same were faulty when repeating the grabbing.

I will tell you the result, after I have figured out Avisynth and used your code.

 
     Top
raffriff42
Posted: Apr 12 2014, 07:15 PM


Advanced Member


Group: Members
Posts: 384
Member No.: 35081
Joined: 25-June 12



Restoration is not my specialty; you might get more help from an Avisynth restoration expert (hello, anyone?). My idea was to get you started; I also wanted to make a fairly simple starter script that does not require any extra downloads. (As I carefully cover my backside in case my script does not work very well for you)
 
     Top
maruli
Posted: Apr 16 2014, 12:24 AM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



Wow, I got as far as step 5 and it did work. I also did copy and paste the more elaborate code, but there is an error about the function conditionalselect. So I could not try it and I do not understand, what it is meant to do.

As far as I can presume, this Code is C++ and it refers to the source code of Virtualdub and to what is in its program library?
I would like to gain at least a basic comprehension. Is there any easy reference, where I can find out the meaning of the commands?

I have ordered one more grabber, this time a new one. As the only place to get it cheap is China, I have to wait at least a month until I get it. Until then I can continue my attempt to find a filter and make suggestions of what it should do.

I can think of an algorithm for the kind of a filter, which may solve my problem. I can only put it into pseudo-code, because my rudimentary understanding of programming was with Pascal.

Variables, x and y should be input options of the filter:

x is the threshold for the saturation of the not distorted bright red pixels.
y is the modification factor to be found by trial and error.
zo is the original saturation of red in any pixel.
zm is the modified saturation of red

if zo >= x, then zm := zo

The correction could be one of the following and should also be an option to choose in the filter
if zo < x then zm := zo * y
if zo < x then zm := zo + y
zm cannot get a value higher than zo.
if zo < x then zm := zo * (x-zo) * y

Has ever any kind of such a filter been programmed?
 
     Top
raffriff42
Posted: Apr 17 2014, 01:46 AM


Advanced Member


Group: Members
Posts: 384
Member No.: 35081
Joined: 25-June 12



First, if you want help with errors, you have to post the exact error. Or, just Google the error message! smile.gif

If you are interested in learning about Avisynth, go to the home page:
http://avisynth.nl/index.php/
Is is a "Wiki" - like Wikipedia. I started learning Avisynth by exploring most of the topics on the front page. Once you have read a few articles there, you will begin to get an idea of the language's power. Once you "get" it, I think you will love it!

If I understand your idea, it should work, provided red is not missing completely. I was assuming it was, and so grabbed some red from the previous frame; this is only one possible way of handling the problem.



 
     Top
maruli
Posted: Apr 17 2014, 09:30 PM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



This is the exact error message:

Avisynth open failure:
Script error: There is no function named "ConditionalSelect" (videotest.avs, line 20).

Googling ConditionalSelect has not got me to anything, that I as a complete newbie to VirtualDub and Avisynth can understand.

I will attempt to get a grasp of Avisynth as much as I can. My ignorance of C++ makes it difficult.

Red is not missing, it is irregularly reduced to different shades of brown, as if some faulty color correction inside the grabber has decreased red below the threshold.

I have been thinking about my algorithm and I think that the last formula should be:
if zo < x then zm := zo * (1+ (x-zo) * y)

But lacking the skill to write C++ code, it is futile to think of algorithms.

 
     Top
dloneranger
Posted: Apr 17 2014, 10:44 PM


Moderator


Group: Moderators
Posts: 2366
Member No.: 22158
Joined: 26-September 07



http://avisynth.nl/index.php/ConditionalFilter
Requires avisynth version 2.6 for conditionalselect

Avisynths language isn't exactly c++, but it's quite similar in structure
A lot of it can be googled quite easily
What language do you normally use? := (delphi/pascal?)

--------------------
MultiAdjust JoinWav WavNormalize FFMPeg Input Plugin v1827 UnSharpMask
Windows7/8 Codec Chooser
All FccHandlers Stuff inc. Installers for acm codecs AAC, AC3, LameMp3
 
    Top
maruli
Posted: Apr 18 2014, 12:24 AM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



I had installed 2.5. After installing 2.6, raffriff42's code works. But there is no visible difference between the processed and the unprocessed video file.

What about the limiter filter? Could I use it to eliminate the bright red and then enhance all red?

I found this:
http://avisynth.nl/index.php/Limiter
Unfortunately I did not find any page, which explains it in a more simple way.

When I try the limiter() command, there is an error: Source must be YUV. But looking through VirtualDub, I cannot find out the color version of my test file.

Does this mean, that my test file is not suitable for the limiter command? Or can this be remedied by some parameters?

So far I could not figure out the correct syntax of how to write a more elaborated limiter command.

I googled but I cannot find any example of a complete script containing the limiter, let alone an example of how to limit only the color red.

Is there any page with script examples, which I am not finding?

QUOTE

What language do you normally use? := (delphi/pascal?)

As of recently, I am not doing any programming.
Ages ago I learned the basics of Pascal, PL/I, Fortran and COBOL and I wrote elaborate Batch files for MS-DOS.
But I am clueless about C++. And I am also new to video processing.

I have to fulfill the promise to digitize a friend's videos. But I have to do it without the faulty red. And I cannot keep her waiting months or years until I may turn into a C++ and video processing specialist. So I would be fine, if I could solve the problem by trial and error, would I find simple and easily comprehensible sample scripts to start from.
 
     Top
dloneranger
Posted: Apr 18 2014, 05:27 AM


Moderator


Group: Moderators
Posts: 2366
Member No.: 22158
Joined: 26-September 07



If functions have limits on input formats, use the convertto... commands before them
http://avisynth.nl/index.php/Convert

Most of the scripts should be fairly readable for anyone with programming experience
One of the ones that always threw me and get used a lot was the assignment with a ? and : in there
That's a "Ternary conditional" http://en.wikipedia.org/wiki/%3F:

resultvariable = testcondition-true-false ? value-if-true : value-if-false
basically a c++ way of writing
if testcontition is true
resultvariable = value-if-true
else
resultvariable = value-if-false

--------------------
MultiAdjust JoinWav WavNormalize FFMPeg Input Plugin v1827 UnSharpMask
Windows7/8 Codec Chooser
All FccHandlers Stuff inc. Installers for acm codecs AAC, AC3, LameMp3
 
    Top
maruli
Posted: Apr 18 2014, 07:10 PM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



I have one test file grabbed via VirtualDub, which is accepted for the limiter() command without an error. But used as such, there is of course no effect.

Speaking a foreign language with mistakes I am usually nevertheless understood, but with programming, one little mistake suffices and nothing works, so I have no chance to write own Avisynth code.

Thanks for giving me ideas and a start. Realistically, all I can do is to search for working code examples to modify. More realistically, I need to wait, until I get the other grabber.

 
     Top
maruli
Posted: Apr 21 2014, 12:27 AM


Member


Group: Members
Posts: 20
Member No.: 37871
Joined: 11-April 14



I found the tweak command. I made some experiments with its parameters but did not succeed to really improve anything.
This made me wonder. Visibly, the problem is red. But what if the problem really is another color overriding red?

I found a little tool called colorpix.exe, which allows me to see the RGB and HSB values of any pixel.

From mixing paint, I know that to get brown, I need three colors, red, blue and yellow. RGB works differently, but it still has three elements, which can somehow show brown on the screen. That red and green adds to yellow is counterintuitive, but I may learn to figure out, how to change brown into more or less red.

But the hue values altered by tweak are HSB. I am puzzled, because in the HSB space, there is no brown.
When reading the HSB value of a pixel, I can attempt to change this hue, but the other hue adding to brown is hidden. So I cannot know, if a brown pixel lacks red or has too much of another color.

Sorry if this sound dumb. But is there anywhere an explanation about brown in HSB?


 
     Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
11 replies since Apr 11 2014, 03:27 AM Track this topic | Email this topic | Print this topic

<< Back to Newbie Questions