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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th March 2011, 02:56   #1  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
A question about displacing pixels using a grid

I was wondering if it would be possible to do something along the lines of this
http://screenshotcomparison.com/comparison/33922
or this
http://screenshotcomparison.com/comparison/33923
that being insert a 2x2, 4x4, or 8x8 grid and have it displace the original image keeping the original pixels all intact only separating them into individual blocks, I had some ideas concerning this, but I need to know if this is possible first
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon
TheProfileth is offline   Reply With Quote
Old 8th March 2011, 03:15   #2  |  Link
-TiLT-
Registered User
 
Join Date: Mar 2003
Location: Germany
Posts: 43
Unfortunately grid() will just draw a grid over the image, not separate the blocks.

Scripting it with avisynth (with a lot of crop() & overlay() ) would be possible, but not trivial to implement (though some pros might write it down in 30 secs).

I think first thing in the script should be adding of black borders (right and bottom) to keep the image modulo of the blocksize and prevent problems when cropping at the right side and bottom.

Last edited by -TiLT-; 8th March 2011 at 03:17.
-TiLT- is offline   Reply With Quote
Old 8th March 2011, 08:34   #3  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Think more simple. Do a PointResize(), then overlay the grid.
__________________
- 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 8th March 2011, 15:18   #4  |  Link
-TiLT-
Registered User
 
Join Date: Mar 2003
Location: Germany
Posts: 43
Like a 1,1->9,9 minus 1px grid for a 8,8 grid.

Yeah, keeping things simple isn't that easy sometimes.

Last edited by -TiLT-; 8th March 2011 at 15:22.
-TiLT- is offline   Reply With Quote
Old 8th March 2011, 23:59   #5  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
I am entirely sure that this is possible with either scripting a dll or an avsi, I will take a look into this and try your idea Didee
Edit:As -TiLT- implied, the actual upscaling to the right resolution ends up being a bit hard to calculate correctly
Edit2: Well Didee after getting the right size , point resize doesn't seem to do anything different than any other resize with regards to achieving my goal.
Again let me state
my goal is to insert a grid quiet literally INTO the picture, meaning that the resolution is increased by the number of pixels that the grid takes up, rather than just superimposing it on the image
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon

Last edited by TheProfileth; 9th March 2011 at 00:29.
TheProfileth is offline   Reply With Quote
Old 9th March 2011, 00:41   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by TheProfileth View Post
my goal is to insert a grid quiet literally INTO the picture, meaning that the resolution is increased by the number of pixels that the grid takes up, rather than just superimposing it on the image
That's the point of using PointResize.
If you get the numbers right, it will add duplicate pixels at exactly the points where the grid goes, displacing the others to the right or down to fit around the grid.

For example, for a 4x4 grid, resize by a factor of 5/4, then overlay the grid.
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 9th March 2011 at 00:44.
Gavino is offline   Reply With Quote
Old 9th March 2011, 00:47   #7  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
Quote:
Originally Posted by Gavino View Post
That's the point of using PointResize.
If you get the numbers right, it will add duplicate pixels at exactly the points where the grid goes, displacing the others to the right or down to fit around the grid.

For example, for a 4x4 grid, resize by a factor of 5/4, then overlay the grid.
Alright let me try that
Edit: Ok well the problem with doing that is that not all of the "extra pixels" get covered up and then you end up with blocks that contain weird artifact like blotches which sort of defeats the purpose
Edit2:lol I forgot to use 5 not 4 ok hold on
Edit3:damn it seems that the input for the grid must be a even number so I can't use 5 or 9 or 17, I also can't use any value below 4
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon

Last edited by TheProfileth; 9th March 2011 at 01:07.
TheProfileth is offline   Reply With Quote
Old 9th March 2011, 00:51   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Remember also that if the grid encloses 4x4 pixels, the grid itself will be every 5 pixels, and so on.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 9th March 2011, 01:25   #9  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
So Gavino, do you or anyone you have any other methods that could work?
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon

Last edited by TheProfileth; 9th March 2011 at 01:28.
TheProfileth is offline   Reply With Quote
Old 9th March 2011, 02:22   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
An alternative way of creating the grid is to use mt_lutspa.
For example,
mt_lutspa(expr="x 5 % y 5 % * 0 == 255 0 ?", relative=false)
will create a grid-like mask with a grid spacing of 5.
The mask can then be used in overlaying a solid-coloured clip on top of the original, thus adding the grid to it.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 9th March 2011, 16:34   #11  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
Quote:
Originally Posted by TheProfileth View Post
Edit3:damn it seems that the input for the grid must be a even number so I can't use 5 or 9 or 17, I also can't use any value below 4
converttorgb() first?
2Bdecided is offline   Reply With Quote
Old 9th March 2011, 17:06   #12  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
... While waiting for the printer to finish my document ...

Most probably this is erroneous, but at least it's a start.

FWIW:

Code:
# YV12 required, as is MaskTools.
#
# target: 8x8-grid expansion
#
#  "MAY CONTAIN NUTS"

o = last

owidth = o.width
oheight = o.height

exwidth0 = owidth * 9.0/8 + 1
exheight0 = oheight * 9.0/8 + 1

exwidth1 = ceil(exwidth0/4.0) * 4
exheight1 = ceil(exheight0/4.0) * 4

xcorr = ((exwidth1-exwidth0) / 9.0) *8
ycorr = ((exheight1-exheight0) / 9.0) *8

ex1 = o.pointresize(exwidth1,exheight1,0,0,owidth+xcorr,oheight+ycorr)
ex2 = ex1.mt_expand(mode="-1 -1",U=3,V=3)

grid = ex2.mt_lutspa(relative=false,expr="x 8 % 0 == y 8 % 0 == | 0 255 ?")

ex2.mt_logic(grid,"min",U=2,V=2)
__________________
- 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 9th March 2011, 18:11   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Didée View Post
# target: 8x8-grid expansion

grid = ex2.mt_lutspa(relative=false,expr="x 8 % 0 == y 8 % 0 == | 0 255 ?")[/code]
I'm not sure how the rest of your script works, but that bit doesn't look right.
As I pointed out above, to contain 8x8 blocks of original pixels, the grid spacing must be 9x9
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 9th March 2011, 18:42   #14  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Oh yes, those 8's should be 9's, of course. Also, the script feeds destination width|height as float values into the resizer. That's not so good.
__________________
- 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 9th March 2011, 21:44   #15  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
I didn't try the above script, but this works with the PointResize approach
[I don't like the mt_merge at the end, but had problems with chroma otherwise. BTW. it needs MaskTools alpha 45 or above as it uses the newer syntax for lutspa]
Code:
# Split into grid of given size
# size = grid x dimension, sizeY = grid y dimension (= x dimension by default)
# color = grid color in RGB (e.g. $00FF00 for green, defaults to black)
# xMod and yMod = dimension restrictions on clips (defaults to multiples of 4) [could calculate from clip type]
# Examples: GridSplit( 8 ) # 8x8 grid       GridSplit(5,3,$808080) # 5x3 grid, gray grid lines
function GridSplit( clip c, int size, int "sizeY", int "color", int "xMod", int "yMod" )
{
	xMod = default( xMod, 4 )
	yMod = default( yMod, 4 )
	sizeY = default( sizeY, size )
	color = default( color, $000000 )

	# Original dimensions
	w = c.Width()
	h = c.Height()

	# Dimensions with grid lines, but may not fit given mods
	nw = w + (w-1) / size
	nh = h + (h-1) / sizeY

	# Pad above dimensions to fit mods
	pw = ((nw + xMod - 1) / xMod) * xMod 
	ph = ((nh + yMod - 1) / yMod) * yMod 

	# Equivalent dimensions to above without grid lines - must pad to this size before rescale to ensure each
	# block of "size" pixels will map to exactly "size+1" pixels in result
	bw = float(size * pw) / (size+1)
	bh = float(sizeY * ph) / (sizeY+1)

	# Pad, then rescale using dimensions calculated. Also offset duplicated pixels to provide neat position for grid lines
	c.PointResize( pw, ph, 1 - 0.5/(size+1), 1 - 0.5/(sizeY+1), bw, bh )

	# Black out both grid and padded pixels
	gridCondition = "x 1 + " + string(size+1) + " % 0 == y 1 + " + string(sizeY+1) + " % 0 == | "
	paddedCondition = "x " + string(nw) + " >= y " + string(nh) + " >= | "
	grid = mt_lutspa( mode="absolute", expr=gridCondition + paddedCondition + "| 0 255 ?", U=1,V=1 )
	
	background = BlankClip( grid, color=color )
	mt_merge( background, last, grid, luma=true )

	return last
}

Last edited by -Vit-; 10th March 2011 at 03:41.
-Vit- is offline   Reply With Quote
Old 10th March 2011, 00:41   #16  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
Hey thanks everyone, I will be sure to try your method out -Vit- will give feedback in a second
Edit: Ok so that works great, but umm..... now I need a method to remove it :3
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon

Last edited by TheProfileth; 10th March 2011 at 00:55.
TheProfileth is offline   Reply With Quote
Old 10th March 2011, 01:03   #17  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
A problem I did not nice until now was that the grid actually causes the image to change, around the grid lines it seems like there is something odd going on , so even if the removal of said grid was easily accomplished it still would leave the image changed.
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon
TheProfileth is offline   Reply With Quote
Old 10th March 2011, 01:15   #18  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
That's an optical illusion. The split pixels are exactly as the original image. However moving pixels will jump as they pass over the lines and the sheer amount of black in the image also makes the levels seem different [ try GridSplit(1) ].

I don't see it as a particularly useful effect though. Best I could
get out of it was by chaining a few together:
Code:
GridSplit( 8 )
GridSplit( 9 )
GridSplit( 10 )
or
Code:
GridSplit( 4 )
GridSplit( 20 )
GridSplit( 84 )

Last edited by -Vit-; 10th March 2011 at 01:23.
-Vit- is offline   Reply With Quote
Old 10th March 2011, 01:20   #19  |  Link
TheProfileth
Leader of Dual-Duality
 
TheProfileth's Avatar
 
Join Date: Aug 2010
Location: America
Posts: 134
-Vit- it is no optical illusion see here
http://eypic.com/kya43f60b.png
look around the edges, this was a blue image originally
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood
My New filter is in the works, and will be out soon
TheProfileth is offline   Reply With Quote
Old 10th March 2011, 01:25   #20  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
Ah yes, I forgot that. The chroma will be off at the edges, because of the subsampling in YV12. Absolutely can't avoid that if you want to inject 1 pixel into a format that samples at every two pixels. Not sure why the effect is creeping two pixels in though.

Would work in RGB, but MaskTools can't do RGB

Last edited by -Vit-; 10th March 2011 at 01:27.
-Vit- is offline   Reply With Quote
Reply


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 00:21.


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