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 > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th March 2005, 19:34   #1  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Averaging pixels (by downsizing image?) - solved

*********************EDIT:
If you happen to need average pixel like this, look directly at posts
17th March 2005 00:29
27th March 2005 21:47
There is also a function ShrinkBy2 in SSETools plugin which "sounds" like it could work, but I didn't check and AFAIK no docs are available.
**********************
Hi,
I want to make average of each block of 4x4 pixels (in YV12) on mod4 sized clip. I thought a way is via downsizing. More exactly, when I have block like this (numbers are colors)
0011
0011
4433
4433
I want to get
2222
2222
2222
2222 etc.

Via downsizing it would be
22
22
and then PointResize back to original size.

But I never achieved it. I tried different resizers.. these aliasing or sharpening or whatever effects cause sometimes result like this:
0000
0000
0000
0000
into
11
11
when there was some value in nearby block. Similar for 8x8.

Thanx
R.

Last edited by redfordxx; 1st April 2005 at 13:58.
redfordxx is offline   Reply With Quote
Old 16th March 2005, 20:27   #2  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
maybe none of the avbisynth resizers is blockbased

a blockbased downsizer or averager shouldn't be hard if you give some more details on what you want
E-Male is offline   Reply With Quote
Old 16th March 2005, 22:01   #3  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by E-Male
...on what you want
When I have frame of a clip and I downsize it by two, I would like to have in each pixel of the downsized clip
average of colors of the four relevant pixels of original clip, which were merged by downsizing.
redfordxx is offline   Reply With Quote
Old 16th March 2005, 22:56   #4  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
what does "relevant" mean for you?
what colorspace?
"by 2" means halfing width AND hight each?
E-Male is offline   Reply With Quote
Old 16th March 2005, 23:12   #5  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by E-Male
what does "relevant" mean for you?
what colorspace?
"by 2" means halfing width AND hight each?
When downsizing by 2 both width AND height, for each pixel in the new smaller picture, there were exactly four pixels (2x2) in the original. These pixels I meant are relevant to the new one. Bad expression.

YV12
The same priciple as for Y sould work for U,V --- only doublesized
redfordxx is offline   Reply With Quote
Old 16th March 2005, 23:25   #6  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,855
Just do :

bilinearresize(half_width, half_height).bilinearresize(quarter_width, quarter_height).pointresize(width, height)

It'll work
Manao is offline   Reply With Quote
Old 16th March 2005, 23:58   #7  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by Manao
Just do :

bilinearresize(half_width, half_height).bilinearresize(quarter_width, quarter_height).pointresize(width, height)
It'll work
No it doesnot.

Look (I'm testing it only in one channel, so don't be scared by the color)


the second one is with higher contrast, to see the difference.
Just try swithing the images fast. You will easily find blocks on the second pic, where the same block on first image is 100% clear. E.g. top left one and the one below...
redfordxx is offline   Reply With Quote
Old 17th March 2005, 00:52   #8  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
reduceby2()
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 17th March 2005, 01:05   #9  |  Link
Si
Simply me
 
Si's Avatar
 
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
Just to fully clarify - do you want this

A B W X
C D Y Z
J K P Q
L M R S

made into

E E V V
E E V V
I I N N
I I N N

Where E is Average(A,B,C,D), V= Average(W,X,Y,Z) etc

or something else

regards
Simon
Si is offline   Reply With Quote
Old 17th March 2005, 01:16   #10  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by Mug Funky
reduceby2()
Again, No, also already tried.
redfordxx is offline   Reply With Quote
Old 17th March 2005, 01:18   #11  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by Si
Just to fully clarify - do you want this

A B W X
C D Y Z
J K P Q
L M R S

made into

E E V V
E E V V
I I N N
I I N N

Where E is Average(A,B,C,D), V= Average(W,X,Y,Z) etc

or something else

regards
Simon
Etc... YES.
redfordxx is offline   Reply With Quote
Old 17th March 2005, 01:21   #12  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
I wonder if bicubic resize is the solution with setting these extra parameters... I don't know what they mean.
redfordxx is offline   Reply With Quote
Old 17th March 2005, 01:29   #13  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
DEdgeMask(0,255,0,255,"0 0 0 0 1 1 0 1 1",U=3,V=3).PointResize(50%).PointResize(100%)

Not sure which points actually are taken by PointResize, though. Eventually the kernel has to be flipped u/d or l/r.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 17th March 2005, 06:41   #14  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,855
Edited : i'll wait to be fully awaken...

Last edited by Manao; 17th March 2005 at 06:43.
Manao is offline   Reply With Quote
Old 17th March 2005, 11:45   #15  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by Didée
DEdgeMask(0,255,0,255,"0 0 0 0 1 1 0 1 1",U=3,V=3).PointResize(50%).PointResize(100%)

Not sure which points actually are taken by PointResize, though. Eventually the kernel has to be flipped u/d or l/r.
Thanx Didée, it works --- I only had to add borders, for the DEdgeMask gave incorrect results, when part of the matrix is outside the frame.

Well, honestly, I didn't expect the solution is so complicated...
(I mean the idea is nice. Probably more CPU time demanding than I thought...)

Kernel=the matrix in "", isn't it?

Last edited by redfordxx; 17th March 2005 at 11:49.
redfordxx is offline   Reply With Quote
Old 17th March 2005, 11:50   #16  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
Quote:
Originally posted by Manao
Edited : i'll wait to be fully awaken...
?????????????????????
redfordxx is offline   Reply With Quote
Old 17th March 2005, 11:53   #17  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,855
I got up too early this morning and gave a wrong answer. I deleted it quickly, but i can't delete the whole post, hence the message.
Manao is offline   Reply With Quote
Old 17th March 2005, 12:19   #18  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Manao: Good moaning, erh, morning ...

Quote:
Originally posted by redfordxx
Well, honestly, I didn't expect the solution is so complicated...
(I mean the idea is nice. Probably more CPU time demanding than I thought...)
A specialised plugin could do the job in a fraction of the time. We just don't have such a one.
Basically, BilinearResize would do the very same thing. But if it were coded so as to average every 2*2 pixels (as you need here), then the resizer would shift the frame around during downsizing+upsizing combos. For a resizer, that's of course not acceptable.

Quote:
Kernel=the matrix in "", isn't it?
Yes. The string "1 2 3 4 5 6 7 8 9" in DEdgeMask normally would be written
Code:
1 2 3
4 5 6
7 8 9
BTW, in case you want to get the average out of 8*8 blocks, the simplest way is to use Tom's DCTFilter() with

DCFilter(1,0,0,0,0,0,0,0)
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 17th March 2005, 12:29   #19  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,855
> BilinearResize would do the very same thing.

No, and that's why I deleted my post : when downsizing by a factor two, the bilinear algorithm takes 4 pixels into accounts ( weighting them 0.25 0.75 0.75 0.25 ). When upsizing, however, it takes only two pixels into account ( 0.5 0.5 ), so the following :

Bilinearresize(double_width, double_height).pointresize(half_width, half_height).pointresize(width, height)

Should give a similar result to your script ( there again, we don't know which pixel is used by pointresize, and an offset is needed )

BTW, Didee, you often use DEgdeMask where i'd use YV12Convolution, especially when i'm not building a mask.
Manao is offline   Reply With Quote
Old 17th March 2005, 12:39   #20  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Ah, yes. Thanks for the correction on the bilinear thingie.

Quote:
Originally posted by Manao
BTW, Didee, you often use DEgdeMask where i'd use YV12Convolution, especially when i'm not building a mask.
Yes indeed. That's a behaviour coming from the fact that there are lots of kernels that cannot be build through the vectorial approach of yv12convolution. Examples:
Code:
1 1 1   2 3 2   -1 -1 -1   1 0 0
1 0 1   3 2 3   -1  9 -1   0 1 0
1 1 1   2 3 2   -1 -1 -1   0 0 1
So, sometimes I spare the time for thinking about "is it seperateable?", and quickly type DEdgeMask instead.

But of course here you're right: In this case, on could as well use

yv12convolution("0 1 1","0 1 1")

Mind I was pretty tired as well when writing that post above
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:30.


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